From a71d5cda181f7bb74420f044614cd78cc2a38496 Mon Sep 17 00:00:00 2001 From: "a.sreekumar" Date: Thu, 27 Jun 2019 10:26:04 +0000 Subject: Making the topic property utility method more generic - addressing Jorge's review comment Making the method to update topic properties object more generic so that it can be used by other components such as drools if needed. Change-Id: I29c0f8fde5f4e1dd464072a9b06f2d93cc15b137 Issue-ID: POLICY-1744 Signed-off-by: a.sreekumar --- .../properties/PolicyEndPointProperties.java | 1 + .../common/endpoints/utils/ParameterUtils.java | 30 +++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'policy-endpoints/src/main/java/org/onap/policy/common/endpoints') diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java index 7e22712b..0d59fd2f 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java @@ -25,6 +25,7 @@ public interface PolicyEndPointProperties { /* Generic property suffixes */ String PROPERTY_TOPIC_SERVERS_SUFFIX = ".servers"; + String PROPERTY_TOPIC_TOPICS_SUFFIX = ".topics"; String PROPERTY_TOPIC_API_KEY_SUFFIX = ".apiKey"; String PROPERTY_TOPIC_API_SECRET_SUFFIX = ".apiSecret"; String PROPERTY_TOPIC_AAF_MECHID_SUFFIX = ".aafMechId"; diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java index 9e7c69a4..40ce8fa5 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java @@ -25,6 +25,7 @@ import java.util.Properties; import org.onap.policy.common.endpoints.parameters.TopicParameterGroup; import org.onap.policy.common.endpoints.parameters.TopicParameters; +import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; /** * This is common utility class with utility methods for parameters. @@ -54,24 +55,35 @@ public abstract class ParameterUtils { // for each topicCommInfrastructure, there could be multiple topics (specified as comma separated string) // for each such topics, there could be multiple servers (specified as comma separated string) for (TopicParameters source : topicSources) { - addTopicProperties(topicProperties, ".source.topics", source); + updateTopicProperties(topicProperties, "source", source.getTopicCommInfrastructure(), source.getTopic(), + source.getServers()); } for (TopicParameters sink : topicSinks) { - addTopicProperties(topicProperties, ".sink.topics", sink); + updateTopicProperties(topicProperties, "sink", sink.getTopicCommInfrastructure(), sink.getTopic(), + sink.getServers()); } return topicProperties; } - private static void addTopicProperties(Properties topicProperties, String keyName, TopicParameters topicParameter) { - String propKey = topicParameter.getTopicCommInfrastructure() + keyName; + /** + * Common method to update topic properties object using the parameters passed. + * + * @param topicProperties the topic properties object which is to be updated + * @param keyName either it is source or sink + * @param topicCommInfra the infra such as dmaap, ueb or noop + * @param topicName the topic + * @param servers the list of server names for the topic + */ + public static void updateTopicProperties(Properties topicProperties, String keyName, String topicCommInfra, + String topicName, List servers) { + String propKey = topicCommInfra + "." + keyName + PolicyEndPointProperties.PROPERTY_TOPIC_TOPICS_SUFFIX; if (topicProperties.containsKey(propKey)) { - topicProperties.setProperty(propKey, - topicProperties.getProperty(propKey) + "," + topicParameter.getTopic()); + topicProperties.setProperty(propKey, topicProperties.getProperty(propKey) + "," + topicName); } else { - topicProperties.setProperty(propKey, topicParameter.getTopic()); + topicProperties.setProperty(propKey, topicName); } - topicProperties.setProperty(propKey + "." + topicParameter.getTopic() + ".servers", - String.join(",", topicParameter.getServers())); + topicProperties.setProperty(propKey + "." + topicName + PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX, + String.join(",", servers)); } } -- cgit 1.2.3-korg