From f9c9d54ecd04e1cd65c6423bacc0e956e11b721f Mon Sep 17 00:00:00 2001 From: "Magnusen, Drew (dm741q)" Date: Thu, 14 Dec 2017 15:29:07 -0600 Subject: Reduce tech debt in policy-management Changes to reduce tech debt in the policy-management module. Issue-ID: POLICY-463 Change-Id: I41f6b66d25a805706e5c9ed2cef2eda256153a37 Signed-off-by: Magnusen, Drew (dm741q) --- .../drools/protocol/coders/JsonProtocolFilter.java | 2 +- .../configuration/ControllerConfiguration.java | 46 ++++++++++++++-------- .../configuration/DroolsConfiguration.java | 41 ++++++++++++------- .../protocol/configuration/PdpdConfiguration.java | 41 ++++++++++++------- 4 files changed, 82 insertions(+), 48 deletions(-) (limited to 'policy-management/src/main/java/org/onap/policy/drools/protocol') 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 0a52d254..12d0ffe5 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 @@ -197,7 +197,7 @@ public class JsonProtocolFilter { for (FilterRule filter: rules) { if (filter.regex == null || filter.regex.isEmpty() || - filter.regex.equals(".*")) { + ".*".equals(filter.regex)) { // Only check for presence if (!event.has(filter.name)) { 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 b0b8b504..845c4944 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 @@ -198,25 +198,13 @@ public class ControllerConfiguration { protected boolean declaredProperty(String name, Object value) { switch (name) { case "name": - if (value instanceof String) { - setName(((String) value)); - } else { - throw new IllegalArgumentException(("property \"name\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); - } + callSetName(value); return true; case "operation": - if (value instanceof String) { - setOperation(((String) value)); - } else { - throw new IllegalArgumentException(("property \"operation\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); - } + callSetOperation(value); return true; case "drools": - 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())); - } + callSetDrools(value); return true; default: return false; @@ -250,13 +238,13 @@ public class ControllerConfiguration { public void set(String name, Object value) { if (!declaredProperty(name, value)) { - getAdditionalProperties().put(name, ((Object) value)); + getAdditionalProperties().put(name, (Object) value); } } public ControllerConfiguration with(String name, Object value) { if (!declaredProperty(name, value)) { - getAdditionalProperties().put(name, ((Object) value)); + getAdditionalProperties().put(name, (Object) value); } return this; } @@ -277,5 +265,29 @@ public class ControllerConfiguration { ControllerConfiguration rhs = ((ControllerConfiguration) other); return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools).append(additionalProperties, rhs.additionalProperties).isEquals(); } + + 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()); + } + } + + 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()); + } + } + + 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()); + } + } } 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 4c672e7b..e822d88e 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 @@ -196,25 +196,13 @@ public class DroolsConfiguration { protected boolean declaredProperty(String name, Object value) { switch (name) { case "artifactId": - if (value instanceof String) { - setArtifactId((String) value); - } else { - throw new IllegalArgumentException(("property \"artifactId\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); - } + callSetArtifactId(value); return true; case "groupId": - if (value instanceof String) { - setGroupId((String) value); - } else { - throw new IllegalArgumentException(("property \"groupId\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); - } + callSetGroupId(value); return true; case "version": - if (value instanceof String) { - setVersion((String) value); - } else { - throw new IllegalArgumentException(("property \"version\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); - } + callSetVersion(value); return true; default: return false; @@ -275,5 +263,28 @@ public class DroolsConfiguration { DroolsConfiguration rhs = ((DroolsConfiguration) other); return new EqualsBuilder().append(artifactId, rhs.artifactId).append(groupId, rhs.groupId).append(version, rhs.version).append(additionalProperties, rhs.additionalProperties).isEquals(); } + + 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()); + } + } + + 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()); + } + } + 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()); + } + } } 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 8d6f9bfd..c7a227b1 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 @@ -201,25 +201,13 @@ public class PdpdConfiguration { protected boolean declaredProperty(String name, Object value) { switch (name) { case "requestID": - if (value instanceof String) { - setRequestID((String) value); - } else { - throw new IllegalArgumentException(("property \"requestID\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); - } + callSetRequestId(value); return true; case "entity": - if (value instanceof String) { - setEntity((String) value); - } else { - throw new IllegalArgumentException(("property \"entity\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); - } + callSetEntity(value); return true; case "controllers": - if (value instanceof List) { - setControllers((List ) value); - } else { - throw new IllegalArgumentException(("property \"controllers\" is of type \"java.util.List\", but got "+ value.getClass().toString())); - } + callSetControllers(value); return true; default: return false; @@ -280,5 +268,28 @@ public class PdpdConfiguration { PdpdConfiguration rhs = (PdpdConfiguration) other; return new EqualsBuilder().append(requestID, rhs.requestID).append(entity, rhs.entity).append(controllers, rhs.controllers).append(additionalProperties, rhs.additionalProperties).isEquals(); } + + 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()); + } + } + + 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()); + } + } + public void callSetControllers(Object value) { + if (value instanceof List) { + setControllers((List ) value); + } else { + throw new IllegalArgumentException("property \"controllers\" is of type \"java.util.List\", but got "+ value.getClass().toString()); + } + } } -- cgit 1.2.3-korg