aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java21
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java6
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java54
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java23
4 files changed, 47 insertions, 57 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java
index 0f6a5e3d..6d16c601 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright(C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -711,26 +712,10 @@ abstract class GenericEventProtocolCoder {
}
GsonProtocolCoderToolset gsonCoderTools =
- new GsonProtocolCoderToolset(
- eventProtocolParams.getTopic(),
- key,
- eventProtocolParams.getGroupId(),
- eventProtocolParams.getArtifactId(),
- eventProtocolParams.getEventClass(),
- eventProtocolParams.getProtocolFilter(),
- eventProtocolParams.getCustomGsonCoder(),
- eventProtocolParams.getModelClassLoaderHash());
+ new GsonProtocolCoderToolset(eventProtocolParams, key);
JacksonProtocolCoderToolset jacksonCoderTools =
- new JacksonProtocolCoderToolset(
- eventProtocolParams.getTopic(),
- key,
- eventProtocolParams.getGroupId(),
- eventProtocolParams.getArtifactId(),
- eventProtocolParams.getEventClass(),
- eventProtocolParams.getProtocolFilter(),
- eventProtocolParams.getCustomJacksonCoder(),
- eventProtocolParams.getModelClassLoaderHash());
+ new JacksonProtocolCoderToolset(eventProtocolParams, key);
// Use Gson as the first priority encoding/decoding toolset, and Jackson
// as second. This is because it has been observed that they can diverge
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java
index 89d22481..e8a140e0 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java
@@ -20,6 +20,8 @@
package org.onap.policy.drools.protocol.coders;
+import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomCoder;
+
public class EventProtocolParams {
private String groupId;
private String artifactId;
@@ -155,4 +157,8 @@ public class EventProtocolParams {
this.modelClassLoaderHash = modelClassLoaderHash;
return this;
}
+
+ public CustomCoder getCustomCoder() {
+ return this.customGsonCoder != null ? this.customGsonCoder : this.customJacksonCoder;
+ }
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
index ead6794c..bc4fe142 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,8 +49,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomCoder;
-import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder;
-import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomJacksonCoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -101,28 +100,25 @@ public abstract class ProtocolCoderToolset {
/**
* Constructor.
*
- * @param topic the topic
+ * @param eventProtocolParams parameter object for event encoder
* @param controllerId the controller id
- * @param codedClass the decoded class
- * @param filters list of filters that apply to the selection of this decodedClass in case of
- * multiplicity
* @throws IllegalArgumentException if invalid data has been passed in
*/
- public ProtocolCoderToolset(String topic, String controllerId, String groupId, String artifactId,
- String codedClass, JsonProtocolFilter filters, CustomCoder customCoder,
- int modelClassLoaderHash) {
+ public ProtocolCoderToolset(EventProtocolParams eventProtocolParams, String controllerId) {
- if (topic == null || controllerId == null || groupId == null || artifactId == null
- || codedClass == null || filters == null || topic.isEmpty() || controllerId.isEmpty()) {
+ if (eventProtocolParams == null || controllerId == null) {
throw new IllegalArgumentException("Invalid input");
}
- this.topic = topic;
+ this.topic = eventProtocolParams.getTopic();
this.controllerId = controllerId;
- this.groupId = groupId;
- this.artifactId = artifactId;
- this.coders.add(new CoderFilters(codedClass, filters, modelClassLoaderHash));
- this.customCoder = customCoder;
+ this.groupId = eventProtocolParams.getGroupId();
+ this.artifactId = eventProtocolParams.getArtifactId();
+ this.coders.add(new CoderFilters(
+ eventProtocolParams.getEventClass(),
+ eventProtocolParams.getProtocolFilter(),
+ eventProtocolParams.getModelClassLoaderHash()));
+ this.customCoder = eventProtocolParams.getCustomCoder();
}
/**
@@ -359,15 +355,11 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset {
/**
* Toolset to encode/decode tools associated with a topic.
*
- * @param topic topic
- * @param decodedClass decoded class of an event
- * @param filter filter
+ * @param eventProtocolParams parameter object for event encoder
+ * @param controllerId controller id
*/
- public JacksonProtocolCoderToolset(String topic, String controllerId, String groupId,
- String artifactId, String decodedClass, JsonProtocolFilter filter,
- CustomJacksonCoder customJacksonCoder, int modelClassLoaderHash) {
- super(topic, controllerId, groupId, artifactId, decodedClass, filter, customJacksonCoder,
- modelClassLoaderHash);
+ public JacksonProtocolCoderToolset(EventProtocolParams eventProtocolParams, String controllerId) {
+ super(eventProtocolParams, controllerId);
this.decoder.registerModule(new JavaTimeModule());
this.decoder.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
@@ -475,11 +467,11 @@ class JacksonProtocolCoderToolset extends ProtocolCoderToolset {
}
+
/**
* Tools used for encoding/decoding using Jackson.
*/
class GsonProtocolCoderToolset extends ProtocolCoderToolset {
-
/**
* Logger.
*/
@@ -550,15 +542,11 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
/**
* Toolset to encode/decode tools associated with a topic.
*
- * @param topic topic
- * @param decodedClass decoded class of an event
- * @param filter filter
+ * @param eventProtocolParams parameter object for event encoder
+ * @param controllerId controller id
*/
- public GsonProtocolCoderToolset(String topic, String controllerId, String groupId,
- String artifactId, String decodedClass, JsonProtocolFilter filter,
- CustomGsonCoder customGsonCoder, int modelClassLoaderHash) {
- super(topic, controllerId, groupId, artifactId, decodedClass, filter, customGsonCoder,
- modelClassLoaderHash);
+ public GsonProtocolCoderToolset(EventProtocolParams eventProtocolParams, String controllerId) {
+ super(eventProtocolParams, controllerId);
}
/**
diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java
index 28168178..d28f1e52 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java
@@ -105,9 +105,14 @@ public class ProtocolCoderToolsetTest {
* @param protocolFilter protocol filter
*/
public void testGsonToolset(JsonProtocolFilter protocolFilter) {
- GsonProtocolCoderToolset gsonToolset = new GsonProtocolCoderToolset(JUNIT_PROTOCOL_CODER_TOPIC, CONTROLLER_ID,
- this.releaseId.getGroupId(), this.releaseId.getArtifactId(), Triple.class.getCanonicalName(),
- protocolFilter, null, 12345678);
+ GsonProtocolCoderToolset gsonToolset = new GsonProtocolCoderToolset(
+ EventProtocolParams.builder().topic(JUNIT_PROTOCOL_CODER_TOPIC)
+ .groupId(this.releaseId.getGroupId())
+ .artifactId(this.releaseId.getArtifactId())
+ .eventClass(Triple.class.getCanonicalName())
+ .protocolFilter(protocolFilter)
+ .customGsonCoder(null)
+ .modelClassLoaderHash(12345678), CONTROLLER_ID);
Assert.assertNotNull(gsonToolset.getEncoder());
Assert.assertNotNull(gsonToolset.getDecoder());
@@ -130,9 +135,15 @@ public class ProtocolCoderToolsetTest {
* @param protocolFilter protocol filter
*/
public void testJacksonToolset(JsonProtocolFilter protocolFilter) {
- JacksonProtocolCoderToolset jacksonToolset = new JacksonProtocolCoderToolset(JUNIT_PROTOCOL_CODER_TOPIC,
- CONTROLLER_ID, this.releaseId.getGroupId(), this.releaseId.getArtifactId(),
- Triple.class.getCanonicalName(), protocolFilter, null, 12345678);
+ JacksonProtocolCoderToolset jacksonToolset = new JacksonProtocolCoderToolset(
+ EventProtocolParams.builder()
+ .topic(JUNIT_PROTOCOL_CODER_TOPIC)
+ .groupId(this.releaseId.getGroupId())
+ .artifactId(this.releaseId.getArtifactId())
+ .eventClass(Triple.class.getCanonicalName())
+ .protocolFilter(protocolFilter)
+ .customJacksonCoder(null)
+ .modelClassLoaderHash(12345678), CONTROLLER_ID);
jacksonToolset.getEncoder().setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
jacksonToolset.getDecoder().setVisibility(PropertyAccessor.FIELD, Visibility.ANY);