Implement validation and hierarchical get
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaPolicy.java
index 7b4ffd1..2816df0 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -46,7 +46,6 @@ import lombok.NonNull;
 
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
-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;
@@ -92,7 +91,7 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
     private Map<String, String> properties;
 
     @ElementCollection
-    private List<PfConceptKey> targets;
+    private List<PfConceptKey> targets = new ArrayList<>();
     // @formatter:on
 
     /**
@@ -129,6 +128,9 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
      */
     public JpaToscaPolicy(@NonNull final JpaToscaPolicy copyConcept) {
         super(copyConcept);
+        this.type = new PfConceptKey(copyConcept.type);
+        this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
+        this.targets = PfUtils.mapList(copyConcept.targets, PfConceptKey::new);
     }
 
     /**
@@ -188,15 +190,13 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
 
         if (toscaPolicy.getType() != null) {
             type.setName(toscaPolicy.getType());
-        }
-        else {
+        } else {
             type.setName(PfKey.NULL_KEY_NAME);
         }
 
         if (toscaPolicy.getTypeVersion() != null) {
             type.setVersion(toscaPolicy.getTypeVersion());
-        }
-        else {
+        } else {
             type.setVersion(PfKey.NULL_KEY_VERSION);
         }
 
@@ -350,33 +350,4 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
 
         return PfUtils.compareObjects(targets, other.targets);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull PfConcept target) {
-        final Object copyObject = target;
-        Assertions.instanceOf(copyObject, PfConcept.class);
-
-        final JpaToscaPolicy copy = ((JpaToscaPolicy) copyObject);
-        super.copyTo(target);
-
-        copy.setType(new PfConceptKey(type));
-
-        if (properties == null) {
-            copy.setProperties(null);
-        } else {
-            copy.setProperties(properties);
-        }
-
-        if (targets == null) {
-            copy.setTargets(null);
-        } else {
-            final List<PfConceptKey> newTargets = new ArrayList<>();
-            for (final PfConceptKey oldTarget : targets) {
-                newTargets.add(new PfConceptKey(oldTarget));
-            }
-            copy.setTargets(newTargets);
-        }
-
-        return copy;
-    }
 }