Address drools-pdp sonar issues 48/98048/2
authorJim Hahn <jrh3@att.com>
Wed, 6 Nov 2019 11:57:50 +0000 (06:57 -0500)
committerJim Hahn <jrh3@att.com>
Wed, 6 Nov 2019 14:18:42 +0000 (09:18 -0500)
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 <jrh3@att.com>
feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpEntity.java
feature-drools-init/src/main/java/org/onap/policy/drools/droolsinit/DroolsInitFeature.java
policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java
policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java
policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java

index 4175068..078b047 100644 (file)
@@ -22,26 +22,21 @@ package org.onap.policy.drools.activestandby;
 
 import java.io.Serializable;
 import java.util.Date;
-
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.Id;
-import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import lombok.Getter;
 import lombok.Setter;
 import org.onap.policy.common.im.MonitorTime;
-import org.onap.policy.drools.activestandby.DroolsPdpObject;
 
 @Entity
 //@Table(name="DroolsPdpEntity")
 
-@NamedQueries({
-    @NamedQuery(name = "DroolsPdpEntity.findAll", query = "SELECT e FROM DroolsPdpEntity e "),
-    @NamedQuery(name = "DroolsPdpEntity.deleteAll", query = "DELETE FROM DroolsPdpEntity WHERE 1=1")
-    })
+@NamedQuery(name = "DroolsPdpEntity.findAll", query = "SELECT e FROM DroolsPdpEntity e ")
+@NamedQuery(name = "DroolsPdpEntity.deleteAll", query = "DELETE FROM DroolsPdpEntity WHERE 1=1")
 @Getter
 @Setter
 public class DroolsPdpEntity extends DroolsPdpObject implements Serializable {
index b3b8485..f97ed75 100644 (file)
@@ -72,16 +72,12 @@ public class DroolsInitFeature implements PolicySessionFeatureApi {
             final FactHandle factHandle = policySession.getKieSession().insert(this);
 
             // after 10 minutes, remove the object from Drools memory (if needed)
-            PolicyEngineConstants.getManager().getExecutorService().schedule(
-                new Runnable() {
-                    @Override
-                    public void run() {
-                        if (policySession.getKieSession().getObject(factHandle) != null) {
-                            // object has not been removed by application -- remove it here
-                            policySession.getKieSession().delete(factHandle);
-                        }
-                    }
-                }, DELAY, TimeUnit.MILLISECONDS);
+            PolicyEngineConstants.getManager().getExecutorService().schedule(() -> {
+                if (policySession.getKieSession().getObject(factHandle) != null) {
+                    // object has not been removed by application -- remove it here
+                    policySession.getKieSession().delete(factHandle);
+                }
+            }, DELAY, TimeUnit.MILLISECONDS);
         }
     }
 }
index 23a8855..d6df0e4 100644 (file)
@@ -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<String, Object> 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<String, Object> 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) {
index 9c0e125..eec4df5 100644 (file)
@@ -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<String, Object> 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<String, Object> 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) {
index 572bc14..3ce2ad9 100644 (file)
@@ -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<String, Object> getAdditionalProperties() {