Address sonar issues in models
[policy/models.git] / models-pdp / src / main / java / org / onap / policy / models / pdp / persistence / concepts / JpaPdpGroup.java
index 1e77c09..67458cf 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,7 +28,6 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-
 import javax.persistence.CascadeType;
 import javax.persistence.CollectionTable;
 import javax.persistence.Column;
@@ -41,14 +40,11 @@ import javax.persistence.InheritanceType;
 import javax.persistence.JoinColumn;
 import javax.persistence.OneToMany;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
 import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConcept;
@@ -135,6 +131,11 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
      */
     public JpaPdpGroup(@NonNull final JpaPdpGroup copyConcept) {
         super(copyConcept);
+        this.key = new PfConceptKey(copyConcept.key);
+        this.description = copyConcept.description;
+        this.pdpGroupState = copyConcept.pdpGroupState;
+        this.properties = (copyConcept.properties == null ? null : new LinkedHashMap<>(copyConcept.properties));
+        this.pdpSubGroups = PfUtils.mapList(copyConcept.pdpSubGroups, JpaPdpSubGroup::new, new ArrayList<>(0));
     }
 
     /**
@@ -238,7 +239,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
         }
 
         if (properties != null) {
-            result = validateProperties(result);
+            validateProperties(result);
         }
 
         if (pdpSubGroups == null) {
@@ -256,11 +257,9 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
     /**
      * Validate the properties.
      *
-     * @param resultIn the incoming validation results so far
-     * @return the revalidation results including the property validation results
+     * @param result where to place any new validation results
      */
-    private PfValidationResult validateProperties(PfValidationResult resultIn) {
-        PfValidationResult result = resultIn;
+    private void validateProperties(PfValidationResult result) {
 
         for (Entry<String, String> propertyEntry : properties.entrySet()) {
             if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
@@ -272,8 +271,6 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
                         "a property value may not be null or blank"));
             }
         }
-
-        return result;
     }
 
     @Override
@@ -285,7 +282,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
             return 0;
         }
         if (getClass() != otherConcept.getClass()) {
-            return this.getClass().getCanonicalName().compareTo(otherConcept.getClass().getCanonicalName());
+            return this.getClass().getName().compareTo(otherConcept.getClass().getName());
         }
 
         final JpaPdpGroup other = (JpaPdpGroup) otherConcept;
@@ -310,19 +307,4 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
 
         return PfUtils.compareObjects(pdpSubGroups, other.pdpSubGroups);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        Assertions.instanceOf(target, JpaPdpGroup.class);
-
-        final JpaPdpGroup copy = ((JpaPdpGroup) target);
-        copy.setKey(new PfConceptKey(key));
-
-        copy.setDescription(description);
-        copy.setPdpGroupState(pdpGroupState);
-        copy.setProperties(properties == null ? null : new LinkedHashMap<>(properties));
-        copy.setPdpSubGroups(PfUtils.mapList(pdpSubGroups, JpaPdpSubGroup::new));
-
-        return copy;
-    }
 }