diff options
Diffstat (limited to 'policy-management/src/main/java/org/onap/policy/drools/protocol')
7 files changed, 1214 insertions, 1087 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 3e4e7ecd..6d752897 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 @@ -183,56 +183,54 @@ public interface EventProtocolCoder { */ public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic); - /** - * Given a controller id and a topic, it gives back the decoding configuration. + * gets all decoders associated with the group and artifact ids. * * @param groupId of the controller * @param artifactId of the controller - * @param topic the topic * - * @return decoding toolset - * - * @throw IllegalArgumentException if an invalid parameter is passed + * @throws IllegalArgumentException if invalid arguments have been provided */ - public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic); + public List<CoderFilters> getDecoderFilters(String groupId, String artifactId); /** - * Given a controller id and a topic, it gives back all the decoding configurations. + * Given a controller id, a topic, and a classname, it gives back the classes that implements the decoding. * * @param groupId of the controller * @param artifactId of the controller + * @param topic the topic + * @param classname classname * - * @return decoding toolset + * @return list of decoders * * @throw IllegalArgumentException if an invalid parameter is passed - */ - public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId); + */ + public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname); /** - * gets all decoders associated with the group and artifact ids. + * Given a controller id and a topic, it gives back the decoding configuration. * * @param groupId of the controller * @param artifactId of the controller + * @param topic the topic * - * @throws IllegalArgumentException if invalid arguments have been provided + * @return decoding toolset + * + * @throw IllegalArgumentException if an invalid parameter is passed */ - public List<CoderFilters> getDecoderFilters(String groupId, String artifactId); - + public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic); /** - * Given a controller id, a topic, and a classname, it gives back the classes that implements the decoding. + * Given a controller id and a topic, it gives back all the decoding configurations. * * @param groupId of the controller * @param artifactId of the controller - * @param topic the topic - * @param classname classname * - * @return list of decoders + * @return decoding toolset * * @throw IllegalArgumentException if an invalid parameter is passed - */ - public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname); + */ + public List<ProtocolCoderToolset> getDecoders(String groupId, String artifactId); /** * Given a controller id and a topic, it gives back the classes that implements the encoding. @@ -411,7 +409,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void addDecoder(String groupId, String artifactId, String topic, @@ -429,7 +427,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void addEncoder(String groupId, String artifactId, String topic, @@ -447,7 +445,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void removeDecoders(String groupId, String artifactId, String topic) { @@ -456,7 +454,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void removeEncoders(String groupId, String artifactId, String topic) { @@ -465,7 +463,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public boolean isDecodingSupported(String groupId, String artifactId, String topic) { @@ -473,7 +471,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public boolean isEncodingSupported(String groupId, String artifactId, String topic) { @@ -481,7 +479,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public Object decode(String groupId, String artifactId, String topic, String json) { @@ -490,7 +488,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public String encode(String groupId, String artifactId, String topic, Object event) { @@ -499,7 +497,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public String encode(String topic, Object event) { @@ -508,7 +506,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public String encode(String topic, Object event, DroolsController droolsController) { @@ -517,7 +515,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public List<CoderFilters> getDecoderFilters(String groupId, String artifactId, String topic) { @@ -525,7 +523,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname) { @@ -533,7 +531,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public List<CoderFilters> getDecoderFilters(String groupId, String artifactId) { @@ -542,7 +540,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic) { @@ -582,7 +580,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public List<CoderFilters> getEncoderFilters(String groupId, String artifactId, String topic) { @@ -590,7 +588,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname) { @@ -598,7 +596,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public List<CoderFilters> getEncoderFilters(String groupId, String artifactId) { @@ -606,7 +604,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public List<CoderFilters> getReverseEncoderFilters(String topic, String encodedClass) { @@ -614,7 +612,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public DroolsController getDroolsController(String topic, Object encodedClass) { @@ -622,7 +620,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public List<DroolsController> getDroolsControllers(String topic, Object encodedClass) { @@ -630,7 +628,7 @@ class MultiplexorEventProtocolCoder implements EventProtocolCoder { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public String toString() { @@ -722,7 +720,7 @@ abstract class GenericEventProtocolCoder { if (coders.containsKey(key)) { Pair<ProtocolCoderToolset, ProtocolCoderToolset> toolsets = coders.get(key); - logger.info("{}: adding coders for existing {}: ", this, key, toolsets.first()); + logger.info("{}: adding coders for existing {}: {}", this, key, toolsets.first()); toolsets.first().addCoder(eventClass, protocolFilter, modelClassLoaderHash); toolsets.second().addCoder(eventClass, protocolFilter, modelClassLoaderHash); @@ -869,7 +867,7 @@ abstract class GenericEventProtocolCoder { while (toolsetsIter.hasNext()) { Pair<ProtocolCoderToolset, ProtocolCoderToolset> toolset = toolsetsIter.next(); if (toolset.first().getControllerId().equals(key)) { - logger.info("{}: removed coder from toolset for {} from reverse mapping {}: ", + logger.info("{}: removed coder from toolset for {} from reverse mapping", this, reverseKey); toolsetsIter.remove(); } @@ -1024,6 +1022,29 @@ abstract class GenericEventProtocolCoder { /** * encode an object into a json string. * + * @param topic topic + * @param encodedClass object to convert to string + * @return the json string + * @throws IllegalArgumentException if invalid argument is provided + * @throws UnsupportedOperationException if the operation cannot be performed + */ + public String encode(String topic, Object encodedClass, DroolsController droolsController) { + + if (encodedClass == null) { + throw new IllegalArgumentException("Invalid encoded class"); + } + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("Invalid topic"); + } + + String key = codersKey(droolsController.getGroupId(), droolsController.getArtifactId(), topic); + return this.encodeInternal(key, encodedClass); + } + + /** + * encode an object into a json string. + * * @param key identifier * @param event object to convert to string * @return the json string @@ -1069,29 +1090,6 @@ abstract class GenericEventProtocolCoder { } /** - * encode an object into a json string. - * - * @param topic topic - * @param encodedClass object to convert to string - * @return the json string - * @throws IllegalArgumentException if invalid argument is provided - * @throws UnsupportedOperationException if the operation cannot be performed - */ - public String encode(String topic, Object encodedClass, DroolsController droolsController) { - - if (encodedClass == null) { - throw new IllegalArgumentException("Invalid encoded class"); - } - - if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("Invalid topic"); - } - - String key = codersKey(droolsController.getGroupId(), droolsController.getArtifactId(), topic); - return this.encodeInternal(key, encodedClass); - } - - /** * Drools creators. * * @param topic topic @@ -1202,6 +1200,31 @@ abstract class GenericEventProtocolCoder { } /** + * get all filters by maven coordinates, topic, and classname. + * + * @param groupId group id + * @param artifactId artifact id + * @param topic topic + * @param classname classname + * @return list of coders + * @throws IllegalArgumentException if invalid input + */ + public CoderFilters getFilters(String groupId, String artifactId, String topic, String classname) { + + if (!isCodingSupported(groupId, artifactId, topic)) { + throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic)); + } + + if (classname == null || classname.isEmpty()) { + throw new IllegalArgumentException("classname must be provided"); + } + + String key = this.codersKey(groupId, artifactId, topic); + Pair<ProtocolCoderToolset,ProtocolCoderToolset> coderTools = coders.get(key); + return coderTools.first().getCoder(classname); + } + + /** * get all coders by maven coordinates and topic. * * @param groupId group id @@ -1251,31 +1274,6 @@ abstract class GenericEventProtocolCoder { } /** - * get all filters by maven coordinates, topic, and classname. - * - * @param groupId group id - * @param artifactId artifact id - * @param topic topic - * @param classname classname - * @return list of coders - * @throws IllegalArgumentException if invalid input - */ - public CoderFilters getFilters(String groupId, String artifactId, String topic, String classname) { - - if (!isCodingSupported(groupId, artifactId, topic)) { - throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic)); - } - - if (classname == null || classname.isEmpty()) { - throw new IllegalArgumentException("classname must be provided"); - } - - String key = this.codersKey(groupId, artifactId, topic); - Pair<ProtocolCoderToolset,ProtocolCoderToolset> coderTools = coders.get(key); - return coderTools.first().getCoder(classname); - } - - /** * get coded based on class and topic. * * @param topic topic @@ -1342,7 +1340,7 @@ abstract class GenericEventProtocolCoder { * * @param topic topic * @param fact fact - * @return + * @return list of drools controllers */ List<DroolsController> getDroolsControllers(String topic, Object fact) { diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java index 4fd2f522..f65efaed 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java @@ -287,7 +287,7 @@ public class JsonProtocolFilter { * Get rules. * * @param name name - * @return + * @return list of filter rules */ public List<FilterRule> getRules(String name) { if (name == null || name.isEmpty()) { 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 7ee8b08a..ead6794c 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 @@ -20,6 +20,21 @@ package org.onap.policy.drools.protocol.coders; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Type; @@ -38,637 +53,630 @@ import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.Cust import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - /** - * Protocol Coding/Decoding Toolset + * Protocol Coding/Decoding Toolset. */ public abstract class ProtocolCoderToolset { - /** - * Logger - */ - private static Logger logger = LoggerFactory.getLogger(ProtocolCoderToolset.class); - - /** - * topic - */ - protected final String topic; - - /** - * controller id - */ - protected final String controllerId; - - /** - * group id - */ - protected final String groupId; - - /** - * artifact id - */ - protected final String artifactId; - - /** - * Protocols and associated Filters - */ - protected final List<CoderFilters> coders = new CopyOnWriteArrayList<>(); - - /** - * Tree model (instead of class model) generic parsing to be able to inspect elements - */ - protected JsonParser filteringParser = new JsonParser(); - - /** - * custom coder - */ - protected CustomCoder customCoder; - - /** - * Constructor - * - * @param topic the topic - * @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) { - - if (topic == null || controllerId == null || groupId == null || artifactId == null - || codedClass == null || filters == null || topic.isEmpty() || controllerId.isEmpty()) { - throw new IllegalArgumentException("Invalid input"); + /** + * Logger. + */ + private static Logger logger = LoggerFactory.getLogger(ProtocolCoderToolset.class); + + /** + * topic. + */ + protected final String topic; + + /** + * controller id. + */ + protected final String controllerId; + + /** + * group id. + */ + protected final String groupId; + + /** + * artifact id. + */ + protected final String artifactId; + + /** + * Protocols and associated Filters. + */ + protected final List<CoderFilters> coders = new CopyOnWriteArrayList<>(); + + /** + * Tree model (instead of class model) generic parsing to be able to inspect elements. + */ + protected JsonParser filteringParser = new JsonParser(); + + /** + * custom coder. + */ + protected CustomCoder customCoder; + + /** + * Constructor. + * + * @param topic the topic + * @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) { + + if (topic == null || controllerId == null || groupId == null || artifactId == null + || codedClass == null || filters == null || topic.isEmpty() || controllerId.isEmpty()) { + throw new IllegalArgumentException("Invalid input"); + } + + this.topic = topic; + this.controllerId = controllerId; + this.groupId = groupId; + this.artifactId = artifactId; + this.coders.add(new CoderFilters(codedClass, filters, modelClassLoaderHash)); + this.customCoder = customCoder; + } + + /** + * gets the coder + filters associated with this class name. + * + * @param classname class name + * @return the decoder filters or null if not found + */ + public CoderFilters getCoder(String classname) { + if (classname == null || classname.isEmpty()) { + throw new IllegalArgumentException("no classname provided"); + } + + for (final CoderFilters decoder : this.coders) { + if (decoder.factClass.equals(classname)) { + return decoder; + } + } + return null; + } + + /** + * get a copy of the coder filters in use. + * + * @return coder filters + */ + public List<CoderFilters> getCoders() { + return new ArrayList<>(this.coders); + } + + /** + * add coder or replace it exists. + * + * @param eventClass decoder + * @param filter filter + */ + public void addCoder(String eventClass, JsonProtocolFilter filter, int modelClassLoaderHash) { + if (eventClass == null || eventClass.isEmpty()) { + throw new IllegalArgumentException("no event class provided"); + } + + for (final CoderFilters coder : this.coders) { + if (coder.getCodedClass().equals(eventClass)) { + coder.setFilter(filter); + coder.setFromClassLoaderHash(modelClassLoaderHash); + return; + } + } + this.coders.add(new CoderFilters(eventClass, filter, modelClassLoaderHash)); + } + + /** + * remove coder. + * + * @param eventClass event class + */ + public void removeCoders(String eventClass) { + if (eventClass == null || eventClass.isEmpty()) { + throw new IllegalArgumentException("no event class provided"); + } + + List<CoderFilters> temp = new ArrayList<>(); + for (final CoderFilters coder : this.coders) { + if (coder.factClass.equals(eventClass)) { + temp.add(coder); + } + } + + this.coders.removeAll(temp); } - this.topic = topic; - this.controllerId = controllerId; - this.groupId = groupId; - this.artifactId = artifactId; - this.coders.add(new CoderFilters(codedClass, filters, modelClassLoaderHash)); - this.customCoder = customCoder; - } - - /** - * gets the coder + filters associated with this class name - * - * @param classname class name - * @return the decoder filters or null if not found - */ - public CoderFilters getCoder(String classname) { - if (classname == null || classname.isEmpty()) - throw new IllegalArgumentException("no classname provided"); - - for (final CoderFilters decoder : this.coders) { - if (decoder.factClass.equals(classname)) { - return decoder; - } + /** + * gets the topic. + * + * @return the topic + */ + public String getTopic() { + return this.topic; } - return null; - } - - /** - * get a copy of the coder filters in use - * - * @return coder filters - */ - public List<CoderFilters> getCoders() { - return new ArrayList<>(this.coders); - } - - /** - * add coder or replace it exists - * - * @param eventClass decoder - * @param filter filter - */ - public void addCoder(String eventClass, JsonProtocolFilter filter, int modelClassLoaderHash) { - if (eventClass == null || eventClass.isEmpty()) - throw new IllegalArgumentException("no event class provided"); - - for (final CoderFilters coder : this.coders) { - if (coder.getCodedClass().equals(eventClass)) { - coder.setFilter(filter); - coder.setFromClassLoaderHash(modelClassLoaderHash); - return; - } + + /** + * gets the controller id. + * + * @return the controller id + */ + public String getControllerId() { + return this.controllerId; } - this.coders.add(new CoderFilters(eventClass, filter, modelClassLoaderHash)); - } - - /** - * remove coder - * @param eventClass event class - */ - public void removeCoders(String eventClass) { - if (eventClass == null || eventClass.isEmpty()) - throw new IllegalArgumentException("no event class provided"); - - List<CoderFilters> temp = new ArrayList<>(); - for (final CoderFilters coder : this.coders) { - if (coder.factClass.equals(eventClass)) { - temp.add(coder); - } + + /** + * Get group id. + * + * @return the groupId + */ + public String getGroupId() { + return this.groupId; } - this.coders.removeAll(temp); - } - - /** - * gets the topic - * - * @return the topic - */ - public String getTopic() { - return this.topic; - } - - /** - * gets the controller id - * - * @return the controller id - */ - public String getControllerId() { - return this.controllerId; - } - - /** - * @return the groupId - */ - public String getGroupId() { - return this.groupId; - } - - /** - * @return the artifactId - */ - public String getArtifactId() { - return this.artifactId; - } - - /** - * @return the customCoder - */ - public CustomCoder getCustomCoder() { - return this.customCoder; - } - - /** - * @param customCoder the customCoder to set - */ - public void setCustomCoder(CustomCoder customCoder) { - this.customCoder = customCoder; - } - - /** - * performs filtering on a json string - * - * @param json json string - * @return the decoder that passes the filter, otherwise null - * @throws UnsupportedOperationException can't filter - * @throws IllegalArgumentException invalid input - */ - protected CoderFilters filter(String json) { - - - // 1. Get list of decoding classes for this controller Id and topic - // 2. If there are no classes, return error - // 3. Otherwise, from the available classes for decoding, pick the first one that - // passes the filters - - // Don't parse if it is not necessary - - if (this.coders.isEmpty()) { - throw new IllegalStateException("No coders available"); + /** + * Get artifact id. + * + * @return the artifactId + */ + public String getArtifactId() { + return this.artifactId; } - if (this.coders.size() == 1) { - final JsonProtocolFilter filter = this.coders.get(0).getFilter(); - if (!filter.isRules()) { - return this.coders.get(0); - } + /** + * Get custom coder. + * + * @return the customCoder + */ + public CustomCoder getCustomCoder() { + return this.customCoder; } - JsonElement event; - try { - event = this.filteringParser.parse(json); - } catch (final Exception e) { - throw new UnsupportedOperationException(e); + /** + * Set custom coder. + * + * @param customCoder the customCoder to set. + */ + public void setCustomCoder(CustomCoder customCoder) { + this.customCoder = customCoder; } - for (final CoderFilters decoder : this.coders) { - try { - final boolean accepted = decoder.getFilter().accept(event); - if (accepted) { - return decoder; + /** + * performs filtering on a json string. + * + * @param json json string + * @return the decoder that passes the filter, otherwise null + * @throws UnsupportedOperationException can't filter + * @throws IllegalArgumentException invalid input + */ + protected CoderFilters filter(String json) { + + + // 1. Get list of decoding classes for this controller Id and topic + // 2. If there are no classes, return error + // 3. Otherwise, from the available classes for decoding, pick the first one that + // passes the filters + + // Don't parse if it is not necessary + + if (this.coders.isEmpty()) { + throw new IllegalStateException("No coders available"); } - } catch (final Exception e) { - logger.info("{}: unexpected failure accepting {} because of {}", this, event, - e.getMessage(), e); - // continue - } + + if (this.coders.size() == 1) { + final JsonProtocolFilter filter = this.coders.get(0).getFilter(); + if (!filter.isRules()) { + return this.coders.get(0); + } + } + + JsonElement event; + try { + event = this.filteringParser.parse(json); + } catch (final Exception e) { + throw new UnsupportedOperationException(e); + } + + for (final CoderFilters decoder : this.coders) { + try { + final boolean accepted = decoder.getFilter().accept(event); + if (accepted) { + return decoder; + } + } catch (final Exception e) { + logger.info("{}: unexpected failure accepting {} because of {}", this, event, + e.getMessage(), e); + // continue + } + } + + return null; } - return null; - } - - /** - * Decode json into a POJO object - * - * @param json json string - * - * @return a POJO object for the json string - * @throws IllegalArgumentException if an invalid parameter has been received - * @throws UnsupportedOperationException if parsing into POJO is not possible - */ - public abstract Object decode(String json); - - /** - * Encodes a POJO object into a JSON String - * - * @param event JSON POJO event to be converted to String - * @return JSON string version of POJO object - * @throws IllegalArgumentException if an invalid parameter has been received - * @throws UnsupportedOperationException if parsing into POJO is not possible - */ - public abstract String encode(Object event); - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("ProtocolCoderToolset [topic=").append(this.topic).append(", controllerId=") + /** + * Decode json into a POJO object. + * + * @param json json string + * + * @return a POJO object for the json string + * @throws IllegalArgumentException if an invalid parameter has been received + * @throws UnsupportedOperationException if parsing into POJO is not possible + */ + public abstract Object decode(String json); + + /** + * Encodes a POJO object into a JSON String. + * + * @param event JSON POJO event to be converted to String + * @return JSON string version of POJO object + * @throws IllegalArgumentException if an invalid parameter has been received + * @throws UnsupportedOperationException if parsing into POJO is not possible + */ + public abstract String encode(Object event); + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("ProtocolCoderToolset [topic=").append(this.topic).append(", controllerId=") .append(this.controllerId).append(", groupId=").append(this.groupId).append(", artifactId=") .append(this.artifactId).append(", coders=").append(this.coders) .append(", filteringParser=").append(this.filteringParser).append(", customCoder=") .append(this.customCoder).append("]"); - return builder.toString(); - } + return builder.toString(); + } } /** - * Tools used for encoding/decoding using Jackson + * Tools used for encoding/decoding using Jackson. */ class JacksonProtocolCoderToolset extends ProtocolCoderToolset { - private static final String WARN_FETCH_FAILED = "{}: cannot fetch application class {}"; -private static final String WARN_FETCH_FAILED_BECAUSE = "{}: cannot fetch application class {} because of {}"; -private static final String FETCH_FAILED = "cannot fetch application class "; -private static final String ENCODE_FAILED = "event cannot be encoded"; -private static Logger logger = LoggerFactory.getLogger(JacksonProtocolCoderToolset.class); - /** - * decoder - */ - @JsonIgnore - protected final ObjectMapper decoder = new ObjectMapper(); - - /** - * encoder - */ - @JsonIgnore - protected final ObjectMapper encoder = new ObjectMapper(); - - /** - * Toolset to encode/decode tools associated with a topic - * - * @param topic topic - * @param decodedClass decoded class of an event - * @param filter - */ - 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); - this.decoder.registerModule(new JavaTimeModule()); - this.decoder.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - } - - /** - * gets the Jackson decoder - * - * @return the Jackson decoder - */ - @JsonIgnore - protected ObjectMapper getDecoder() { - return this.decoder; - } - - /** - * gets the Jackson encoder - * - * @return the Jackson encoder - */ - @JsonIgnore - protected ObjectMapper getEncoder() { - return this.encoder; - } - - /** - * {@inheritDoc} - */ - @Override - public Object decode(String json) { - - // 0. Use custom coder if available - - if (this.customCoder != null) { - throw new UnsupportedOperationException( - "Jackon Custom Decoder is not supported at this time"); + private static final String WARN_FETCH_FAILED = "{}: cannot fetch application class {}"; + private static final String WARN_FETCH_FAILED_BECAUSE = "{}: cannot fetch application class {} because of {}"; + private static final String FETCH_FAILED = "cannot fetch application class "; + private static final String ENCODE_FAILED = "event cannot be encoded"; + private static Logger logger = LoggerFactory.getLogger(JacksonProtocolCoderToolset.class); + + /** + * decoder. + */ + @JsonIgnore + protected final ObjectMapper decoder = new ObjectMapper(); + + /** + * encoder. + */ + @JsonIgnore + protected final ObjectMapper encoder = new ObjectMapper(); + + /** + * Toolset to encode/decode tools associated with a topic. + * + * @param topic topic + * @param decodedClass decoded class of an event + * @param filter filter + */ + 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); + this.decoder.registerModule(new JavaTimeModule()); + this.decoder.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } - final DroolsController droolsController = - DroolsController.factory.get(this.groupId, this.artifactId, ""); - if (droolsController == null) { - logger.warn("{}: no drools-controller to process {}", this, json); - throw new IllegalStateException("no drools-controller to process event"); + /** + * gets the Jackson decoder. + * + * @return the Jackson decoder + */ + @JsonIgnore + protected ObjectMapper getDecoder() { + return this.decoder; } - final CoderFilters decoderFilter = this.filter(json); - if (decoderFilter == null) { - logger.debug("{}: no decoder to process {}", this, json); - throw new UnsupportedOperationException("no decoder to process event"); + /** + * gets the Jackson encoder. + * + * @return the Jackson encoder + */ + @JsonIgnore + protected ObjectMapper getEncoder() { + return this.encoder; } - Class<?> decoderClass; - try { - decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass()); - if (decoderClass == null) { - logger.warn(WARN_FETCH_FAILED, this, decoderFilter.getCodedClass()); - throw new IllegalStateException( - FETCH_FAILED + decoderFilter.getCodedClass()); - } - } catch (final Exception e) { - logger.warn(WARN_FETCH_FAILED_BECAUSE, this, - decoderFilter.getCodedClass(), e.getMessage()); - throw new UnsupportedOperationException( - FETCH_FAILED + decoderFilter.getCodedClass(), e); - } + /** + * {@inheritDoc}. + */ + @Override + public Object decode(String json) { + // 0. Use custom coder if available - try { - return this.decoder.readValue(json, decoderClass); - } catch (final Exception e) { - logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(), - e.getMessage(), e); - throw new UnsupportedOperationException( - "cannont decode into " + decoderFilter.getCodedClass(), e); - } - } + if (this.customCoder != null) { + throw new UnsupportedOperationException( + "Jackon Custom Decoder is not supported at this time"); + } - /** - * {@inheritDoc} - */ - @Override - public String encode(Object event) { + final DroolsController droolsController = + DroolsController.factory.get(this.groupId, this.artifactId, ""); + if (droolsController == null) { + logger.warn("{}: no drools-controller to process {}", this, json); + throw new IllegalStateException("no drools-controller to process event"); + } - // 0. Use custom coder if available + final CoderFilters decoderFilter = this.filter(json); + if (decoderFilter == null) { + logger.debug("{}: no decoder to process {}", this, json); + throw new UnsupportedOperationException("no decoder to process event"); + } - if (this.customCoder != null) { - throw new UnsupportedOperationException( - "Jackon Custom Encoder is not supported at this time"); + Class<?> decoderClass; + try { + decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass()); + if (decoderClass == null) { + logger.warn(WARN_FETCH_FAILED, this, decoderFilter.getCodedClass()); + throw new IllegalStateException( + FETCH_FAILED + decoderFilter.getCodedClass()); + } + } catch (final Exception e) { + logger.warn(WARN_FETCH_FAILED_BECAUSE, this, + decoderFilter.getCodedClass(), e.getMessage()); + throw new UnsupportedOperationException( + FETCH_FAILED + decoderFilter.getCodedClass(), e); + } + + + try { + return this.decoder.readValue(json, decoderClass); + } catch (final Exception e) { + logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(), + e.getMessage(), e); + throw new UnsupportedOperationException( + "cannont decode into " + decoderFilter.getCodedClass(), e); + } } - try { - return this.encoder.writeValueAsString(event); - } catch (final JsonProcessingException e) { - logger.error("{} cannot encode {} because of {}", this, event, e.getMessage(), e); - throw new UnsupportedOperationException(ENCODE_FAILED); + /** + * {@inheritDoc}. + */ + @Override + public String encode(Object event) { + + // 0. Use custom coder if available + + if (this.customCoder != null) { + throw new UnsupportedOperationException( + "Jackon Custom Encoder is not supported at this time"); + } + + try { + return this.encoder.writeValueAsString(event); + } catch (final JsonProcessingException e) { + logger.error("{} cannot encode {} because of {}", this, event, e.getMessage(), e); + throw new UnsupportedOperationException(ENCODE_FAILED); + } } - } - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("JacksonProtocolCoderToolset [toString()=").append(super.toString()).append("]"); - return builder.toString(); - } + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("JacksonProtocolCoderToolset [toString()=").append(super.toString()).append("]"); + return builder.toString(); + } } /** - * Tools used for encoding/decoding using Jackson + * Tools used for encoding/decoding using Jackson. */ class GsonProtocolCoderToolset extends ProtocolCoderToolset { - /** - * Logger - */ - private static final Logger logger = LoggerFactory.getLogger(GsonProtocolCoderToolset.class); - - /** - * Formatter for JSON encoding/decoding - */ - @JsonIgnore - public static final DateTimeFormatter format = - DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); - - @JsonIgnore - public static final DateTimeFormatter zuluFormat = DateTimeFormatter.ISO_INSTANT; - - /** - * Adapter for ZonedDateTime - */ - public static class GsonUTCAdapter - implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> { - @Override - public ZonedDateTime deserialize(JsonElement element, Type type, - JsonDeserializationContext context) { - try { - return ZonedDateTime.parse(element.getAsString(), format); - } catch (final Exception e) { - logger.info("GsonUTCAdapter: cannot parse {} because of {}", element, e.getMessage(), e); - } - return null; - } + /** + * Logger. + */ + private static final Logger logger = LoggerFactory.getLogger(GsonProtocolCoderToolset.class); + + /** + * Formatter for JSON encoding/decoding. + */ + @JsonIgnore + public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); + + @JsonIgnore + public static final DateTimeFormatter zuluFormat = DateTimeFormatter.ISO_INSTANT; + + /** + * Adapter for ZonedDateTime. + */ + public static class GsonUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> { + @Override + public ZonedDateTime deserialize(JsonElement element, Type type, + JsonDeserializationContext context) { + try { + return ZonedDateTime.parse(element.getAsString(), format); + } catch (final Exception e) { + logger.info("GsonUTCAdapter: cannot parse {} because of {}", element, e.getMessage(), e); + } + return null; + } - @Override - public JsonElement serialize(ZonedDateTime datetime, Type type, - JsonSerializationContext context) { - return new JsonPrimitive(datetime.format(format)); + @Override + public JsonElement serialize(ZonedDateTime datetime, Type type, + JsonSerializationContext context) { + return new JsonPrimitive(datetime.format(format)); + } } - } - public static class GsonInstantAdapter - implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + public static class GsonInstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { - @Override - public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { - return Instant.ofEpochMilli(json.getAsLong()); - } + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return Instant.ofEpochMilli(json.getAsLong()); + } - @Override - public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { - return new JsonPrimitive(src.toEpochMilli()); - } + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toEpochMilli()); + } - } - - - /** - * decoder - */ - @JsonIgnore - protected final Gson decoder = new GsonBuilder().disableHtmlEscaping() - .registerTypeAdapter(ZonedDateTime.class, new GsonUTCAdapter()) - .registerTypeAdapter(Instant.class, new GsonInstantAdapter()).create(); - - /** - * encoder - */ - @JsonIgnore - protected final Gson encoder = new GsonBuilder().disableHtmlEscaping() - .registerTypeAdapter(ZonedDateTime.class, new GsonUTCAdapter()) - .registerTypeAdapter(Instant.class, new GsonInstantAdapter()).create(); - - /** - * Toolset to encode/decode tools associated with a topic - * - * @param topic topic - * @param decodedClass decoded class of an event - * @param filter - */ - 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); - } - - /** - * gets the Gson decoder - * - * @return the Gson decoder - */ - @JsonIgnore - protected Gson getDecoder() { - return this.decoder; - } - - /** - * gets the Gson encoder - * - * @return the Gson encoder - */ - @JsonIgnore - protected Gson getEncoder() { - return this.encoder; - } - - /** - * {@inheritDoc} - */ - @Override - public Object decode(String json) { - - final DroolsController droolsController = - DroolsController.factory.get(this.groupId, this.artifactId, ""); - if (droolsController == null) { - logger.warn("{}: no drools-controller to process {}", this, json); - throw new IllegalStateException("no drools-controller to process event"); } - final CoderFilters decoderFilter = this.filter(json); - if (decoderFilter == null) { - logger.debug("{}: no decoder to process {}", this, json); - throw new UnsupportedOperationException("no decoder to process event"); + + /** + * decoder. + */ + @JsonIgnore + protected final Gson decoder = new GsonBuilder().disableHtmlEscaping() + .registerTypeAdapter(ZonedDateTime.class, new GsonUTCAdapter()) + .registerTypeAdapter(Instant.class, new GsonInstantAdapter()).create(); + + /** + * encoder. + */ + @JsonIgnore + protected final Gson encoder = new GsonBuilder().disableHtmlEscaping() + .registerTypeAdapter(ZonedDateTime.class, new GsonUTCAdapter()) + .registerTypeAdapter(Instant.class, new GsonInstantAdapter()).create(); + + /** + * Toolset to encode/decode tools associated with a topic. + * + * @param topic topic + * @param decodedClass decoded class of an event + * @param filter filter + */ + 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); } - Class<?> decoderClass; - try { - decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass()); - if (decoderClass == null) { - logger.warn("{}: cannot fetch application class {}", this, decoderFilter.getCodedClass()); - throw new IllegalStateException( - "cannot fetch application class " + decoderFilter.getCodedClass()); - } - } catch (final Exception e) { - logger.warn("{}: cannot fetch application class {} because of {}", this, - decoderFilter.getCodedClass(), e.getMessage()); - throw new UnsupportedOperationException( - "cannot fetch application class " + decoderFilter.getCodedClass(), e); + /** + * gets the Gson decoder. + * + * @return the Gson decoder + */ + @JsonIgnore + protected Gson getDecoder() { + return this.decoder; } - if (this.customCoder != null) { - try { - final Class<?> gsonClassContainer = - droolsController.fetchModelClass(this.customCoder.getClassContainer()); - final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField); - final Object gsonObject = gsonField.get(null); - final Method fromJsonMethod = gsonObject.getClass().getDeclaredMethod("fromJson", - new Class[] {String.class, Class.class}); - return fromJsonMethod.invoke(gsonObject, json, decoderClass); - } catch (final Exception e) { - logger.warn("{}: cannot fetch application class {} because of {}", this, - decoderFilter.getCodedClass(), e.getMessage()); - throw new UnsupportedOperationException( - "cannot fetch application class " + decoderFilter.getCodedClass(), e); - } - } else { - try { - return this.decoder.fromJson(json, decoderClass); - } catch (final Exception e) { - logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(), - e.getMessage(), e); - throw new UnsupportedOperationException( - "cannont decode into " + decoderFilter.getCodedClass(), e); - } + /** + * gets the Gson encoder. + * + * @return the Gson encoder + */ + @JsonIgnore + protected Gson getEncoder() { + return this.encoder; } - } + /** + * {@inheritDoc}. + */ + @Override + public Object decode(String json) { + + final DroolsController droolsController = + DroolsController.factory.get(this.groupId, this.artifactId, ""); + if (droolsController == null) { + logger.warn("{}: no drools-controller to process {}", this, json); + throw new IllegalStateException("no drools-controller to process event"); + } + final CoderFilters decoderFilter = this.filter(json); + if (decoderFilter == null) { + logger.debug("{}: no decoder to process {}", this, json); + throw new UnsupportedOperationException("no decoder to process event"); + } - /** - * {@inheritDoc} - */ - @Override - public String encode(Object event) { + Class<?> decoderClass; + try { + decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass()); + if (decoderClass == null) { + logger.warn("{}: cannot fetch application class {}", this, decoderFilter.getCodedClass()); + throw new IllegalStateException( + "cannot fetch application class " + decoderFilter.getCodedClass()); + } + } catch (final Exception e) { + logger.warn("{}: cannot fetch application class {} because of {}", this, + decoderFilter.getCodedClass(), e.getMessage()); + throw new UnsupportedOperationException( + "cannot fetch application class " + decoderFilter.getCodedClass(), e); + } - if (this.customCoder != null) { - try { - final DroolsController droolsController = - DroolsController.factory.get(this.groupId, this.artifactId, null); - final Class<?> gsonClassContainer = - droolsController.fetchModelClass(this.customCoder.getClassContainer()); - final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField); - final Object gsonObject = gsonField.get(null); - final Method toJsonMethod = - gsonObject.getClass().getDeclaredMethod("toJson", new Class[] {Object.class}); - return (String) toJsonMethod.invoke(gsonObject, event); - } catch (final Exception e) { - logger.warn("{} cannot custom-encode {} because of {}", this, event, e.getMessage(), e); - throw new UnsupportedOperationException("event cannot be encoded", e); - } - } else { - try { - return this.encoder.toJson(event); - } catch (final Exception e) { - logger.warn("{} cannot encode {} because of {}", this, event, e.getMessage(), e); - throw new UnsupportedOperationException("event cannot be encoded", e); - } + if (this.customCoder != null) { + try { + final Class<?> gsonClassContainer = + droolsController.fetchModelClass(this.customCoder.getClassContainer()); + final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField); + final Object gsonObject = gsonField.get(null); + final Method fromJsonMethod = gsonObject.getClass().getDeclaredMethod("fromJson", + new Class[] {String.class, Class.class}); + return fromJsonMethod.invoke(gsonObject, json, decoderClass); + } catch (final Exception e) { + logger.warn("{}: cannot fetch application class {} because of {}", this, + decoderFilter.getCodedClass(), e.getMessage()); + throw new UnsupportedOperationException( + "cannot fetch application class " + decoderFilter.getCodedClass(), e); + } + } else { + try { + return this.decoder.fromJson(json, decoderClass); + } catch (final Exception e) { + logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(), + e.getMessage(), e); + throw new UnsupportedOperationException( + "cannont decode into " + decoderFilter.getCodedClass(), e); + } + } + } + + /** + * {@inheritDoc}. + */ + @Override + public String encode(Object event) { + + if (this.customCoder != null) { + try { + final DroolsController droolsController = + DroolsController.factory.get(this.groupId, this.artifactId, null); + final Class<?> gsonClassContainer = + droolsController.fetchModelClass(this.customCoder.getClassContainer()); + final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField); + final Object gsonObject = gsonField.get(null); + final Method toJsonMethod = + gsonObject.getClass().getDeclaredMethod("toJson", new Class[] {Object.class}); + return (String) toJsonMethod.invoke(gsonObject, event); + } catch (final Exception e) { + logger.warn("{} cannot custom-encode {} because of {}", this, event, e.getMessage(), e); + throw new UnsupportedOperationException("event cannot be encoded", e); + } + } else { + try { + return this.encoder.toJson(event); + } catch (final Exception e) { + logger.warn("{} cannot encode {} because of {}", this, event, e.getMessage(), e); + throw new UnsupportedOperationException("event cannot be encoded", e); + } + } + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("GsonProtocolCoderToolset [toString()=").append(super.toString()).append("]"); + return builder.toString(); } - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("GsonProtocolCoderToolset [toString()=").append(super.toString()).append("]"); - return builder.toString(); - } } diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java index 7c1b128f..f7fc4d21 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java @@ -24,286 +24,308 @@ import java.util.List; public class TopicCoderFilterConfiguration { - /** - * Custom coder, contains class and static field to access parser that the controller - * desires to use instead of the framework provided parser - */ - public abstract static class CustomCoder { - protected String className; - protected String staticCoderField; - - /** - * create custom coder from raw string in the following format - * (typically embedded in a property file): - * - * Note this is to support decoding/encoding of partial structures that are - * only known by the model. - * - * @param rawCustomCoder with format: <class-containing-custom-coder>,<static-coder-field> - */ - public CustomCoder(String rawCustomCoder) { - if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) { - - this.className = rawCustomCoder.substring(0,rawCustomCoder.indexOf(",")); - if (this.className == null || this.className.isEmpty()) { - throw new IllegalArgumentException("No classname to create CustomCoder cannot be created"); - } - - this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(",")+1); - if (this.staticCoderField == null || this.staticCoderField.isEmpty()) { - throw new IllegalArgumentException - ("No staticCoderField to create CustomCoder cannot be created for class " + - className); - } - - } - } - /** - * @param classContainer - * @param staticCoderField - */ - public CustomCoder(String className, String staticCoderField) { - if (className == null || className.isEmpty()) { - throw new IllegalArgumentException("No classname to create CustomCoder cannot be created"); - } - - if (staticCoderField == null || staticCoderField.isEmpty()) { - throw new IllegalArgumentException - ("No staticCoderField to create CustomCoder cannot be created for class " + - className); - } - - this.className = className; - this.staticCoderField = staticCoderField; - } - - /** - * @return the className - */ - public String getClassContainer() { - return className; - } - - /** - * @param className the className to set - */ - public void setClassContainer(String className) { - this.className = className; - } - - /** - * @return the staticCoderField - */ - public String getStaticCoderField() { - return staticCoderField; - } - - /** - * @param staticCoderField the staticGson to set - */ - public void setStaticCoderField(String staticCoderField) { - this.staticCoderField = staticCoderField; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("CustomCoder [className=").append(className).append(", staticCoderField=") - .append(staticCoderField).append("]"); - return builder.toString(); - } - } - - public static class CustomGsonCoder extends CustomCoder { - - public CustomGsonCoder(String className, String staticCoderField) { - super(className, staticCoderField); - } - - public CustomGsonCoder(String customGson) { - super(customGson); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("CustomGsonCoder [toString()=").append(super.toString()).append("]"); - return builder.toString(); - } - - } - - public static class CustomJacksonCoder extends CustomCoder { - - public CustomJacksonCoder(String className, String staticCoderField) { - super(className, staticCoderField); - } - - public CustomJacksonCoder(String customJackson) { - super(customJackson); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("CustomJacksonCoder [toString()=").append(super.toString()).append("]"); - return builder.toString(); - } - - } - - /** - * Coder/Decoder class and Filter container. The decoder class is potential, - * in order to be operational needs to be fetched from an available - * class loader. - * - */ - public static class PotentialCoderFilter { - - /** - * decoder class (pending from being able to be fetched and found - * in some class loader) - */ - protected String codedClass; - - /** - * filters to apply to the selection of the decodedClass; - */ - protected JsonProtocolFilter filter; - - /** - * constructor - * - * @param codedClass decoder class - * @param filter filters to apply - */ - public PotentialCoderFilter(String codedClass, JsonProtocolFilter filter) { - this.codedClass = codedClass; - this.filter = filter; - } - - /** - * @return the decodedClass - */ - public String getCodedClass() { - return codedClass; - } - - /** - * @param decodedClass the decodedClass to set - */ - public void setCodedClass(String decodedClass) { - this.codedClass = decodedClass; - } - - /** - * @return the filter - */ - public JsonProtocolFilter getFilter() { - return filter; - } - - /** - * @param filter the filter to set - */ - public void setFilter(JsonProtocolFilter filter) { - this.filter = filter; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("PotentialCoderFilter [codedClass=").append(codedClass).append(", filter=").append(filter) - .append("]"); - return builder.toString(); - } - } - - /** - * the source topic - */ - protected final String topic; - - /** - * List of decoder -> filters - */ - protected final List<PotentialCoderFilter> coderFilters; - - /** - * custom gson coder that this controller prefers to use instead of the framework ones - */ - protected CustomGsonCoder customGsonCoder; - - /** - * custom jackson coder that this controller prefers to use instead of the framework ones - */ - protected CustomJacksonCoder customJacksonCoder; - - /** - * Constructor - * - * @param decoderFilters list of decoders and associated filters - * @param topic the topic - */ - public TopicCoderFilterConfiguration(String topic, List<PotentialCoderFilter> decoderFilters, - CustomGsonCoder customGsonCoder, - CustomJacksonCoder customJacksonCoder) { - this.coderFilters = decoderFilters; - this.topic = topic; - this.customGsonCoder = customGsonCoder; - this.customJacksonCoder = customJacksonCoder; - } - - /** - * @return the topic - */ - public String getTopic() { - return topic; - } - - /** - * @return the decoderFilters - */ - public List<PotentialCoderFilter> getCoderFilters() { - return coderFilters; - } - - /** - * @return the customGsonCoder - */ - public CustomGsonCoder getCustomGsonCoder() { - return customGsonCoder; - } - - /** - * @param customGsonCoder the customGsonCoder to set - */ - public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) { - this.customGsonCoder = customGsonCoder; - } - - /** - * @return the customJacksonCoder - */ - public CustomJacksonCoder getCustomJacksonCoder() { - return customJacksonCoder; - } - - /** - * @param customJacksonCoder the customJacksonCoder to set - */ - public void setCustomJacksonCoder(CustomJacksonCoder customJacksonCoder) { - this.customJacksonCoder = customJacksonCoder; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("TopicCoderFilterConfiguration [topic=").append(topic).append(", coderFilters=") - .append(coderFilters).append(", customGsonCoder=").append(customGsonCoder) - .append(", customJacksonCoder=").append(customJacksonCoder).append("]"); - return builder.toString(); - } + /** + * Custom coder, contains class and static field to access parser that the controller desires to + * use instead of the framework provided parser. + */ + public abstract static class CustomCoder { + protected String className; + protected String staticCoderField; + /** + * create custom coder from raw string in the following format (typically embedded in a property + * file): + * + * <p>Note this is to support decoding/encoding of partial structures that are only known by the + * model. + * + * @param rawCustomCoder with format: <class-containing-custom-coder>,<static-coder-field>. + */ + public CustomCoder(String rawCustomCoder) { + if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) { + this.className = rawCustomCoder.substring(0, rawCustomCoder.indexOf(",")); + if (this.className == null || this.className.isEmpty()) { + throw new IllegalArgumentException( + "No classname to create CustomCoder cannot be created"); + } + + this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(",") + 1); + if (this.staticCoderField == null || this.staticCoderField.isEmpty()) { + throw new IllegalArgumentException( + "No staticCoderField to create CustomCoder cannot be created for class " + className); + } + } + } + + /** + * Constructor. + * + * @param className class name + * @param staticCoderField static coder field + */ + public CustomCoder(String className, String staticCoderField) { + if (className == null || className.isEmpty()) { + throw new IllegalArgumentException("No classname to create CustomCoder cannot be created"); + } + + if (staticCoderField == null || staticCoderField.isEmpty()) { + throw new IllegalArgumentException( + "No staticCoderField to create CustomCoder cannot be created for class " + className); + } + + this.className = className; + this.staticCoderField = staticCoderField; + } + + /** + * Get class container. + * + * @return the className + **/ + public String getClassContainer() { + return className; + } + + /** + * Set class container. + * + * @param className the className to set + **/ + public void setClassContainer(String className) { + this.className = className; + } + + /** + * Get static coder field. + * + * @return the staticCoderField + **/ + public String getStaticCoderField() { + return staticCoderField; + } + + /** + * Set static coder field. + * + * @param staticCoderField the staticGson to set + **/ + public void setStaticCoderField(String staticCoderField) { + this.staticCoderField = staticCoderField; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder + .append("CustomCoder [className=") + .append(className) + .append(", staticCoderField=") + .append(staticCoderField) + .append("]"); + return builder.toString(); + } + } + + public static class CustomGsonCoder extends CustomCoder { + + public CustomGsonCoder(String className, String staticCoderField) { + super(className, staticCoderField); + } + + public CustomGsonCoder(String customGson) { + super(customGson); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CustomGsonCoder [toString()=").append(super.toString()).append("]"); + return builder.toString(); + } + } + + public static class CustomJacksonCoder extends CustomCoder { + + public CustomJacksonCoder(String className, String staticCoderField) { + super(className, staticCoderField); + } + + public CustomJacksonCoder(String customJackson) { + super(customJackson); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CustomJacksonCoder [toString()=").append(super.toString()).append("]"); + return builder.toString(); + } + } + + /** + * Coder/Decoder class and Filter container. The decoder class is potential, in order to be + * operational needs to be fetched from an available class loader. + */ + public static class PotentialCoderFilter { + + /* decoder class (pending from being able to be fetched and found in some class loader) */ + protected String codedClass; + + /* filters to apply to the selection of the decodedClass; */ + protected JsonProtocolFilter filter; + + /** + * constructor. + * + * @param codedClass decoder class + * @param filter filters to apply + */ + public PotentialCoderFilter(String codedClass, JsonProtocolFilter filter) { + this.codedClass = codedClass; + this.filter = filter; + } + + /** + * Get coded class. + * + * @return the decodedClass + **/ + public String getCodedClass() { + return codedClass; + } + + /** Set coded class. + * + * @param decodedClass the decodedClass to set + **/ + public void setCodedClass(String decodedClass) { + this.codedClass = decodedClass; + } + + /** + * Get filter. + * + * @return the filter + **/ + public JsonProtocolFilter getFilter() { + return filter; + } + + /** + * Set filter. + * + * @param filter the filter to set + **/ + public void setFilter(JsonProtocolFilter filter) { + this.filter = filter; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder + .append("PotentialCoderFilter [codedClass=") + .append(codedClass) + .append(", filter=") + .append(filter) + .append("]"); + return builder.toString(); + } + } + + /* the source topic */ + protected final String topic; + + /* List of decoder -> filters */ + protected final List<PotentialCoderFilter> coderFilters; + + /* custom gson coder that this controller prefers to use instead of the framework ones */ + protected CustomGsonCoder customGsonCoder; + + /* custom jackson coder that this controller prefers to use instead of the framework ones */ + protected CustomJacksonCoder customJacksonCoder; + + /** + * Constructor. + * + * @param decoderFilters list of decoders and associated filters + * @param topic the topic + */ + public TopicCoderFilterConfiguration( + String topic, + List<PotentialCoderFilter> decoderFilters, + CustomGsonCoder customGsonCoder, + CustomJacksonCoder customJacksonCoder) { + this.coderFilters = decoderFilters; + this.topic = topic; + this.customGsonCoder = customGsonCoder; + this.customJacksonCoder = customJacksonCoder; + } + + /** + * Get topic. + * @return the topic + **/ + public String getTopic() { + return topic; + } + + /** Get coder filters. + * + * @return the decoderFilters + **/ + public List<PotentialCoderFilter> getCoderFilters() { + return coderFilters; + } + + /** + * Get custom gson coder. + * + * @return the customGsonCoder + **/ + public CustomGsonCoder getCustomGsonCoder() { + return customGsonCoder; + } + + /** + * Set custom gson coder. + * + * @param customGsonCoder the customGsonCoder to set + **/ + public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) { + this.customGsonCoder = customGsonCoder; + } + + /** Get custom jackson coder. + * + * @return the customJacksonCoder + **/ + public CustomJacksonCoder getCustomJacksonCoder() { + return customJacksonCoder; + } + + /** + * Set custom Jackson coder. + * @param customJacksonCoder the customJacksonCoder to set + **/ + public void setCustomJacksonCoder(CustomJacksonCoder customJacksonCoder) { + this.customJacksonCoder = customJacksonCoder; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder + .append("TopicCoderFilterConfiguration [topic=") + .append(topic) + .append(", coderFilters=") + .append(coderFilters) + .append(", customGsonCoder=") + .append(customGsonCoder) + .append(", customJacksonCoder=") + .append(customJacksonCoder) + .append("]"); + return builder.toString(); + } } diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java index 62b66611..69e13b43 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java @@ -20,6 +20,12 @@ package org.onap.policy.drools.protocol.configuration; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + import java.util.HashMap; import java.util.Map; @@ -27,41 +33,34 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - /** - * Drools Related Information + * Drools Related Information. * */ @JsonInclude(JsonInclude.Include.NON_NULL) public class ControllerConfiguration { - public static final String CONFIG_CONTROLLER_OPERATION_CREATE = "create"; - public static final String CONFIG_CONTROLLER_OPERATION_UPDATE = "update"; - public static final String CONFIG_CONTROLLER_OPERATION_LOCK = "lock"; - public static final String CONFIG_CONTROLLER_OPERATION_UNLOCK = "unlock"; - + public static final String CONFIG_CONTROLLER_OPERATION_CREATE = "create"; + public static final String CONFIG_CONTROLLER_OPERATION_UPDATE = "update"; + public static final String CONFIG_CONTROLLER_OPERATION_LOCK = "lock"; + public static final String CONFIG_CONTROLLER_OPERATION_UNLOCK = "unlock"; + /** - * - * (Required) + * (Required). * */ @JsonProperty("name") private String name; /** * Set of operations that can be applied to a controller: create, lock - * (Required) + * (Required). * */ @JsonProperty("operation") private String operation; /** - * Maven Related Information + * Maven Related Information. * */ @JsonProperty("drools") @@ -71,18 +70,19 @@ public class ControllerConfiguration { protected static final Object NOT_FOUND_VALUE = new Object(); /** - * No args constructor for use in serialization + * No args constructor for use in serialization. * */ public ControllerConfiguration() { - // Empty + // Empty } /** + * Constructor. * - * @param name - * @param drools - * @param operation + * @param name name + * @param operation operation + * @param drools drools */ public ControllerConfiguration(String name, String operation, DroolsConfiguration drools) { this.name = name; @@ -91,8 +91,7 @@ public class ControllerConfiguration { } /** - * - * (Required) + * (Required). * * @return * The name @@ -103,8 +102,7 @@ public class ControllerConfiguration { } /** - * - * (Required) + * (Required). * * @param name * The name @@ -121,7 +119,7 @@ public class ControllerConfiguration { /** * Set of operations that can be applied to a controller: create, lock - * (Required) + * (Required). * * @return * The operation @@ -133,7 +131,7 @@ public class ControllerConfiguration { /** * Set of operations that can be applied to a controller: create, lock - * (Required) + * (Required). * * @param operation * The operation @@ -149,7 +147,7 @@ public class ControllerConfiguration { } /** - * Maven Related Information + * Maven Related Information. * * @return * The drools @@ -160,7 +158,7 @@ public class ControllerConfiguration { } /** - * Maven Related Information + * Maven Related Information. * * @param drools * The drools @@ -224,24 +222,43 @@ public class ControllerConfiguration { } } + /** + * Get. + * + * @param name name + * @return the object + */ @SuppressWarnings({ "unchecked" - }) - public<T >T get(String name) { + }) + public <T> T get(String name) { Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE); - if (ControllerConfiguration.NOT_FOUND_VALUE!= value) { + if (ControllerConfiguration.NOT_FOUND_VALUE != value) { return ((T) value); } else { return ((T) getAdditionalProperties().get(name)); } } + /** + * Set the property. + * + * @param name property name + * @param value property value + */ public void set(String name, Object value) { if (!declaredProperty(name, value)) { getAdditionalProperties().put(name, (Object) value); } } + /** + * With - sets the property and additionally returns the object. + * + * @param name property name + * @param value property value + * @return this + */ public ControllerConfiguration with(String name, Object value) { if (!declaredProperty(name, value)) { getAdditionalProperties().put(name, (Object) value); @@ -251,7 +268,8 @@ public class ControllerConfiguration { @Override public int hashCode() { - return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties).toHashCode(); + return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties) + .toHashCode(); } @Override @@ -263,30 +281,50 @@ public class ControllerConfiguration { return false; } ControllerConfiguration rhs = ((ControllerConfiguration) other); - return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools).append(additionalProperties, rhs.additionalProperties).isEquals(); + return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools) + .append(additionalProperties, rhs.additionalProperties).isEquals(); } + /** + * Call set name. + * + * @param value value + */ public void callSetName(Object value) { if (value instanceof String) { setName((String) value); } else { - throw new IllegalArgumentException("property \"name\" is of type \"java.lang.String\", but got "+ value.getClass().toString()); + throw new IllegalArgumentException("property \"name\" is of type \"java.lang.String\", but got " + + value.getClass().toString()); } } + /** + * Call set operation. + * + * @param value value + */ public void callSetOperation(Object value) { if (value instanceof String) { setOperation((String) value); } else { - throw new IllegalArgumentException("property \"operation\" is of type \"java.lang.String\", but got "+ value.getClass().toString()); + throw new IllegalArgumentException("property \"operation\" is of type \"java.lang.String\", but got " + + value.getClass().toString()); } } + /** + * Call set drools. + * + * @param value value + */ public void callSetDrools(Object value) { if (value instanceof DroolsConfiguration) { setDrools((DroolsConfiguration) value); } else { - throw new IllegalArgumentException("property \"drools\" is of type \"org.onap.policy.drools.protocol.configuration.Drools\", but got "+ value.getClass().toString()); + throw new IllegalArgumentException("property \"drools\" is of type" + + "\"org.onap.policy.drools.protocol.configuration.Drools\", but got " + + value.getClass().toString()); } } diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java index cac4f565..e1f7f63a 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java @@ -20,22 +20,21 @@ package org.onap.policy.drools.protocol.configuration; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ToStringBuilder; - import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; /** - * Maven Related Information + * Maven Related Information. * */ @JsonInclude(JsonInclude.Include.NON_NULL) @@ -43,21 +42,23 @@ public class DroolsConfiguration { /** * Maven Artifact ID - * (Required) + * (Required). * */ @JsonProperty("artifactId") private String artifactId; + /** * Maven Group ID - * (Required) + * (Required). * */ @JsonProperty("groupId") private String groupId; + /** * Maven Version - * (Required) + * (Required). * */ @JsonProperty("version") @@ -67,18 +68,19 @@ public class DroolsConfiguration { protected static final Object NOT_FOUND_VALUE = new Object(); /** - * No args constructor for use in serialization + * No args constructor for use in serialization. * */ public DroolsConfiguration() { - // Empty + // Empty } /** + * Constructor. * - * @param groupId - * @param artifactId - * @param version + * @param groupId group id + * @param artifactId artifact id + * @param version version */ public DroolsConfiguration(String artifactId, String groupId, String version) { this.artifactId = artifactId; @@ -88,7 +90,7 @@ public class DroolsConfiguration { /** * Maven Artifact ID - * (Required) + * (Required). * * @return * The artifactId @@ -100,7 +102,7 @@ public class DroolsConfiguration { /** * Maven Artifact ID - * (Required) + * (Required). * * @param artifactId * The artifactId @@ -117,7 +119,7 @@ public class DroolsConfiguration { /** * Maven Group ID - * (Required) + * (Required). * * @return * The groupId @@ -129,7 +131,7 @@ public class DroolsConfiguration { /** * Maven Group ID - * (Required) + * (Required). * * @param groupId * The groupId @@ -146,7 +148,7 @@ public class DroolsConfiguration { /** * Maven Version - * (Required) + * (Required). * * @return * The version @@ -158,7 +160,7 @@ public class DroolsConfiguration { /** * Maven Version - * (Required) + * (Required). * * @param version * The version @@ -222,24 +224,43 @@ public class DroolsConfiguration { } } + /** + * Get declared property. + * + * @param name property name + * @return the property object + */ @SuppressWarnings({ "unchecked" - }) - public<T >T get(String name) { + }) + public <T> T get(String name) { Object value = declaredPropertyOrNotFound(name, DroolsConfiguration.NOT_FOUND_VALUE); - if (DroolsConfiguration.NOT_FOUND_VALUE!= value) { + if (DroolsConfiguration.NOT_FOUND_VALUE != value) { return (T) value; } else { return (T) getAdditionalProperties().get(name); } } + /** + * Set property value. + * + * @param name property name + * @param value property value + */ public void set(String name, Object value) { if (!declaredProperty(name, value)) { getAdditionalProperties().put(name, value); } } + /** + * Set property value and return object. + * + * @param name property name + * @param value property value + * @return this + */ public DroolsConfiguration with(String name, Object value) { if (!declaredProperty(name, value)) { getAdditionalProperties().put(name, value); @@ -249,7 +270,8 @@ public class DroolsConfiguration { @Override public int hashCode() { - return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties).toHashCode(); + return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties) + .toHashCode(); } @Override @@ -261,30 +283,50 @@ public class DroolsConfiguration { return false; } DroolsConfiguration rhs = ((DroolsConfiguration) other); - return new EqualsBuilder().append(artifactId, rhs.artifactId).append(groupId, rhs.groupId).append(version, rhs.version).append(additionalProperties, rhs.additionalProperties).isEquals(); + return new EqualsBuilder().append(artifactId, rhs.artifactId) + .append(groupId, rhs.groupId).append(version, rhs.version) + .append(additionalProperties, rhs.additionalProperties).isEquals(); } + /** + * Call set artifact id. + * + * @param value id + */ public void callSetArtifactId(Object value) { if (value instanceof String) { setArtifactId((String) value); } else { - throw new IllegalArgumentException("property \"artifactId\" is of type \"java.lang.String\", but got "+ value.getClass().toString()); + throw new IllegalArgumentException("property \"artifactId\" is of type \"java.lang.String\", but got " + + value.getClass().toString()); } } + /** + * Call set group id. + * + * @param value id + */ public void callSetGroupId(Object value) { if (value instanceof String) { setGroupId((String) value); } else { - throw new IllegalArgumentException("property \"groupId\" is of type \"java.lang.String\", but got "+ value.getClass().toString()); + throw new IllegalArgumentException("property \"groupId\" is of type \"java.lang.String\", but got " + + value.getClass().toString()); } } + /** + * Call set version. + * + * @param value version + */ public void callSetVersion(Object value) { if (value instanceof String) { setVersion((String) value); } else { - throw new IllegalArgumentException("property \"version\" is of type \"java.lang.String\", but got "+ value.getClass().toString()); + throw new IllegalArgumentException("property \"version\" is of type \"java.lang.String\", but got " + + value.getClass().toString()); } } } diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java index 29888bbb..58cd67fd 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java @@ -20,84 +20,65 @@ package org.onap.policy.drools.protocol.configuration; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; /** - * ENGINE-CONFIGURATION - * <p> - * - * + * ENGINE-CONFIGURATION. */ @JsonInclude(JsonInclude.Include.NON_NULL) public class PdpdConfiguration { - - /** - * Controller Entity ID - */ - public static final String CONFIG_ENTITY_CONTROLLER = "controller"; - /** - * Unique Transaction ID. This is an UUID. - * (Required) - * - */ + /** Controller Entity ID. */ + public static final String CONFIG_ENTITY_CONTROLLER = "controller"; + + /** Unique Transaction ID. This is an UUID. (Required) */ @JsonProperty("requestID") private String requestID; - /** - * Set of entities on which configuration can be performed: controller - * (Required) - * - */ + /* Set of entities on which configuration can be performed: controller (Required) */ @JsonProperty("entity") private String entity; - /** - * Controller Information, only applicable when the entity is set to controller - * - */ + /* Controller Information, only applicable when the entity is set to controller */ @JsonProperty("controllers") private List<ControllerConfiguration> controllers = new ArrayList<>(); - @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<>(); + + @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<>(); protected static final Object NOT_FOUND_VALUE = new Object(); - /** - * No args constructor for use in serialization - * - */ + /** No args constructor for use in serialization. */ public PdpdConfiguration() { - // Empty + // Empty } /** + * Constructor. * - * @param controller - * @param requestID - * @param entity + * @param requestID request id + * @param entity entity + * @param controllers controllers */ - public PdpdConfiguration(String requestID, String entity, List<ControllerConfiguration> controllers) { + public PdpdConfiguration( + String requestID, String entity, List<ControllerConfiguration> controllers) { this.requestID = requestID; this.entity = entity; this.controllers = controllers; } /** - * Unique Transaction ID. This is an UUID. - * (Required) - * - * @return - * The requestID + * Unique Transaction ID. This is an UUID. (Required) + * + * @return The requestID */ @JsonProperty("requestID") public String getRequestID() { @@ -105,11 +86,9 @@ public class PdpdConfiguration { } /** - * Unique Transaction ID. This is an UUID. - * (Required) - * - * @param requestID - * The requestID + * Unique Transaction ID. This is an UUID. (Required) + * + * @param requestID The requestID */ @JsonProperty("requestID") public void setRequestID(String requestID) { @@ -122,11 +101,9 @@ public class PdpdConfiguration { } /** - * Set of entities on which configuration can be performed: controller - * (Required) - * - * @return - * The entity + * Set of entities on which configuration can be performed: controller (Required). + * + * @return The entity */ @JsonProperty("entity") public String getEntity() { @@ -134,11 +111,9 @@ public class PdpdConfiguration { } /** - * Set of entities on which configuration can be performed: controller - * (Required) - * - * @param entity - * The entity + * Set of entities on which configuration can be performed: controller (Required). + * + * @param entity The entity */ @JsonProperty("entity") public void setEntity(String entity) { @@ -151,10 +126,9 @@ public class PdpdConfiguration { } /** - * Controller Information, only applicable when the entity is set to controller - * - * @return - * The controller + * Controller Information, only applicable when the entity is set to controller. + * + * @return The controller */ @JsonProperty("controller") public List<ControllerConfiguration> getControllers() { @@ -162,10 +136,9 @@ public class PdpdConfiguration { } /** - * Controller Information, only applicable when the entity is set to controller - * - * @param controller - * The controller + * Controller Information, only applicable when the entity is set to controller. + * + * @param controllers controllers */ @JsonProperty("controller") public void setControllers(List<ControllerConfiguration> controllers) { @@ -226,24 +199,37 @@ public class PdpdConfiguration { } } - @SuppressWarnings({ - "unchecked" - }) - public<T >T get(String name) { + /** + * Get. + * + * @param name name + * @return object + */ + @SuppressWarnings({"unchecked"}) + public <T> T get(String name) { Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE); - if (PdpdConfiguration.NOT_FOUND_VALUE!= value) { + if (PdpdConfiguration.NOT_FOUND_VALUE != value) { return (T) value; } else { return (T) getAdditionalProperties().get(name); } } + /** + * Set property. + * + * @param name name + * @param value value + */ public void set(String name, Object value) { if (!declaredProperty(name, value)) { getAdditionalProperties().put(name, value); } } + /** + * With - sets and returns the object. + */ public PdpdConfiguration with(String name, Object value) { if (!declaredProperty(name, value)) { getAdditionalProperties().put(name, value); @@ -253,7 +239,12 @@ public class PdpdConfiguration { @Override public int hashCode() { - return new HashCodeBuilder().append(requestID).append(entity).append(controllers).append(additionalProperties).toHashCode(); + return new HashCodeBuilder() + .append(requestID) + .append(entity) + .append(controllers) + .append(additionalProperties) + .toHashCode(); } @Override @@ -265,31 +256,59 @@ public class PdpdConfiguration { return false; } PdpdConfiguration rhs = (PdpdConfiguration) other; - return new EqualsBuilder().append(requestID, rhs.requestID).append(entity, rhs.entity).append(controllers, rhs.controllers).append(additionalProperties, rhs.additionalProperties).isEquals(); + return new EqualsBuilder() + .append(requestID, rhs.requestID) + .append(entity, rhs.entity) + .append(controllers, rhs.controllers) + .append(additionalProperties, rhs.additionalProperties) + .isEquals(); } - + + /** + * Call set request id. + * + * @param value value + */ public void callSetRequestId(Object value) { if (value instanceof String) { setRequestID((String) value); } else { - throw new IllegalArgumentException("property \"requestID\" is of type \"java.lang.String\", but got "+ value.getClass().toString()); - } + throw new IllegalArgumentException( + "property \"requestID\" is of type \"java.lang.String\", but got " + + value.getClass().toString()); + } } - + + /** + * Call set entity. + * + * @param value value + */ public void callSetEntity(Object value) { if (value instanceof String) { setEntity((String) value); } else { - throw new IllegalArgumentException("property \"entity\" is of type \"java.lang.String\", but got "+ value.getClass().toString()); - } + throw new IllegalArgumentException( + "property \"entity\" is of type \"java.lang.String\", but got " + + value.getClass().toString()); + } } + /** + * Call set controllers. + * + * @param value value + */ @SuppressWarnings("unchecked") - public void callSetControllers(Object value) { + public void callSetControllers(Object value) { if (value instanceof List) { - setControllers((List<ControllerConfiguration> ) value); + setControllers((List<ControllerConfiguration>) value); } else { - throw new IllegalArgumentException("property \"controllers\" is of type \"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", but got "+ value.getClass().toString()); - } + throw new IllegalArgumentException( + "property \"controllers\" is of type " + + "\"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", " + + "but got " + + value.getClass().toString()); + } } } |