Modify event (en)coder to use param objs 17/72717/1
authorkris.jinka <kris.jinka@samsung.com>
Thu, 15 Nov 2018 00:51:02 +0000 (09:51 +0900)
committerkris.jinka <kris.jinka@samsung.com>
Thu, 15 Nov 2018 00:51:21 +0000 (09:51 +0900)
Use builder object to send params to event protocol
coder and encoder methods to fix sonar issue

Issue-ID: POLICY-1251
Change-Id: I6ca5823e1aa35d9aa3a05eb23ac159947efdde23
Signed-off-by: kris.jinka <kris.jinka@samsung.com>
policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java
policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolParams.java [new file with mode: 0644]
policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java
policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java

index 707a8e7..ef20b84 100644 (file)
@@ -42,6 +42,7 @@ import org.onap.policy.drools.core.PolicySession;
 import org.onap.policy.drools.core.jmx.PdpJmx;
 import org.onap.policy.drools.features.DroolsControllerFeatureAPI;
 import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
+import org.onap.policy.drools.protocol.coders.EventProtocolParams;
 import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
 import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
 import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder;
@@ -310,11 +311,12 @@ public class MavenDroolsController implements DroolsController {
                             customJacksonCoder,
                             this.policyContainer.getClassLoader().hashCode());
                 } else {
-                    EventProtocolCoder.manager.addEncoder(this.getGroupId(), this.getArtifactId(), 
-                            topic, potentialCodedClass, protocolFilter,
-                            customGsonCoder,
-                            customJacksonCoder,
-                            this.policyContainer.getClassLoader().hashCode());
+                    EventProtocolCoder.manager.addEncoder(
+                            EventProtocolParams.builder().groupId(this.getGroupId())
+                                    .artifactId(this.getArtifactId()).topic(topic)
+                                    .eventClass(potentialCodedClass).protocolFilter(protocolFilter)
+                                    .customGsonCoder(customGsonCoder).customJacksonCoder(customJacksonCoder)
+                                    .modelClassLoaderHash(this.policyContainer.getClassLoader().hashCode()));
                 }
             }
         }
index 6d75289..b9cb568 100644 (file)
@@ -281,21 +281,10 @@ public interface EventProtocolCoder {
     /**
      * Adds a Encoder class to encode the protocol over this topic.
      *  
-     * @param groupId of the controller
-     * @param artifactId of the controller
-     * @param topic the topic 
-     * @param eventClass the event class
-     * @param protocolFilter filters to selectively choose a particular decoder
-     *     when there are multiples
-     * 
-     * @throw IllegalArgumentException if an invalid parameter is passed
+     *
+     * @param eventProtocolParams@throw IllegalArgumentException if an invalid parameter is passed
      */
-    public void addEncoder(String groupId, String artifactId, String topic, 
-            String eventClass, 
-            JsonProtocolFilter protocolFilter,
-            CustomGsonCoder customGsonCoder,
-            CustomJacksonCoder customJacksonCoder,
-            int modelClassLoaderHash);
+    public void addEncoder(EventProtocolParams eventProtocolParams);
 
     /**
      * is there an encoder supported for the controller id and topic.
@@ -428,20 +417,21 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder {
 
     /**
      * {@inheritDoc}.
+     * @param eventProtocolParams parameter object for event encoder
      */
     @Override
-    public void addEncoder(String groupId, String artifactId, String topic, 
-            String eventClass, 
-            JsonProtocolFilter protocolFilter,
-            CustomGsonCoder customGsonCoder,
-            CustomJacksonCoder customJacksonCoder,
-            int modelClassLoaderHash) {
-        logger.info("{}: add-decoder {}:{}:{}:{}:{}:{}:{}:{}", this, 
-                groupId, artifactId, topic, eventClass,
-                protocolFilter, customGsonCoder, customJacksonCoder,
-                modelClassLoaderHash);
-        this.encoders.add(groupId, artifactId, topic, eventClass, protocolFilter, 
-                customGsonCoder, customJacksonCoder, modelClassLoaderHash);
+    public void addEncoder(EventProtocolParams eventProtocolParams) {
+        logger.info("{}: add-decoder {}:{}:{}:{}:{}:{}:{}:{}", this,
+                eventProtocolParams.getGroupId(), eventProtocolParams.getArtifactId(), eventProtocolParams.getTopic(),
+                eventProtocolParams.getEventClass(),
+                eventProtocolParams.getProtocolFilter(), eventProtocolParams.getCustomGsonCoder(),
+                eventProtocolParams.getCustomJacksonCoder(),
+                eventProtocolParams.getModelClassLoaderHash());
+        this.encoders.add(eventProtocolParams.getGroupId(), eventProtocolParams.getArtifactId(),
+                eventProtocolParams.getTopic(), eventProtocolParams.getEventClass(),
+                eventProtocolParams.getProtocolFilter(),
+                eventProtocolParams.getCustomGsonCoder(), eventProtocolParams.getCustomJacksonCoder(),
+                eventProtocolParams.getModelClassLoaderHash());
     }
 
     /**
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
new file mode 100644 (file)
index 0000000..89d2248
--- /dev/null
@@ -0,0 +1,158 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.protocol.coders;
+
+public class EventProtocolParams {
+    private String groupId;
+    private String artifactId;
+    private String topic;
+    private String eventClass;
+    private JsonProtocolFilter protocolFilter;
+    private TopicCoderFilterConfiguration.CustomGsonCoder customGsonCoder;
+    private TopicCoderFilterConfiguration.CustomJacksonCoder customJacksonCoder;
+    private int modelClassLoaderHash;
+
+    public String getGroupId() {
+        return groupId;
+    }
+
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    public String getTopic() {
+        return topic;
+    }
+
+    public String getEventClass() {
+        return eventClass;
+    }
+
+    public JsonProtocolFilter getProtocolFilter() {
+        return protocolFilter;
+    }
+
+    public TopicCoderFilterConfiguration.CustomGsonCoder getCustomGsonCoder() {
+        return customGsonCoder;
+    }
+
+    public TopicCoderFilterConfiguration.CustomJacksonCoder getCustomJacksonCoder() {
+        return customJacksonCoder;
+    }
+
+    public int getModelClassLoaderHash() {
+        return modelClassLoaderHash;
+    }
+
+    public static EventProtocolParams builder() {
+        return new EventProtocolParams();
+    }
+
+    /**
+     * Setter method.
+     *
+     * @param groupId of the controller
+     * @return EventProtocolParams
+     */
+    public EventProtocolParams groupId(String groupId) {
+        this.groupId = groupId;
+        return this;
+    }
+
+    /**
+     * Setter method.
+     *
+     * @param artifactId of the controller
+     * @return EventProtocolParams
+     */
+    public EventProtocolParams artifactId(String artifactId) {
+        this.artifactId = artifactId;
+        return this;
+    }
+
+    /**
+     * Setter method.
+     *
+     * @param topic the topic
+     * @return EventProtocolParams
+     */
+    public EventProtocolParams topic(String topic) {
+        this.topic = topic;
+        return this;
+    }
+
+    /**
+     * Setter method.
+     *
+     * @param eventClass the event class
+     * @return EventProtocolParams
+     */
+    public EventProtocolParams eventClass(String eventClass) {
+        this.eventClass = eventClass;
+        return this;
+    }
+
+    /**
+     * Setter method.
+     *
+     * @param protocolFilter filters to selectively choose a particular decoder
+     *                       when there are multiples
+     * @return EventProtocolParams
+     */
+    public EventProtocolParams protocolFilter(JsonProtocolFilter protocolFilter) {
+        this.protocolFilter = protocolFilter;
+        return this;
+    }
+
+    /**
+     * Setter method.
+     *
+     * @param customGsonCoder custom gscon coder
+     * @return EventProtocolParams
+     */
+    public EventProtocolParams customGsonCoder(
+            TopicCoderFilterConfiguration.CustomGsonCoder customGsonCoder) {
+        this.customGsonCoder = customGsonCoder;
+        return this;
+    }
+
+    /**
+     * Setter method.
+     *
+     * @param customJacksonCoder custom Jackson coder
+     * @return EventProtocolParams
+     */
+    public EventProtocolParams customJacksonCoder(
+            TopicCoderFilterConfiguration.CustomJacksonCoder customJacksonCoder) {
+        this.customJacksonCoder = customJacksonCoder;
+        return this;
+    }
+
+    /**
+     * Setter method.
+     * @param modelClassLoaderHash integer representing model hash
+     * @return EventProtocolParams
+     */
+    public EventProtocolParams modelClassLoaderHash(int modelClassLoaderHash) {
+        this.modelClassLoaderHash = modelClassLoaderHash;
+        return this;
+    }
+}
index d6330cd..ec1b999 100644 (file)
@@ -84,9 +84,12 @@ public class EventProtocolCoderTest {
 
         TopicEndpoint.manager.addTopicSinks(noopSinkProperties);
 
-        EventProtocolCoder.manager.addEncoder(ENCODER_GROUP, ENCODER_ARTIFACT, NOOP_TOPIC,
-                DroolsConfiguration.class.getCanonicalName(), new JsonProtocolFilter(), null, null,
-                DroolsConfiguration.class.getName().hashCode());
+        EventProtocolCoder.manager.addEncoder(
+                EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT)
+                        .topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getCanonicalName())
+                        .protocolFilter(new JsonProtocolFilter()).customGsonCoder(null)
+                        .customJacksonCoder(null)
+                        .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()));
 
         final String json = EventProtocolCoder.manager.encode(NOOP_TOPIC,
                 new DroolsConfiguration(ENCODER_GROUP, ENCODER_ARTIFACT, ENCODER_VERSION));
index cd93d94..4a2767a 100644 (file)
@@ -41,10 +41,9 @@ import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
 import org.onap.policy.drools.persistence.SystemPersistence;
 import org.onap.policy.drools.properties.DroolsProperties;
 import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
+import org.onap.policy.drools.protocol.coders.EventProtocolParams;
 import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
 import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
-import org.onap.policy.drools.system.PolicyController;
-import org.onap.policy.drools.system.PolicyEngine;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -205,9 +204,12 @@ public class PolicyEngineTest {
 
         TopicEndpoint.manager.addTopicSinks(noopSinkProperties).get(0).start();
 
-        EventProtocolCoder.manager.addEncoder(ENCODER_GROUP, ENCODER_ARTIFACT, NOOP_TOPIC,
-                DroolsConfiguration.class.getCanonicalName(), new JsonProtocolFilter(), null, null,
-                DroolsConfiguration.class.getName().hashCode());
+        EventProtocolCoder.manager.addEncoder(
+                EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT)
+                        .topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getCanonicalName())
+                        .protocolFilter(new JsonProtocolFilter()).customGsonCoder(null)
+                        .customJacksonCoder(null)
+                        .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()));
 
         assertTrue(PolicyEngine.manager.deliver(NOOP_TOPIC,
                 new DroolsConfiguration(ENCODER_GROUP, ENCODER_ARTIFACT, ENCODER_VERSION)));