Use lombok in common params 97/121997/1
authorJim Hahn <jrh3@att.com>
Wed, 16 Jun 2021 21:45:03 +0000 (17:45 -0400)
committerJim Hahn <jrh3@att.com>
Wed, 16 Jun 2021 22:06:08 +0000 (18:06 -0400)
Also condensed some Map calls.

Issue-ID: POLICY-3394
Change-Id: I850fcad5a72d92271da76b0731195e8b93dd4089
Signed-off-by: Jim Hahn <jrh3@att.com>
14 files changed:
common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterConstants.java
common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterException.java
common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterRuntimeException.java
common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java
common-parameters/src/main/java/org/onap/policy/common/parameters/ValidationResultImpl.java
common-parameters/src/main/java/org/onap/policy/common/parameters/ValueValidator.java
gson/src/main/java/org/onap/policy/common/gson/DoubleConverter.java
gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java
gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java
integrity-audit/pom.xml
integrity-audit/src/main/java/org/onap/policy/common/ia/AuditorTime.java
integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java
integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java
integrity-audit/src/main/java/org/onap/policy/common/ia/jpa/IntegrityAuditEntity.java

index 240b1f4..300d49c 100644 (file)
@@ -1,45 +1,43 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2021 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.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * 
+ *
  * SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
 
 package org.onap.policy.common.parameters;
 
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
 /**
  * This static class holds the values of constants for parameter handling.
  */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class ParameterConstants {
     // Indentation is 0 on the left and 2 for each level of hierarchy
     public static final String DEFAULT_INITIAL_RESULT_INDENTATION = "";
     public static final String DEFAULT_RESULT_INDENTATION = "  ";
-    
+
     // By default we do not show validation results for parameters that are validated as clean
     public static final boolean DO_NOT_SHOW_CLEAN_RESULTS = false;
-    
+
     // Messages for clean validations
     public static final String PARAMETER_GROUP_HAS_STATUS_MESSAGE = "parameter group has status ";
     public static final String PARAMETER_GROUP_MAP_HAS_STATUS_MESSAGE = "parameter group map has status ";
     public static final String PARAMETER_HAS_STATUS_MESSAGE       = "parameter has status ";
-    
-    /**
-     * Private constructor to prevent subclassing.
-     */
-    private ParameterConstants() {
-        // Private constructor to prevent subclassing
-    }
-}
\ No newline at end of file
+}
index 84faa9c..aa3105e 100644 (file)
@@ -21,6 +21,8 @@
 
 package org.onap.policy.common.parameters;
 
+import lombok.Getter;
+
 /**
  * Exception thrown oon parameter reading, validation, and check errors.
  *
@@ -30,6 +32,7 @@ public class ParameterException extends Exception {
     private static final long serialVersionUID = -8507246953751956974L;
 
     // The object on which the exception was thrown
+    @Getter
     private final transient Object object;
 
     /**
@@ -100,13 +103,4 @@ public class ParameterException extends Exception {
 
         return builder.toString();
     }
-
-    /**
-     * Get the object on which the exception was thrown.
-     *
-     * @return The object on which the exception was thrown
-     */
-    public Object getObject() {
-        return object;
-    }
 }
index 071593a..4eb7944 100644 (file)
@@ -1,25 +1,28 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2021 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.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * 
+ *
  * SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
 
 package org.onap.policy.common.parameters;
 
+import lombok.Getter;
+
 /**
  * A run time exception thrown on parameter validations.
  *
@@ -29,6 +32,7 @@ public class ParameterRuntimeException extends RuntimeException {
     private static final long serialVersionUID = -8507246953751956974L;
 
     // The object on which the exception was thrown
+    @Getter
     private final transient Object object;
 
     /**
@@ -81,13 +85,4 @@ public class ParameterRuntimeException extends RuntimeException {
     public String getCascadedMessage() {
         return ParameterException.buildCascadedMessage(this);
     }
-
-    /**
-     * Get the object on which the exception was thrown.
-     *
-     * @return The object
-     */
-    public Object getObject() {
-        return object;
-    }
 }
index 7bf0ac5..a368d25 100644 (file)
@@ -25,6 +25,8 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
 
 /**
  * The parameter service makes ONAP PF parameter groups available to all classes in a JVM.
@@ -37,25 +39,18 @@ import java.util.concurrent.ConcurrentHashMap;
  *
  * @author Liam Fallon (liam.fallon@ericsson.com)
  */
-public abstract class ParameterService {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ParameterService {
     // The map holding the parameters
     private static Map<String, ParameterGroup> parameterGroupMap = new ConcurrentHashMap<>();
 
-    /**
-     * This class is an abstract static class that cannot be extended.
-     */
-    private ParameterService() {
-    }
-
     /**
      * Register a parameter group with the parameter service.
      *
      * @param parameterGroup the parameter group
      */
     public static void register(final ParameterGroup parameterGroup) {
-        if (!parameterGroupMap.containsKey(parameterGroup.getName())) {
-            parameterGroupMap.put(parameterGroup.getName(), parameterGroup);
-        } else {
+        if (parameterGroupMap.putIfAbsent(parameterGroup.getName(), parameterGroup) != null) {
             throw new ParameterRuntimeException(
                             "\"" + parameterGroup.getName() + "\" already registered in parameter service");
         }
@@ -81,9 +76,7 @@ public abstract class ParameterService {
      * @param parameterGroupName the name of the parameter group
      */
     public static void deregister(final String parameterGroupName) {
-        if (parameterGroupMap.containsKey(parameterGroupName)) {
-            parameterGroupMap.remove(parameterGroupName);
-        } else {
+        if (parameterGroupMap.remove(parameterGroupName) == null) {
             throw new ParameterRuntimeException("\"" + parameterGroupName + "\" not registered in parameter service");
         }
     }
@@ -121,7 +114,7 @@ public abstract class ParameterService {
      * @return true if the parameter is defined
      */
     public static boolean contains(final String parameterGroupName) {
-        return parameterGroupMap.containsKey(parameterGroupName) && parameterGroupMap.get(parameterGroupName) != null;
+        return parameterGroupMap.get(parameterGroupName) != null;
     }
 
     /**
index 0fda51a..4589881 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  *  Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
 
 package org.onap.policy.common.parameters;
 
+import lombok.AllArgsConstructor;
 import lombok.Getter;
 
 /**
  * Basic implementation of a ValidationResult.
  */
 @Getter
+@AllArgsConstructor
 public abstract class ValidationResultImpl implements ValidationResult {
     public static final String ITEM_HAS_STATUS_MESSAGE = "item has status ";
 
@@ -62,21 +64,6 @@ public abstract class ValidationResultImpl implements ValidationResult {
         this.object = object;
     }
 
-    /**
-     * Constructs the object.
-     *
-     * @param name name of the object of this result
-     * @param object object being validated
-     * @param status the validation status
-     * @param message the validation message explaining the validation status
-     */
-    protected ValidationResultImpl(String name, Object object, ValidationStatus status, String message) {
-        this.name = name;
-        this.object = object;
-        this.status = status;
-        this.message = message;
-    }
-
     /**
      * Validates that the value is not {@code null}.
      *
index a8a0e61..faf4100 100644 (file)
@@ -25,6 +25,7 @@ import java.util.ArrayList;
 import java.util.List;
 import lombok.AccessLevel;
 import lombok.Getter;
+import lombok.NoArgsConstructor;
 import lombok.Setter;
 import org.onap.policy.common.parameters.annotations.NotNull;
 
@@ -34,6 +35,7 @@ import org.onap.policy.common.parameters.annotations.NotNull;
  * Note: this currently does not support Min/Max validation of "short" or "byte"; these
  * annotations are simply ignored for these types.
  */
+@NoArgsConstructor
 public class ValueValidator {
 
     /**
@@ -55,14 +57,6 @@ public class ValueValidator {
      */
     protected List<Checker> checkers = new ArrayList<>(10);
 
-
-    /**
-     * Constructs the object.
-     */
-    public ValueValidator() {
-        // do nothing
-    }
-
     /**
      * Determines if the validator has anything to check.
      *
index cbf5d0e..4d10bd1 100644 (file)
@@ -25,18 +25,17 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
 
 /**
  * Converter for Double values. By default, GSON treats all Objects that are numbers, as
  * Double. This converts Doubles to Integer or Long, if possible. It converts stand-alone
  * Doubles, as well as those found within Arrays and Maps.
  */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
 public class DoubleConverter {
 
-    private DoubleConverter() {
-        // do nothing
-    }
-
     /**
      * Performs in-place conversion of all values in a list.
      *
index c15ccb7..af4a746 100644 (file)
@@ -29,6 +29,7 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.util.function.Supplier;
+import lombok.Getter;
 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
 
 /**
@@ -49,6 +50,7 @@ public class Adapter {
     /**
      * Name of the property within the json structure containing the item.
      */
+    @Getter
     private final String propName;
 
     /**
@@ -69,6 +71,7 @@ public class Adapter {
     /**
      * Name of the item being lifted - used when throwing exceptions.
      */
+    @Getter
     private final String fullName;
 
     /**
@@ -143,14 +146,6 @@ public class Adapter {
         return reader.getConverter().fromJsonTree(tree);
     }
 
-    public final String getPropName() {
-        return propName;
-    }
-
-    public final String getFullName() {
-        return fullName;
-    }
-
     /**
      * Makes an error message, appending the item's full name to the message prefix.
      *
index ef4eaae..954d3f4 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 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.
@@ -30,6 +30,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import lombok.Getter;
 import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
 import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
@@ -79,23 +80,16 @@ public class ClassWalker {
      * Method having {@link GsonJsonAnyGetter} annotation. Overwritten as new "any-getters"
      * are identified.
      */
+    @Getter
     private Method anyGetter = null;
 
     /**
      * Method having {@link GsonJsonAnySetter} annotation. Overwritten as new "any-setters"
      * are identified.
      */
+    @Getter
     private Method anySetter = null;
 
-
-    public Method getAnyGetter() {
-        return anyGetter;
-    }
-
-    public Method getAnySetter() {
-        return anySetter;
-    }
-
     /**
      * Gets the names of input properties that are not being ignored.
      *
index cf46fc7..4e85791 100644 (file)
     <name>Integrity Audit</name>
 
     <dependencies>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
index 95eecbc..5bfedaa 100644 (file)
@@ -2,14 +2,14 @@
  * ============LICENSE_START=======================================================
  * Integrity Audit
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2021 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.
 package org.onap.policy.common.ia;
 
 import java.util.function.Supplier;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
 import org.onap.policy.common.utils.time.CurrentTime;
 
 /**
  * "Current" time used by IntegrityMonitor classes.
  */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
 public class AuditorTime {
 
     /**
@@ -40,16 +43,9 @@ public class AuditorTime {
      */
     private static Supplier<CurrentTime> supplier = () -> currentTime;
 
-    /**
-     * Constructor.
-     */
-    private AuditorTime() {
-        super();
-    }
-
     /**
      * Get instance.
-     * 
+     *
      * @return the CurrentTime singleton
      */
     public static CurrentTime getInstance() {
index 10900e3..66ab307 100644 (file)
@@ -21,6 +21,8 @@
 package org.onap.policy.common.ia;
 
 import java.util.Properties;
+import lombok.Getter;
+import lombok.Setter;
 import org.apache.commons.lang3.StringUtils;
 import org.onap.policy.common.ia.IntegrityAuditProperties.NodeTypeEnum;
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
@@ -34,8 +36,12 @@ public class IntegrityAudit {
 
     private static final Logger logger = FlexLogger.getLogger(IntegrityAudit.class);
 
-    private static boolean isUnitTesting;
-    private boolean isThreadInitialized = false;
+    @Getter
+    @Setter
+    private static boolean unitTesting;
+
+    @Getter
+    private boolean threadInitialized = false;
 
     AuditThread auditThread = null;
 
@@ -54,6 +60,7 @@ public class IntegrityAudit {
      * indicated period
      *
      */
+    @Getter
     private int integrityAuditPeriodSeconds;
 
     /**
@@ -93,13 +100,6 @@ public class IntegrityAudit {
 
     }
 
-    /**
-     * Used during JUnit testing by AuditPeriodTest.java
-     */
-    public int getIntegrityAuditPeriodSeconds() {
-        return integrityAuditPeriodSeconds;
-    }
-
     /**
      * Determine if the nodeType conforms to the required node types.
      */
@@ -237,21 +237,9 @@ public class IntegrityAudit {
         logger.info("stopAuditThread: Exiting");
     }
 
-    public boolean isThreadInitialized() {
-        return isThreadInitialized;
-    }
-
     public void setThreadInitialized(boolean isThreadInitialized) {
         logger.info("setThreadInitialized: Setting isThreadInitialized=" + isThreadInitialized);
-        this.isThreadInitialized = isThreadInitialized;
-    }
-
-    public static boolean isUnitTesting() {
-        return isUnitTesting;
-    }
-
-    public static void setUnitTesting(boolean isUnitTesting) {
-        IntegrityAudit.isUnitTesting = isUnitTesting;
+        this.threadInitialized = isThreadInitialized;
     }
 
     /**
index 365afd2..9122b72 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * Integrity Audit
  * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 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.
 
 package org.onap.policy.common.ia;
 
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
 public class IntegrityAuditProperties {
 
     public static final int DEFAULT_AUDIT_PERIOD_SECONDS = -1; // Audit does not run
@@ -38,9 +42,4 @@ public class IntegrityAuditProperties {
         PDP_XACML, PDP_DROOLS, PAP, PAP_ADMIN, LOGPARSER, BRMS_GATEWAY, ASTRA_GATEWAY, ELK_SERVER, PYPDP
 
     }
-
-    private IntegrityAuditProperties() {
-
-    }
-
 }
index 1c8277c..3768885 100644 (file)
@@ -35,6 +35,10 @@ import javax.persistence.PreUpdate;
 import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
 /*
  * The Entity class to for management of IntegrityAudits
  */
@@ -44,15 +48,20 @@ import org.onap.policy.common.ia.AuditorTime;
 @Table(name = "IntegrityAuditEntity")
 @NamedQuery(name = " IntegrityAuditEntity.findAll", query = "SELECT e FROM IntegrityAuditEntity e ")
 @NamedQuery(name = "IntegrityAuditEntity.deleteAll", query = "DELETE FROM IntegrityAuditEntity WHERE 1=1")
-
+@NoArgsConstructor
+@Getter
+@Setter
 public class IntegrityAuditEntity implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    private static boolean isUnitTesting;
+    @Getter
+    @Setter
+    private static boolean unitTesting;
 
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
     @Column(name = "id")
+    @Setter(AccessLevel.PRIVATE)
     private long id;
 
     @Column(name = "persistenceUnit", nullable = false)
@@ -90,11 +99,6 @@ public class IntegrityAuditEntity implements Serializable {
     @Column(name = "lastUpdated")
     private Date lastUpdated;
 
-
-    public IntegrityAuditEntity() {
-        // Empty constructor
-    }
-
     /**
      * Pre persist.
      */
@@ -110,106 +114,6 @@ public class IntegrityAuditEntity implements Serializable {
         this.lastUpdated = AuditorTime.getInstance().getDate();
     }
 
-    public long getId() {
-        return id;
-    }
-
-    public String getPersistenceUnit() {
-        return persistenceUnit;
-    }
-
-    public void setPersistenceUnit(String persistenceUnit) {
-        this.persistenceUnit = persistenceUnit;
-    }
-
-    public String getSite() {
-        return site;
-    }
-
-    public void setSite(String site) {
-        this.site = site;
-    }
-
-    public String getNodeType() {
-        return nodeType;
-    }
-
-    public void setNodeType(String nodeType) {
-        this.nodeType = nodeType;
-    }
-
-    public String getResourceName() {
-        return resourceName;
-    }
-
-    public void setResourceName(String resourceName) {
-        this.resourceName = resourceName;
-    }
-
-    public boolean isDesignated() {
-        return designated;
-    }
-
-    public void setDesignated(boolean designated) {
-        this.designated = designated;
-    }
-
-    public String getJdbcDriver() {
-        return jdbcDriver;
-    }
-
-    public void setJdbcDriver(String jdbcDriver) {
-        this.jdbcDriver = jdbcDriver;
-    }
-
-    public String getJdbcUrl() {
-        return jdbcUrl;
-    }
-
-    public void setJdbcUrl(String jdbcUrl) {
-        this.jdbcUrl = jdbcUrl;
-    }
-
-    public String getJdbcUser() {
-        return jdbcUser;
-    }
-
-    public void setJdbcUser(String jdbcUser) {
-        this.jdbcUser = jdbcUser;
-    }
-
-    public String getJdbcPassword() {
-        return jdbcPassword;
-    }
-
-    public void setJdbcPassword(String jdbcPassword) {
-        this.jdbcPassword = jdbcPassword;
-    }
-
-    public Date getLastUpdated() {
-        return lastUpdated;
-    }
-
-    public void setLastUpdated(Date lastUpdated) {
-        this.lastUpdated = lastUpdated;
-    }
-
-    public Date getCreatedDate() {
-        return createdDate;
-    }
-
-    public void setCreatedDate(Date created) {
-        this.createdDate = created;
-    }
-
-    public static boolean isUnitTesting() {
-        return isUnitTesting;
-    }
-
-    public static void setUnitTesting(boolean isUnitTesting) {
-        IntegrityAuditEntity.isUnitTesting = isUnitTesting;
-    }
-
     private void writeObject(ObjectOutputStream out) throws IOException {
         if (isUnitTesting()) {
             /*