From 1221c6bcdba722996e74c991881db6e52e158d23 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 6 Nov 2019 06:57:50 -0500 Subject: Address drools-pdp sonar issues Addressed more sonar issues in drools-pdp: - unwrap multiple instances of the same annotation (NamedQuery) - use lambda instead of anonymous class - duplicate code; addressed by using annotation instead of toString. This still leaves other duplicate code. Issue-ID: POLICY-2203 Change-Id: I8c6ff6562820af638044f134eb8a6725a5f05e8e Signed-off-by: Jim Hahn --- .../configuration/ControllerConfiguration.java | 62 ++++++++++------------ .../configuration/DroolsConfiguration.java | 60 ++++++++++----------- .../protocol/configuration/PdpdConfiguration.java | 8 +-- 3 files changed, 57 insertions(+), 73 deletions(-) (limited to 'policy-management') 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 23a8855f..d6df0e42 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 @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,13 +25,11 @@ 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 lombok.ToString; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ToStringBuilder; import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter; import org.onap.policy.common.gson.annotation.GsonJsonAnySetter; import org.onap.policy.common.gson.annotation.GsonJsonIgnore; @@ -40,9 +38,10 @@ import org.onap.policy.common.gson.annotation.GsonJsonProperty; /** * Drools Related Information. - * + * */ @JsonInclude(JsonInclude.Include.NON_NULL) +@ToString public class ControllerConfiguration { public static final String CONFIG_CONTROLLER_OPERATION_CREATE = "create"; @@ -52,7 +51,7 @@ public class ControllerConfiguration { /** * (Required). - * + * */ @JsonProperty("name") @GsonJsonProperty("name") @@ -60,28 +59,28 @@ public class ControllerConfiguration { /** * Set of operations that can be applied to a controller: create, lock * (Required). - * + * */ @JsonProperty("operation") @GsonJsonProperty("operation") private String operation; /** * Maven Related Information. - * + * */ @JsonProperty("drools") @GsonJsonProperty("drools") private DroolsConfiguration drools; - + @JsonIgnore @GsonJsonIgnore private Map additionalProperties = new HashMap<>(); - + protected static final Object NOT_FOUND_VALUE = new Object(); /** * No args constructor for use in serialization. - * + * */ public ControllerConfiguration() { // Empty @@ -89,7 +88,7 @@ public class ControllerConfiguration { /** * Constructor. - * + * * @param name name * @param operation operation * @param drools drools @@ -102,7 +101,7 @@ public class ControllerConfiguration { /** * (Required). - * + * * @return * The name */ @@ -114,7 +113,7 @@ public class ControllerConfiguration { /** * (Required). - * + * * @param name * The name */ @@ -132,7 +131,7 @@ public class ControllerConfiguration { /** * Set of operations that can be applied to a controller: create, lock * (Required). - * + * * @return * The operation */ @@ -145,7 +144,7 @@ public class ControllerConfiguration { /** * Set of operations that can be applied to a controller: create, lock * (Required). - * + * * @param operation * The operation */ @@ -162,7 +161,7 @@ public class ControllerConfiguration { /** * Maven Related Information. - * + * * @return * The drools */ @@ -174,7 +173,7 @@ public class ControllerConfiguration { /** * Maven Related Information. - * + * * @param drools * The drools */ @@ -189,11 +188,6 @@ public class ControllerConfiguration { return this; } - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this); - } - @JsonAnyGetter @GsonJsonAnyGetter public Map getAdditionalProperties() { @@ -242,7 +236,7 @@ public class ControllerConfiguration { /** * Get. - * + * * @param name name * @return the object */ @@ -260,7 +254,7 @@ public class ControllerConfiguration { /** * Set the property. - * + * * @param name property name * @param value property value */ @@ -272,7 +266,7 @@ public class ControllerConfiguration { /** * With - sets the property and additionally returns the object. - * + * * @param name property name * @param value property value * @return this @@ -302,10 +296,10 @@ public class ControllerConfiguration { 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) { @@ -316,10 +310,10 @@ public class ControllerConfiguration { + value.getClass().toString()); } } - + /** * Call set operation. - * + * * @param value value */ public void callSetOperation(Object value) { @@ -330,10 +324,10 @@ public class ControllerConfiguration { + value.getClass().toString()); } } - + /** * Call set drools. - * + * * @param value value */ public void callSetDrools(Object value) { 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 9c0e125b..eec4df56 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,13 +25,11 @@ 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 lombok.ToString; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ToStringBuilder; import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter; import org.onap.policy.common.gson.annotation.GsonJsonAnySetter; import org.onap.policy.common.gson.annotation.GsonJsonIgnore; @@ -39,47 +37,48 @@ import org.onap.policy.common.gson.annotation.GsonJsonProperty; /** * Maven Related Information. - * + * */ @JsonInclude(JsonInclude.Include.NON_NULL) +@ToString public class DroolsConfiguration { /** * Maven Artifact ID * (Required). - * + * */ @JsonProperty("artifactId") @GsonJsonProperty("artifactId") private String artifactId; - + /** * Maven Group ID * (Required). - * + * */ @JsonProperty("groupId") @GsonJsonProperty("groupId") private String groupId; - + /** * Maven Version * (Required). - * + * */ @JsonProperty("version") @GsonJsonProperty("version") private String version; - + @JsonIgnore @GsonJsonIgnore private Map additionalProperties = new HashMap<>(); - + protected static final Object NOT_FOUND_VALUE = new Object(); /** * No args constructor for use in serialization. - * + * */ public DroolsConfiguration() { // Empty @@ -87,7 +86,7 @@ public class DroolsConfiguration { /** * Constructor. - * + * * @param groupId group id * @param artifactId artifact id * @param version version @@ -101,7 +100,7 @@ public class DroolsConfiguration { /** * Maven Artifact ID * (Required). - * + * * @return * The artifactId */ @@ -114,7 +113,7 @@ public class DroolsConfiguration { /** * Maven Artifact ID * (Required). - * + * * @param artifactId * The artifactId */ @@ -132,7 +131,7 @@ public class DroolsConfiguration { /** * Maven Group ID * (Required). - * + * * @return * The groupId */ @@ -145,7 +144,7 @@ public class DroolsConfiguration { /** * Maven Group ID * (Required). - * + * * @param groupId * The groupId */ @@ -163,7 +162,7 @@ public class DroolsConfiguration { /** * Maven Version * (Required). - * + * * @return * The version */ @@ -176,7 +175,7 @@ public class DroolsConfiguration { /** * Maven Version * (Required). - * + * * @param version * The version */ @@ -191,11 +190,6 @@ public class DroolsConfiguration { return this; } - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this); - } - @JsonAnyGetter @GsonJsonAnyGetter public Map getAdditionalProperties() { @@ -244,7 +238,7 @@ public class DroolsConfiguration { /** * Get declared property. - * + * * @param name property name * @return the property object */ @@ -262,7 +256,7 @@ public class DroolsConfiguration { /** * Set property value. - * + * * @param name property name * @param value property value */ @@ -274,7 +268,7 @@ public class DroolsConfiguration { /** * Set property value and return object. - * + * * @param name property name * @param value property value * @return this @@ -305,10 +299,10 @@ public class DroolsConfiguration { .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) { @@ -322,7 +316,7 @@ public class DroolsConfiguration { /** * Call set group id. - * + * * @param value id */ public void callSetGroupId(Object value) { @@ -336,7 +330,7 @@ public class DroolsConfiguration { /** * Call set version. - * + * * @param value version */ public void callSetVersion(Object value) { 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 572bc14f..3ce2ad92 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 @@ -29,9 +29,9 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import lombok.ToString; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ToStringBuilder; import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter; import org.onap.policy.common.gson.annotation.GsonJsonAnySetter; import org.onap.policy.common.gson.annotation.GsonJsonIgnore; @@ -42,6 +42,7 @@ import org.onap.policy.common.gson.annotation.GsonJsonProperty; * ENGINE-CONFIGURATION. */ @JsonInclude(JsonInclude.Include.NON_NULL) +@ToString public class PdpdConfiguration { /** Controller Entity ID. */ @@ -163,11 +164,6 @@ public class PdpdConfiguration { return this; } - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this); - } - @JsonAnyGetter @GsonJsonAnyGetter public Map getAdditionalProperties() { -- cgit 1.2.3-korg