Replace copyTo methods with copy constructors 54/94354/3
authorJim Hahn <jrh3@att.com>
Mon, 26 Aug 2019 16:20:27 +0000 (12:20 -0400)
committerJim Hahn <jrh3@att.com>
Tue, 27 Aug 2019 15:49:30 +0000 (11:49 -0400)
Deleted the copyTo() method from PfConcepts and replaced uses
with deep-copy constructors.  Also added mapMap() and makeCopy()
methods to PfUtils to facilitate.

Change-Id: Id6391bb806ef0dfab6c1089278bf2b514c7e303e
Issue-ID: POLICY-1600
Signed-off-by: Jim Hahn <jrh3@att.com>
52 files changed:
models-base/src/main/java/org/onap/policy/models/base/PfConcept.java
models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java
models-base/src/main/java/org/onap/policy/models/base/PfModel.java
models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java
models-base/src/main/java/org/onap/policy/models/base/PfUtils.java
models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java
models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java
models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java
models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java
models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptKeySub.java
models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java
models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java
models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
models-dao/src/test/java/org/onap/policy/models/dao/DummyConceptEntity.java
models-dao/src/test/java/org/onap/policy/models/dao/DummyReferenceEntity.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java
models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java
models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java
models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java

index 9a376fe..a1cfac4 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -44,7 +45,7 @@ public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
      * @param copyConcept the concept to copy from
      */
     public PfConcept(@NonNull final PfConcept copyConcept) {
-        copyConcept.copyTo(this);
+        // nothing else to do (other than @NonNull check)
     }
 
     /**
@@ -86,15 +87,6 @@ public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
     @Override
     public abstract int hashCode();
 
-    /**
-     * Copy this concept to another object. The target object must have the same class as the source
-     * object.
-     *
-     * @param target the target object to which this object is copied
-     * @return the copied object
-     */
-    public abstract PfConcept copyTo(@NonNull PfConcept target);
-
     /**
      * Gets the ID string of this concept.
      *
index 63ab14e..1b60932 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -29,7 +30,6 @@ import java.util.Map.Entry;
 import java.util.NavigableMap;
 import java.util.Set;
 import java.util.TreeMap;
-
 import javax.persistence.CascadeType;
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
@@ -37,12 +37,9 @@ import javax.persistence.FetchType;
 import javax.persistence.ManyToMany;
 import javax.persistence.Table;
 import javax.ws.rs.core.Response;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 
 // @formatter:off
@@ -111,6 +108,14 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
      */
     public PfConceptContainer(@NonNull final PfConceptContainer<C, A> copyConcept) {
         super(copyConcept);
+        this.key = new PfConceptKey(copyConcept.key);
+
+        this.conceptMap = new TreeMap<>();
+        for (final Entry<PfConceptKey, C> conceptMapEntry : copyConcept.conceptMap.entrySet()) {
+            PfConceptKey newK = new PfConceptKey(conceptMapEntry.getKey());
+            C newC = PfUtils.makeCopy(conceptMapEntry.getValue());
+            this.conceptMap.put(newK, newC);
+        }
     }
 
     @Override
@@ -278,24 +283,6 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
         return 0;
     }
 
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        Assertions.instanceOf(target, PfConceptContainer.class);
-
-        @SuppressWarnings("unchecked")
-        final PfConceptContainer<C, A> copy = (PfConceptContainer<C, A>) target;
-        copy.setKey(new PfConceptKey(key));
-        final Map<PfConceptKey, C> newConceptMap = new TreeMap<>();
-        for (final Entry<PfConceptKey, C> conceptMapEntry : conceptMap.entrySet()) {
-            C newC = getConceptNewInstance();
-            conceptMapEntry.getValue().copyTo(newC);
-            newConceptMap.put(new PfConceptKey(conceptMapEntry.getKey()), newC);
-        }
-        copy.setConceptMap(newConceptMap);
-
-        return copy;
-    }
-
     @Override
     public C get(final PfConceptKey conceptKey) {
         return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).get(conceptKey);
index 17fda7c..f5baae7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
- *  ModificationsCopyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 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.
@@ -73,6 +73,8 @@ public class PfConceptKey extends PfKey {
      */
     public PfConceptKey(@NonNull final PfConceptKey copyConcept) {
         super(copyConcept);
+        this.name = copyConcept.name;
+        this.version = copyConcept.version;
     }
 
     /**
@@ -288,20 +290,6 @@ public class PfConceptKey extends PfKey {
         version = Assertions.validateStringParameter(VERSION_TOKEN, version, VERSION_REGEXP);
     }
 
-    @Override
-    public PfConcept copyTo(final PfConcept target) {
-        Assertions.argumentNotNull(target, "target may not be null");
-
-        final PfConcept copyObject = target;
-        Assertions.instanceOf(copyObject, PfConceptKey.class);
-
-        final PfConceptKey copy = ((PfConceptKey) copyObject);
-        copy.setName(name);
-        copy.setVersion(version);
-
-        return copyObject;
-    }
-
     @Override
     public int compareTo(@NonNull final PfConcept otherObj) {
         Assertions.argumentNotNull(otherObj, "comparison object may not be null");
index d56b0db..0387323 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
 package org.onap.policy.models.base;
 
 import java.util.List;
-
-import javax.ws.rs.core.Response;
-
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
 import lombok.ToString;
-
 import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 
@@ -69,6 +66,7 @@ public class PfKeyUse extends PfKey {
      */
     public PfKeyUse(@NonNull final PfKeyUse copyConcept) {
         super(copyConcept);
+        this.usedKey = PfUtils.makeCopy(copyConcept.usedKey);
     }
 
     @Override
@@ -159,21 +157,4 @@ public class PfKeyUse extends PfKey {
 
         return usedKey.compareTo(other.usedKey);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        final Object copyObject = target;
-        Assertions.instanceOf(copyObject, PfKeyUse.class);
-
-        final PfKeyUse copy = ((PfKeyUse) copyObject);
-        try {
-            copy.usedKey = usedKey.getClass().newInstance();
-        } catch (final Exception e) {
-            throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
-                    "error copying concept key: " + e.getMessage(), e);
-        }
-        usedKey.copyTo(copy.usedKey);
-
-        return copy;
-    }
 }
index 07ec3af..83ae71c 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -91,6 +92,7 @@ public abstract class PfModel extends PfConcept {
      */
     public PfModel(@NonNull final PfModel copyConcept) {
         super(copyConcept);
+        this.key = new PfConceptKey(copyConcept.key);
     }
 
     /**
@@ -281,14 +283,4 @@ public abstract class PfModel extends PfConcept {
 
         return key.compareTo(other.key);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        Assertions.instanceOf(target, PfModel.class);
-
-        final PfModel copy = ((PfModel) target);
-        copy.setKey(new PfConceptKey(key));
-
-        return copy;
-    }
 }
index bdf16dc..a5ae6c5 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -381,22 +382,6 @@ public class PfReferenceKey extends PfKey {
         localName = Assertions.validateStringParameter(LOCAL_NAME, localName, LOCAL_NAME_REGEXP);
     }
 
-    @Override
-    public PfConcept copyTo(final PfConcept target) {
-        Assertions.argumentNotNull(target, "target may not be null");
-
-        final Object copyObject = target;
-        Assertions.instanceOf(copyObject, PfReferenceKey.class);
-
-        final PfReferenceKey copy = ((PfReferenceKey) copyObject);
-        copy.setParentKeyName(parentKeyName);
-        copy.setParentKeyVersion(parentKeyVersion);
-        copy.setLocalName(localName);
-        copy.setParentLocalName(parentLocalName);
-
-        return copy;
-    }
-
     @Override
     public int compareTo(final PfConcept otherObj) {
         Assertions.argumentNotNull(otherObj, "comparison object may not be null");
index c33271d..8f1040b 100644 (file)
 
 package org.onap.policy.models.base;
 
-import java.util.ArrayList;
+import java.lang.reflect.InvocationTargetException;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 import java.util.function.Function;
 import java.util.stream.Collectors;
+import javax.ws.rs.core.Response;
 
 /**
  * Utility class for Policy Framework concept utilities.
@@ -69,13 +73,88 @@ public final class PfUtils {
      *
      * @param source list whose elements are to be mapped, or {@code null}
      * @param mapFunc mapping function
+     * @param defaultValue value to be returned if source is {@code null}
      * @return a new list, containing mappings of all of the items in the original list
      */
-    public static <T> List<T> mapList(List<T> source, Function<T, T> mapFunc) {
+    public static <T> List<T> mapList(List<T> source, Function<T, T> mapFunc, List<T> defaultValue) {
         if (source == null) {
-            return new ArrayList<>(0);
+            return defaultValue;
         }
 
         return source.stream().map(mapFunc).collect(Collectors.toList());
     }
+
+    /**
+     * Convenience method to apply a mapping function to all of the elements of a list,
+     * generating a new list.
+     *
+     * @param source list whose elements are to be mapped, or {@code null}
+     * @param mapFunc mapping function
+     * @return a new list, containing mappings of all of the items in the original list,
+     *         or {@code null} if the source is {@code null}
+     */
+    public static <T> List<T> mapList(List<T> source, Function<T, T> mapFunc) {
+        return mapList(source, mapFunc, null);
+    }
+
+    /**
+     * Convenience method to apply a mapping function to all of the values of a map,
+     * generating a new map.
+     *
+     * @param source map whose values are to be mapped, or {@code null}
+     * @param mapFunc mapping function
+     * @param defaultValue value to be returned if source is {@code null}
+     * @return a new map, containing mappings of all of the items in the original map
+     */
+    public static <T> Map<String, T> mapMap(Map<String, T> source, Function<T, T> mapFunc,
+                    Map<String, T> defaultValue) {
+        if (source == null) {
+            return defaultValue;
+        }
+
+        Map<String, T> map = new LinkedHashMap<>();
+        for (Entry<String, T> ent : source.entrySet()) {
+            map.put(ent.getKey(), mapFunc.apply(ent.getValue()));
+        }
+
+        return map;
+    }
+
+    /**
+     * Convenience method to apply a mapping function to all of the values of a map,
+     * generating a new map.
+     *
+     * @param source map whose values are to be mapped, or {@code null}
+     * @param mapFunc mapping function
+     * @return a new map, containing mappings of all of the items in the original map,
+     *         or {@code null} if the source is {@code null}
+     */
+    public static <T> Map<String, T> mapMap(Map<String, T> source, Function<T, T> mapFunc) {
+        return mapMap(source, mapFunc, null);
+    }
+
+    /**
+     * Makes a copy of an object using the copy constructor from the object's class.
+     *
+     * @param source object to be copied
+     * @return a copy of the source, or {@code null} if the source is {@code null}
+     * @throws PfModelRuntimeException if the object cannot be copied
+     */
+    public static <T> T makeCopy(T source) {
+        if (source == null) {
+            return null;
+        }
+
+        try {
+            @SuppressWarnings("unchecked")
+            Class<? extends T> clazz = (Class<? extends T>) source.getClass();
+
+            return clazz.getConstructor(clazz).newInstance(source);
+
+        } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException
+                        | RuntimeException e) {
+            throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
+                            "error copying concept key class: " + source.getClass().getName(), e);
+        }
+    }
 }
index 984d2b9..5e84dff 100644 (file)
@@ -113,8 +113,8 @@ public class PfConceptContainerTest {
 
         assertEquals(0, container.compareTo(clonedContainer));
 
-        final DummyPfConceptContainer container2 = container;
-        assertThatThrownBy(() -> container2.copyTo(null)).hasMessage("target is marked @NonNull but is null");
+        assertThatThrownBy(() -> new DummyPfConceptContainer((DummyPfConceptContainer) null))
+                        .isInstanceOf(NullPointerException.class);
 
         assertFalse(container.compareTo(null) == 0);
         assertEquals(0, container.compareTo(container));
index f7d1d9a..3e5d738 100644 (file)
@@ -96,14 +96,9 @@ public class PfKeyUseTest {
         assertThatThrownBy(() -> keyUse.validate(null)).hasMessage("result is marked @NonNull but is null");
 
         PfKeyUse testKeyUse = new PfKeyUse(new DummyPfConceptKeySub(new PfConceptKey()));
-        PfKeyUse targetKeyUse = new PfKeyUse(key);
+        assertEquals(testKeyUse, new PfKeyUse(testKeyUse));
 
-        assertThatThrownBy(() -> keyUse.copyTo(null)).hasMessage("target is marked @NonNull but is null");
-
-        assertThatThrownBy(() -> {
-            testKeyUse.copyTo(targetKeyUse);
-            keyUse.isCompatible(null);
-        }).hasMessage("error copying concept key: Some error message");
+        assertThatThrownBy(() -> new PfKeyUse((PfKeyUse) null)).isInstanceOf(NullPointerException.class);
 
         assertThatThrownBy(() -> keyUse.isNewerThan(null)).hasMessage(OTHER_KEY_IS_NULL);
 
index 2f4a1be..9b1a778 100644 (file)
@@ -60,7 +60,7 @@ public class PfModelTest {
         dpmClone.clean();
         assertEquals(dpm, dpmClone);
 
-        assertThatThrownBy(() -> dpm.copyTo(null)).hasMessage("target is marked @NonNull but is null");
+        assertThatThrownBy(() -> new DummyPfModel((DummyPfModel) null)).isInstanceOf(NullPointerException.class);
 
         assertEquals(0, dpm.compareTo(dpmClone));
         assertEquals(-1, dpm.compareTo(null));
index 21b82fc..b12ce4d 100644 (file)
@@ -125,14 +125,9 @@ public class PfReferenceKeyTest {
 
         assertFalse(testReferenceKey.equals(null));
 
-        assertThatThrownBy(() -> testReferenceKey.copyTo(null)).hasMessage("target may not be null");
+        assertThatThrownBy(() -> new PfReferenceKey((PfReferenceKey) null)).isInstanceOf(NullPointerException.class);
 
-        assertThatThrownBy(() -> testReferenceKey.copyTo(new PfConceptKey("Key", VERSION001)))
-                        .hasMessage("org.onap.policy.models.base.PfConceptKey"
-                                        + " is not an instance of org.onap.policy.models.base.PfReferenceKey");
-
-        PfReferenceKey targetRefKey = new PfReferenceKey();
-        assertEquals(testReferenceKey, testReferenceKey.copyTo(targetRefKey));
+        assertEquals(testReferenceKey, new PfReferenceKey(testReferenceKey));
     }
 
     @Test
index bd55dcd..a66aba2 100644 (file)
 
 package org.onap.policy.models.base;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import lombok.Getter;
+import lombok.ToString;
 import org.junit.Test;
 
 /**
@@ -52,13 +57,7 @@ public class PfUtilsTest {
         List<Object> resultList = PfUtils.mapList(null, item -> {
             throw new RuntimeException("should not be invoked");
         });
-        assertTrue(resultList.isEmpty());
-
-        // verify that we can modify the empty list without throwing an exception
-        resultList.add("xyz");
-        resultList.add("pdq");
-        resultList.remove("xyz");
-
+        assertNull(resultList);
 
         List<String> origList = Arrays.asList("abc", "def");
         List<String> newList = PfUtils.mapList(origList, text -> text + "X");
@@ -69,4 +68,54 @@ public class PfUtilsTest {
         newList.remove("abcX");
         newList.add("something else");
     }
+
+    @Test
+    public void testMapMap() {
+        Map<String,String> resultMap = PfUtils.mapMap(null, item -> {
+            throw new RuntimeException("should not be invoked");
+        });
+        assertNull(resultMap);
+
+        Map<String,String> origMap = new TreeMap<>();
+        origMap.put("key2A", "xyz2");
+        origMap.put("key2B", "pdq2");
+        Map<String,String> newMap = PfUtils.mapMap(origMap, text -> text + "X");
+
+        assertEquals("{key2A=xyz2X, key2B=pdq2X}", newMap.toString());
+
+        // verify that we can modify the map without throwing an exception
+        newMap.remove("abcX");
+        newMap.put("something", "else");
+    }
+
+    @Test
+    public void testMakeCopy() {
+        assertNull(PfUtils.makeCopy((MyObject) null));
+
+        MyObject origObject = new MyObject();
+        origObject.name = HELLO;
+        assertEquals(origObject.toString(), PfUtils.makeCopy(origObject).toString());
+
+        assertThatThrownBy(() -> PfUtils.makeCopy(new NoCopyConstructor())).isInstanceOf(PfModelRuntimeException.class);
+    }
+
+    @Getter
+    @ToString
+    private static class MyObject {
+        private String name;
+
+        public MyObject() {
+            // do nothing
+        }
+
+        @SuppressWarnings("unused")
+        public MyObject(MyObject source) {
+            this.name = source.name;
+        }
+    }
+
+    @Getter
+    private static class NoCopyConstructor {
+        private String name;
+    }
 }
index 6cb44e6..be398b9 100644 (file)
 package org.onap.policy.models.base.testconcepts;
 
 import java.util.List;
-
 import javax.persistence.EmbeddedId;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
 import org.apache.commons.lang3.ObjectUtils;
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfConceptKey;
@@ -72,6 +68,8 @@ public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuth
      */
     public DummyPfConcept(final DummyPfConcept copyConcept) {
         super(copyConcept);
+        this.key = new PfConceptKey(copyConcept.key);
+        this.description = copyConcept.description;
     }
 
     @Override
@@ -141,16 +139,4 @@ public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuth
 
         return ObjectUtils.compare(description, other.description);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull PfConcept target) {
-        final Object copyObject = target;
-        Assertions.instanceOf(copyObject, PfConcept.class);
-
-        final DummyPfConcept copy = ((DummyPfConcept) copyObject);
-        copy.setKey(new PfConceptKey(key));
-        copy.setDescription(description);
-
-        return copy;
-    }
 }
index da18cba..893dc53 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -50,4 +51,13 @@ public class DummyPfConceptKeySub extends PfConceptKey {
     public DummyPfConceptKeySub(@NonNull final PfConceptKey usedKey) {
         super(usedKey);
     }
+
+    /**
+     * Copy constructor.
+     *
+     * @param source object to be copied
+     */
+    public DummyPfConceptKeySub(@NonNull final DummyPfConceptKeySub source) {
+        super(source);
+    }
 }
index 944c1e6..058ef37 100644 (file)
@@ -33,6 +33,12 @@ import org.onap.policy.models.base.PfValidationResult;
 public class DummyPfKey extends PfKey {
     private static final long serialVersionUID = 1L;
 
+    public DummyPfKey() { }
+
+    public DummyPfKey(DummyPfKey source) {
+        super(source);
+    }
+
     @Override
     public int compareTo(PfConcept arg0) {
         return 0;
@@ -93,11 +99,6 @@ public class DummyPfKey extends PfKey {
         return 0;
     }
 
-    @Override
-    public PfConcept copyTo(PfConcept target) {
-        return null;
-    }
-
     @Override
     public boolean isNewerThan(@NonNull PfKey otherKey) {
         // TODO Auto-generated method stub
index 4a30f59..764b91b 100644 (file)
@@ -23,18 +23,13 @@ package org.onap.policy.models.base.testconcepts;
 
 import java.util.ArrayList;
 import java.util.List;
-
-import javax.ws.rs.core.Response;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
-
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfKey;
 import org.onap.policy.models.base.PfModel;
-import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.base.PfValidationResult;
 
 @Data
@@ -83,6 +78,11 @@ public class DummyPfModel extends PfModel {
      */
     public DummyPfModel(final DummyPfModel copyConcept) {
         super(copyConcept);
+
+        this.keyList = new ArrayList<>();
+        for (final PfKey pfKey : copyConcept.keyList) {
+            keyList.add(PfUtils.makeCopy(pfKey));
+        }
     }
 
     @Override
@@ -147,30 +147,4 @@ public class DummyPfModel extends PfModel {
 
         return 0;
     }
-
-    @Override
-    public PfConcept copyTo(final PfConcept targetObject) {
-        super.copyTo(targetObject);
-
-        Assertions.instanceOf(targetObject, DummyPfModel.class);
-
-        final DummyPfModel copy = ((DummyPfModel) targetObject);
-
-        final List<PfKey> newKeyList = new ArrayList<>();
-        for (final PfKey pfKey : keyList) {
-            PfKey newPfKey;
-            try {
-                newPfKey = pfKey.getClass().newInstance();
-            } catch (final Exception e) {
-                throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
-                        "error copying concept key: " + e.getMessage(), e);
-            }
-            newPfKey.copyTo(pfKey);
-            newKeyList.add(newPfKey);
-        }
-        copy.setKeyList(newKeyList);
-
-
-        return copy;
-    }
 }
index b5739a6..62b9c41 100644 (file)
@@ -35,6 +35,7 @@ import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.dao.DaoParameters;
 import org.onap.policy.models.dao.PfDao;
 import org.slf4j.Logger;
@@ -327,9 +328,7 @@ public class DefaultPfDao implements PfDao {
             if (t != null) {
                 // This clone is created to force the JPA DAO to recurse down through the object
                 try {
-                    final T clonedT = someClass.newInstance();
-                    t.copyTo(clonedT);
-                    return clonedT;
+                    return PfUtils.makeCopy(t);
                 } catch (final Exception e) {
                     LOGGER.warn("Could not clone object of class \"" + someClass.getName() + "\"", e);
                     return null;
@@ -352,9 +351,7 @@ public class DefaultPfDao implements PfDao {
             final T t = mg.find(someClass, key);
             if (t != null) {
                 try {
-                    final T clonedT = someClass.newInstance();
-                    t.copyTo(clonedT);
-                    return clonedT;
+                    return PfUtils.makeCopy(t);
                 } catch (final Exception e) {
                     LOGGER.warn("Could not clone object of class \"" + someClass.getName() + "\"", e);
                     return null;
index fa2e71a..c61a585 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -62,6 +63,17 @@ public class DummyConceptEntity extends PfConcept {
         this.key = new PfConceptKey();
     }
 
+    /**
+     * Copy constructor.
+     *
+     * @param source object from which to copy
+     */
+    public DummyConceptEntity(DummyConceptEntity source) {
+        this.key = source.key;
+        this.uuid = source.uuid;
+        this.description = source.description;
+    }
+
     public DummyConceptEntity(final Double doubleValue) {
         this.key = new PfConceptKey();
     }
@@ -100,21 +112,6 @@ public class DummyConceptEntity extends PfConcept {
         key.clean();
     }
 
-    @Override
-    public PfConcept copyTo(final PfConcept target) {
-        Assertions.argumentNotNull(target, "target may not be null");
-
-        final PfConcept copyObject = target;
-        Assertions.instanceOf(copyObject, DummyConceptEntity.class);
-
-        final DummyConceptEntity copy = ((DummyConceptEntity) copyObject);
-        copy.setKey(key);
-        copy.setUuid(uuid);
-        copy.setDescription(description);
-
-        return copyObject;
-    }
-
     @Override
     public int compareTo(final PfConcept otherObj) {
         Assertions.argumentNotNull(otherObj, "comparison object may not be null");
index aad2aa5..41ead40 100644 (file)
@@ -61,6 +61,11 @@ public class DummyReferenceEntity extends PfConcept {
         this.doubleValue = 123.45;
     }
 
+    public DummyReferenceEntity(DummyReferenceEntity source) {
+        this.key = source.key;
+        this.doubleValue = source.doubleValue;
+    }
+
     /**
      * Constructor.
      *
@@ -89,20 +94,6 @@ public class DummyReferenceEntity extends PfConcept {
         key.clean();
     }
 
-    @Override
-    public PfConcept copyTo(final PfConcept target) {
-        Assertions.argumentNotNull(target, "target may not be null");
-
-        final PfConcept copyObject = target;
-        Assertions.instanceOf(copyObject, DummyReferenceEntity.class);
-
-        final DummyReferenceEntity copy = ((DummyReferenceEntity) copyObject);
-        copy.setKey(key);
-        copy.setDoubleValue(doubleValue);
-
-        return copyObject;
-    }
-
 
     @Override
     public int compareTo(final PfConcept otherObj) {
index 4e7fc41..6d5f804 100644 (file)
@@ -22,6 +22,7 @@
 package org.onap.policy.models.pdp.concepts;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -69,7 +70,7 @@ public class PdpGroup implements PfNameVersion, Comparable<PdpGroup> {
         this.description = source.description;
         this.pdpGroupState = source.pdpGroupState;
         this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties));
-        this.pdpSubgroups = PfUtils.mapList(source.pdpSubgroups, PdpSubGroup::new);
+        this.pdpSubgroups = PfUtils.mapList(source.pdpSubgroups, PdpSubGroup::new, new ArrayList<>(0));
     }
 
     @Override
index 3655aa7..e50694b 100644 (file)
@@ -21,6 +21,7 @@
 
 package org.onap.policy.models.pdp.concepts;
 
+import java.util.ArrayList;
 import java.util.List;
 import lombok.Getter;
 import lombok.Setter;
@@ -78,8 +79,9 @@ public class PdpStatus extends PdpMessage {
         this.state = source.state;
         this.healthy = source.healthy;
         this.description = source.description;
-        this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, ToscaPolicyTypeIdentifier::new);
-        this.policies = PfUtils.mapList(source.policies, ToscaPolicyIdentifier::new);
+        this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, ToscaPolicyTypeIdentifier::new,
+                        new ArrayList<>(0));
+        this.policies = PfUtils.mapList(source.policies, ToscaPolicyIdentifier::new, new ArrayList<>(0));
         this.deploymentInstanceInfo = source.deploymentInstanceInfo;
         this.properties = source.properties;
         this.statistics = (source.statistics == null ? null : new PdpStatistics(source.statistics));
index 2618a50..236cc85 100644 (file)
@@ -21,6 +21,7 @@
 
 package org.onap.policy.models.pdp.concepts;
 
+import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -64,12 +65,13 @@ public class PdpSubGroup {
      */
     public PdpSubGroup(@NonNull final PdpSubGroup source) {
         this.pdpType = source.pdpType;
-        this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, ToscaPolicyTypeIdentifier::new);
-        this.policies = PfUtils.mapList(source.policies, ToscaPolicyIdentifier::new);
+        this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, ToscaPolicyTypeIdentifier::new,
+                        new ArrayList<>(0));
+        this.policies = PfUtils.mapList(source.policies, ToscaPolicyIdentifier::new, new ArrayList<>(0));
         this.currentInstanceCount = source.currentInstanceCount;
         this.desiredInstanceCount = source.desiredInstanceCount;
         this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties));
-        this.pdpInstances = PfUtils.mapList(source.pdpInstances, Pdp::new);
+        this.pdpInstances = PfUtils.mapList(source.pdpInstances, Pdp::new, new ArrayList<>(0));
     }
 
     /**
index 7d90c03..5820a35 100644 (file)
@@ -25,21 +25,17 @@ package org.onap.policy.models.pdp.persistence.concepts;
 
 import java.io.Serializable;
 import java.util.List;
-
 import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 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.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfKey;
@@ -113,6 +109,10 @@ public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializabl
      */
     public JpaPdp(@NonNull final JpaPdp copyConcept) {
         super(copyConcept);
+        this.key = new PfReferenceKey(copyConcept.key);
+        this.pdpState = copyConcept.pdpState;
+        this.healthy = copyConcept.healthy;
+        this.message = copyConcept.message;
     }
 
     /**
@@ -230,17 +230,4 @@ public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializabl
 
         return ObjectUtils.compare(message, other.message);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        Assertions.instanceOf(target, JpaPdp.class);
-
-        final JpaPdp copy = ((JpaPdp) target);
-        copy.setKey(new PfReferenceKey(key));
-        copy.setPdpState(pdpState);
-        copy.setHealthy(healthy);
-        copy.setMessage(message);
-
-        return copy;
-    }
 }
index 36d5cc1..0df620b 100644 (file)
@@ -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));
     }
 
     /**
@@ -310,19 +311,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;
-    }
 }
index 723d427..3a81c0b 100644 (file)
@@ -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.Column;
 import javax.persistence.ElementCollection;
@@ -44,8 +43,6 @@ import javax.persistence.Table;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
-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;
@@ -145,6 +142,14 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro
      */
     public JpaPdpSubGroup(@NonNull final JpaPdpSubGroup copyConcept) {
         super(copyConcept);
+        this.key = new PfReferenceKey(copyConcept.key);
+        this.supportedPolicyTypes = PfUtils.mapList(copyConcept.supportedPolicyTypes,
+                                        PfConceptKey::new, new ArrayList<>(0));
+        this.policies = PfUtils.mapList(copyConcept.policies, PfConceptKey::new, new ArrayList<>(0));
+        this.currentInstanceCount = copyConcept.currentInstanceCount;
+        this.desiredInstanceCount = copyConcept.desiredInstanceCount;
+        this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
+        this.pdpInstances = PfUtils.mapList(copyConcept.pdpInstances, JpaPdp::new, new ArrayList<>(0));
     }
 
     /**
@@ -393,21 +398,4 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro
 
         return PfUtils.compareObjects(pdpInstances, other.pdpInstances);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        Assertions.instanceOf(target, JpaPdpSubGroup.class);
-
-        final JpaPdpSubGroup copy = ((JpaPdpSubGroup) target);
-        copy.setKey(new PfReferenceKey(key));
-
-        copy.setSupportedPolicyTypes(PfUtils.mapList(supportedPolicyTypes, PfConceptKey::new));
-        copy.setPolicies(PfUtils.mapList(policies, PfConceptKey::new));
-        copy.setCurrentInstanceCount(currentInstanceCount);
-        copy.setDesiredInstanceCount(desiredInstanceCount);
-        copy.setProperties(properties == null ? null : new LinkedHashMap<>(properties));
-        copy.setPdpInstances(PfUtils.mapList(pdpInstances, JpaPdp::new));
-
-        return copy;
-    }
 }
index a2f502b..b40c919 100644 (file)
@@ -119,9 +119,7 @@ public class JpaPdpGroupTest {
         testJpaPdpGroup.setKey(new PfConceptKey(PDP_GROUP0, VERSION));
         testJpaPdpGroup.fromAuthorative(testPdpGroup);
 
-        assertThatThrownBy(() -> {
-            testJpaPdpGroup.copyTo(null);
-        }).hasMessage("target is marked @NonNull but is null");
+        assertThatThrownBy(() -> new JpaPdpGroup((JpaPdpGroup) null)).isInstanceOf(NullPointerException.class);
 
         assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName());
         assertEquals(PDP_GROUP0, new JpaPdpGroup(testPdpGroup).getKey().getName());
@@ -230,5 +228,7 @@ public class JpaPdpGroupTest {
         assertEquals(2, testJpaPdpGroup.getKeys().size());
         testJpaPdpGroup.clean();
         assertEquals(2, testJpaPdpGroup.getKeys().size());
+
+        assertEquals(testJpaPdpGroup, new JpaPdpGroup(testJpaPdpGroup));
     }
 }
index 981f40f..ad0164a 100644 (file)
@@ -127,9 +127,7 @@ public class JpaPdpSubGroupTest {
             testJpaPdpSubGroup.fromAuthorative(null);
         }).hasMessage("pdpSubgroup is marked @NonNull but is null");
 
-        assertThatThrownBy(() -> {
-            testJpaPdpSubGroup.copyTo(null);
-        }).hasMessage("target is marked @NonNull but is null");
+        assertThatThrownBy(() -> new JpaPdpSubGroup((JpaPdpSubGroup) null)).isInstanceOf(NullPointerException.class);
 
         assertEquals(PDP_A, testJpaPdpSubGroup.getKey().getLocalName());
         assertEquals(PDP_A, new JpaPdpSubGroup(testPdpSubgroup).getKey().getLocalName());
@@ -279,5 +277,7 @@ public class JpaPdpSubGroupTest {
         assertEquals("Prop Value", testJpaPdpSubGroup.getProperties().get("PropKey"));
 
         assertEquals(4, testJpaPdpSubGroup.getKeys().size());
+
+        assertEquals(testJpaPdpSubGroup, new JpaPdpSubGroup(testJpaPdpSubGroup));
     }
 }
index 5ffba10..b6d5161 100644 (file)
@@ -99,9 +99,7 @@ public class JpaPdpTest {
             testJpaPdp.fromAuthorative(null);
         }).hasMessage("pdp is marked @NonNull but is null");
 
-        assertThatThrownBy(() -> {
-            testJpaPdp.copyTo(null);
-        }).hasMessage("target is marked @NonNull but is null");
+        assertThatThrownBy(() -> new JpaPdp((JpaPdp) null)).isInstanceOf(NullPointerException.class);
 
         assertEquals(PDP1, testJpaPdp.getKey().getLocalName());
         assertEquals(PDP1, new JpaPdp(testPdp).getKey().getLocalName());
@@ -184,5 +182,7 @@ public class JpaPdpTest {
         assertEquals(-13, testJpaPdp.compareTo(otherJpaPdp));
         testJpaPdp.setMessage("Valid Message");
         assertEquals(0, testJpaPdp.compareTo(otherJpaPdp));
+
+        assertEquals(testJpaPdp, new JpaPdp(testJpaPdp));
     }
 }
index 7e2b641..e959007 100644 (file)
@@ -28,18 +28,14 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-
 import javax.persistence.ElementCollection;
 import javax.persistence.Entity;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfConceptKey;
@@ -96,6 +92,9 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen
      */
     public JpaToscaDataType(final JpaToscaDataType copyConcept) {
         super(copyConcept);
+        // Constraints are immutable
+        this.constraints = (copyConcept.constraints != null ? new ArrayList<>(copyConcept.constraints) : null);
+        this.properties = PfUtils.mapMap(copyConcept.properties, JpaToscaProperty::new);
     }
 
     /**
@@ -264,35 +263,4 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen
 
         return 0;
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull PfConcept target) {
-        final Object copyObject = target;
-        Assertions.instanceOf(copyObject, PfConcept.class);
-
-        final JpaToscaDataType copy = ((JpaToscaDataType) copyObject);
-        super.copyTo(target);
-
-        if (constraints == null) {
-            copy.setConstraints(null);
-        } else {
-            final List<JpaToscaConstraint> newConstraints = new ArrayList<>();
-            for (final JpaToscaConstraint constraint : constraints) {
-                newConstraints.add(constraint); // Constraints are immutable
-            }
-            copy.setConstraints(newConstraints);
-        }
-
-        if (properties == null) {
-            copy.setProperties(null);
-        } else {
-            final Map<String, JpaToscaProperty> newProperties = new LinkedHashMap<>();
-            for (final Entry<String, JpaToscaProperty> propertyEntry : properties.entrySet()) {
-                newProperties.put(propertyEntry.getKey(), new JpaToscaProperty(propertyEntry.getValue()));
-            }
-            copy.setProperties(newProperties);
-        }
-
-        return copy;
-    }
 }
index 67d4ecf..8908ba7 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -31,7 +32,7 @@ import javax.persistence.Table;
 
 import lombok.Data;
 import lombok.EqualsAndHashCode;
-
+import lombok.ToString;
 import org.onap.policy.models.base.PfConceptContainer;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
@@ -45,6 +46,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
 @Table(name = "ToscaDataTypes")
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
+@ToString(callSuper = true)
 @EqualsAndHashCode(callSuper = true)
 public class JpaToscaDataTypes extends PfConceptContainer<JpaToscaDataType, ToscaDataType> {
     private static final long serialVersionUID = 2941102271022190348L;
index bade7a2..506add3 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -25,20 +26,16 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.TreeMap;
-
 import javax.persistence.AttributeOverride;
 import javax.persistence.AttributeOverrides;
 import javax.persistence.Column;
 import javax.persistence.ElementCollection;
 import javax.persistence.EmbeddedId;
 import javax.persistence.MappedSuperclass;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
 import org.apache.commons.lang3.ObjectUtils;
-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;
@@ -104,6 +101,10 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme
      */
     public JpaToscaEntityType(final JpaToscaEntityType<T> copyConcept) {
         super(copyConcept);
+        this.key = new PfConceptKey(copyConcept.key);
+        this.derivedFrom = (copyConcept.derivedFrom != null ? new PfConceptKey(copyConcept.derivedFrom) : null);
+        this.metadata = (copyConcept.metadata != null ? new TreeMap<>(copyConcept.metadata) : null);
+        this.description = copyConcept.description;
     }
 
     /**
@@ -269,27 +270,4 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme
 
         return ObjectUtils.compare(description, other.description);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull PfConcept target) {
-        final Object copyObject = target;
-        Assertions.instanceOf(copyObject, PfConcept.class);
-
-        @SuppressWarnings("unchecked")
-        final JpaToscaEntityType<T> copy = ((JpaToscaEntityType<T>) copyObject);
-        copy.setKey(new PfConceptKey(key));
-        copy.setDerivedFrom(derivedFrom != null ? new PfConceptKey(derivedFrom) : null);
-
-        if (metadata != null) {
-            final Map<String, String> newMatadata = new TreeMap<>();
-            for (final Entry<String, String> metadataEntry : metadata.entrySet()) {
-                newMatadata.put(metadataEntry.getKey(), metadataEntry.getValue());
-            }
-            copy.setMetadata(newMatadata);
-        }
-
-        copy.setDescription(description);
-
-        return copy;
-    }
 }
index 40727c9..7168137 100644 (file)
 package org.onap.policy.models.tosca.simple.concepts;
 
 import java.util.List;
-
 import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
 import org.apache.commons.lang3.ObjectUtils;
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfKey;
@@ -105,6 +101,10 @@ public class JpaToscaEventFilter extends PfConcept {
      */
     public JpaToscaEventFilter(final JpaToscaEventFilter copyConcept) {
         super(copyConcept);
+        this.key = new PfReferenceKey(copyConcept.key);
+        this.node = new PfConceptKey(copyConcept.node);
+        this.requirement = copyConcept.requirement;
+        this.capability = copyConcept.capability;
     }
 
     @Override
@@ -180,18 +180,4 @@ public class JpaToscaEventFilter extends PfConcept {
 
         return ObjectUtils.compare(capability, other.capability);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        final Object copyObject = target;
-        Assertions.instanceOf(copyObject, JpaToscaEventFilter.class);
-
-        final JpaToscaEventFilter copy = ((JpaToscaEventFilter) copyObject);
-        copy.setKey(new PfReferenceKey(key));
-        copy.setNode(new PfConceptKey(node));
-        copy.setRequirement(requirement);
-        copy.setCapability(capability);
-
-        return copy;
-    }
 }
\ No newline at end of file
index 5e4bd4f..cc9b1bc 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -21,7 +22,6 @@
 package org.onap.policy.models.tosca.simple.concepts;
 
 import java.util.List;
-
 import javax.persistence.CascadeType;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
@@ -29,12 +29,9 @@ import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfKey;
@@ -97,6 +94,7 @@ public class JpaToscaModel extends PfModel {
      */
     public JpaToscaModel(@NonNull final JpaToscaModel copyConcept) {
         super(copyConcept);
+        this.serviceTemplates = new JpaToscaServiceTemplates(copyConcept.serviceTemplates);
     }
 
     @Override
@@ -147,15 +145,4 @@ public class JpaToscaModel extends PfModel {
 
         return serviceTemplates.compareTo(other.serviceTemplates);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept targetObject) {
-        Assertions.instanceOf(targetObject, JpaToscaModel.class);
-
-        final JpaToscaModel copy = ((JpaToscaModel) targetObject);
-        super.copyTo(targetObject);
-        copy.setServiceTemplates(new JpaToscaServiceTemplates(serviceTemplates));
-
-        return copy;
-    }
 }
index 012d8a2..25e7dc0 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -31,7 +32,7 @@ import javax.persistence.Table;
 
 import lombok.Data;
 import lombok.EqualsAndHashCode;
-
+import lombok.ToString;
 import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConceptContainer;
 import org.onap.policy.models.base.PfConceptKey;
@@ -46,6 +47,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 @Table(name = "ToscaPolicies")
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
+@ToString(callSuper = true)
 @EqualsAndHashCode(callSuper = true)
 public class JpaToscaPolicies extends PfConceptContainer<JpaToscaPolicy, ToscaPolicy>
         implements PfAuthorative<List<Map<String, ToscaPolicy>>> {
index 7b4ffd1..36acec0 100644 (file)
 
 package org.onap.policy.models.tosca.simple.concepts;
 
-import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-
 import javax.persistence.AttributeOverride;
 import javax.persistence.AttributeOverrides;
 import javax.persistence.Column;
@@ -39,14 +37,11 @@ import javax.persistence.InheritanceType;
 import javax.persistence.Lob;
 import javax.persistence.Table;
 import javax.ws.rs.core.Response;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 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;
@@ -129,6 +124,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);
     }
 
     /**
@@ -350,33 +348,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;
-    }
 }
index d7560c4..37e92b5 100644 (file)
 
 package org.onap.policy.models.tosca.simple.concepts;
 
-import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-
 import javax.persistence.ElementCollection;
 import javax.persistence.Entity;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 import javax.persistence.Lob;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfConceptKey;
@@ -101,6 +96,9 @@ public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> impl
      */
     public JpaToscaPolicyType(final JpaToscaPolicyType copyConcept) {
         super(copyConcept);
+        this.properties = PfUtils.mapMap(copyConcept.properties, JpaToscaProperty::new);
+        this.targets = PfUtils.mapList(copyConcept.targets, PfConceptKey::new);
+        this.triggers = PfUtils.mapList(copyConcept.triggers, JpaToscaTrigger::new);
     }
 
     /**
@@ -300,45 +298,4 @@ public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> impl
 
         return PfUtils.compareObjects(triggers, other.triggers);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull PfConcept target) {
-        final Object copyObject = target;
-        Assertions.instanceOf(copyObject, PfConcept.class);
-
-        final JpaToscaPolicyType copy = ((JpaToscaPolicyType) copyObject);
-        super.copyTo(target);
-
-        if (properties == null) {
-            copy.setProperties(null);
-        } else {
-            final Map<String, JpaToscaProperty> newProperties = new LinkedHashMap<>();
-            for (final Entry<String, JpaToscaProperty> propertyEntry : properties.entrySet()) {
-                newProperties.put(propertyEntry.getKey(), new JpaToscaProperty(propertyEntry.getValue()));
-            }
-            copy.setProperties(newProperties);
-        }
-
-        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);
-        }
-
-        if (triggers == null) {
-            copy.setTargets(null);
-        } else {
-            final List<JpaToscaTrigger> newTriggers = new ArrayList<>();
-            for (final JpaToscaTrigger trigger : triggers) {
-                newTriggers.add(new JpaToscaTrigger(trigger));
-            }
-            copy.setTriggers(newTriggers);
-        }
-
-        return copy;
-    }
 }
index af8a21a..5a54a33 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -31,7 +32,7 @@ import javax.persistence.Table;
 
 import lombok.Data;
 import lombok.EqualsAndHashCode;
-
+import lombok.ToString;
 import org.onap.policy.models.base.PfConceptContainer;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
@@ -45,6 +46,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
 @Table(name = "ToscaPolicyTypes")
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
+@ToString(callSuper = true)
 @EqualsAndHashCode(callSuper = true)
 public class JpaToscaPolicyTypes extends PfConceptContainer<JpaToscaPolicyType, ToscaPolicyType> {
     private static final long serialVersionUID = -4157979965271220098L;
index 10e8b5d..93da035 100644 (file)
@@ -25,7 +25,6 @@ package org.onap.policy.models.tosca.simple.concepts;
 
 import java.util.ArrayList;
 import java.util.List;
-
 import javax.persistence.Column;
 import javax.persistence.ElementCollection;
 import javax.persistence.EmbeddedId;
@@ -33,13 +32,10 @@ import javax.persistence.Entity;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
 import org.apache.commons.lang3.ObjectUtils;
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfConceptKey;
@@ -125,6 +121,15 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
      */
     public JpaToscaProperty(final JpaToscaProperty copyConcept) {
         super(copyConcept);
+        this.key = new PfReferenceKey(copyConcept.key);
+        this.type = new PfConceptKey(copyConcept.type);
+        this.description = copyConcept.description;
+        this.required = copyConcept.required;
+        this.defaultValue = copyConcept.defaultValue;
+        this.status = copyConcept.status;
+        // Constraints are immutable
+        this.constraints = (copyConcept.constraints != null ? new ArrayList<>(copyConcept.constraints) : null);
+        this.entrySchema = (copyConcept.entrySchema != null ? new JpaToscaEntrySchema(copyConcept.entrySchema) : null);
     }
 
     /**
@@ -334,31 +339,4 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
 
         return entrySchema.compareTo(other.entrySchema);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        Assertions.instanceOf(target, JpaToscaProperty.class);
-
-        final JpaToscaProperty copy = ((JpaToscaProperty) target);
-        copy.setKey(new PfReferenceKey(key));
-        copy.setType(new PfConceptKey(type));
-        copy.setDescription(description);
-        copy.setRequired(required);
-        copy.setDefaultValue(defaultValue);
-        copy.setStatus(status);
-
-        if (constraints == null) {
-            copy.setConstraints(null);
-        } else {
-            final List<JpaToscaConstraint> newConstraints = new ArrayList<>();
-            for (final JpaToscaConstraint constraint : constraints) {
-                newConstraints.add(constraint); // Constraints are immutable
-            }
-            copy.setConstraints(newConstraints);
-        }
-
-        copy.setEntrySchema(entrySchema != null ? new JpaToscaEntrySchema(entrySchema) : null);
-
-        return copy;
-    }
 }
index 904db84..83c9dc0 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -21,9 +22,7 @@
 package org.onap.policy.models.tosca.simple.concepts;
 
 import com.google.gson.annotations.SerializedName;
-
 import java.util.List;
-
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -32,13 +31,10 @@ import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
 import org.apache.commons.lang3.ObjectUtils;
-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;
@@ -119,6 +115,11 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
      */
     public JpaToscaServiceTemplate(final JpaToscaServiceTemplate copyConcept) {
         super(copyConcept);
+        this.toscaDefinitionsVersion = copyConcept.toscaDefinitionsVersion;
+        this.dataTypes = (copyConcept.dataTypes != null ? new JpaToscaDataTypes(copyConcept.dataTypes) : null);
+        this.policyTypes = (copyConcept.policyTypes != null ? new JpaToscaPolicyTypes(copyConcept.policyTypes) : null);
+        this.topologyTemplate = (copyConcept.topologyTemplate != null
+                        ? new JpaToscaTopologyTemplate(copyConcept.topologyTemplate) : null);
     }
 
     /**
@@ -275,20 +276,4 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
 
         return ObjectUtils.compare(topologyTemplate, other.topologyTemplate);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull PfConcept target) {
-        final Object copyObject = target;
-        Assertions.instanceOf(copyObject, PfConcept.class);
-
-        final JpaToscaServiceTemplate copy = ((JpaToscaServiceTemplate) copyObject);
-        super.copyTo(target);
-        copy.setToscaDefinitionsVersion(toscaDefinitionsVersion);
-
-        copy.setDataTypes(dataTypes != null ? new JpaToscaDataTypes(dataTypes) : null);
-        copy.setPolicyTypes(policyTypes != null ? new JpaToscaPolicyTypes(policyTypes) : null);
-        copy.setTopologyTemplate(topologyTemplate != null ? new JpaToscaTopologyTemplate(topologyTemplate) : null);
-
-        return copy;
-    }
 }
index a62affd..5e5d014 100644 (file)
 package org.onap.policy.models.tosca.simple.concepts;
 
 import com.google.gson.annotations.SerializedName;
-
 import java.util.Date;
 import java.util.List;
-
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfKey;
 import org.onap.policy.models.base.PfReferenceKey;
@@ -106,6 +101,9 @@ public class JpaToscaTimeInterval extends PfConcept {
      */
     public JpaToscaTimeInterval(final JpaToscaTimeInterval copyConcept) {
         super(copyConcept);
+        this.key = new PfReferenceKey(copyConcept.key);
+        this.startTime = copyConcept.startTime;
+        this.endTime = copyConcept.endTime;
     }
 
     @Override
@@ -172,17 +170,4 @@ public class JpaToscaTimeInterval extends PfConcept {
 
         return PfUtils.compareObjects(endTime, other.endTime);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        final Object copyObject = target;
-        Assertions.instanceOf(copyObject, JpaToscaTimeInterval.class);
-
-        final JpaToscaTimeInterval copy = ((JpaToscaTimeInterval) copyObject);
-        copy.setKey(new PfReferenceKey(key));
-        copy.setStartTime(startTime);
-        copy.setEndTime(endTime);
-
-        return copy;
-    }
 }
index bafcb84..5fd1a49 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -21,7 +22,6 @@
 package org.onap.policy.models.tosca.simple.concepts;
 
 import java.util.List;
-
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
@@ -31,13 +31,10 @@ import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
 import org.apache.commons.lang3.ObjectUtils;
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfKey;
@@ -97,6 +94,9 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
      */
     public JpaToscaTopologyTemplate(final JpaToscaTopologyTemplate copyConcept) {
         super(copyConcept);
+        this.key = new PfReferenceKey(copyConcept.key);
+        this.description = copyConcept.description;
+        this.policies = (copyConcept.policies != null ? new JpaToscaPolicies(copyConcept.policies) : null);
     }
 
     /**
@@ -200,17 +200,4 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
 
         return ObjectUtils.compare(policies, other.policies);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull PfConcept target) {
-        final Object copyObject = target;
-        Assertions.instanceOf(copyObject, PfConcept.class);
-
-        final JpaToscaTopologyTemplate copy = ((JpaToscaTopologyTemplate) copyObject);
-        copy.setKey(new PfReferenceKey(key));
-        copy.setDescription(description);
-        copy.setPolicies(policies != null ? new JpaToscaPolicies(policies) : null);
-
-        return copy;
-    }
 }
index f46d43a..417e83f 100644 (file)
 package org.onap.policy.models.tosca.simple.concepts;
 
 import com.google.gson.annotations.SerializedName;
-
 import java.time.Duration;
 import java.util.List;
-
 import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
 import org.apache.commons.lang3.ObjectUtils;
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfKey;
@@ -137,6 +132,18 @@ public class JpaToscaTrigger extends PfConcept {
      */
     public JpaToscaTrigger(final JpaToscaTrigger copyConcept) {
         super(copyConcept);
+        this.key = new PfReferenceKey(copyConcept.key);
+        this.description = copyConcept.description;
+        this.eventType = copyConcept.eventType;
+        this.schedule = (copyConcept.schedule != null ? new JpaToscaTimeInterval(copyConcept.schedule) : null);
+        this.targetFilter =
+                        (copyConcept.targetFilter != null ? new JpaToscaEventFilter(copyConcept.targetFilter) : null);
+        this.condition = copyConcept.condition;
+        this.constraint = copyConcept.constraint;
+        this.period = copyConcept.period;
+        this.evaluations = copyConcept.evaluations;
+        this.method = copyConcept.method;
+        this.action = copyConcept.action;
     }
 
     @Override
@@ -298,24 +305,4 @@ public class JpaToscaTrigger extends PfConcept {
 
         return ObjectUtils.compare(action, other.action);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        Assertions.instanceOf(target, JpaToscaTrigger.class);
-
-        final JpaToscaTrigger copy = ((JpaToscaTrigger) target);
-        copy.setKey(new PfReferenceKey(key));
-        copy.setDescription(description);
-        copy.setEventType(eventType);
-        copy.setSchedule(schedule != null ? new JpaToscaTimeInterval(schedule) : null);
-        copy.setTargetFilter(targetFilter != null ? new JpaToscaEventFilter(targetFilter) : null);
-        copy.setCondition(condition);
-        copy.setConstraint(constraint);
-        copy.setPeriod(period);
-        copy.setEvaluations(evaluations);
-        copy.setMethod(method);
-        copy.setAction(action);
-
-        return copy;
-    }
 }
index 591c655..281ddfc 100644 (file)
@@ -62,9 +62,8 @@ public class JpaToscaDataTypeTest {
             new JpaToscaDataType((PfConceptKey) null);
         }).hasMessage("key is marked @NonNull but is null");
 
-        assertThatThrownBy(() -> {
-            new JpaToscaDataType((JpaToscaDataType) null);
-        }).hasMessage("copyConcept is marked @NonNull but is null");
+        assertThatThrownBy(() -> new JpaToscaDataType((JpaToscaDataType) null))
+                        .isInstanceOf(NullPointerException.class);
 
         PfConceptKey dtKey = new PfConceptKey("tdt", VERSION_001);
         JpaToscaDataType tdt = new JpaToscaDataType(dtKey);
@@ -86,8 +85,7 @@ public class JpaToscaDataTypeTest {
         assertEquals(tdt, tdtClone0);
         assertEquals(0, tdt.compareTo(tdtClone0));
 
-        JpaToscaDataType tdtClone1 = new JpaToscaDataType();
-        tdt.copyTo(tdtClone1);
+        JpaToscaDataType tdtClone1 = new JpaToscaDataType(tdt);
         assertEquals(tdt, tdtClone1);
         assertEquals(0, tdt.compareTo(tdtClone1));
 
@@ -106,10 +104,6 @@ public class JpaToscaDataTypeTest {
         otherDt.setProperties(properties);
         assertEquals(0, tdt.compareTo(otherDt));
 
-        assertThatThrownBy(() -> {
-            tdt.copyTo(null);
-        }).hasMessage("target is marked @NonNull but is null");
-
         assertEquals(3, tdt.getKeys().size());
         assertEquals(1, new JpaToscaDataType().getKeys().size());
 
index 602985d..7d34a73 100644 (file)
@@ -61,7 +61,7 @@ public class JpaToscaEventFilterTest {
                         .hasMessage("node is marked @NonNull but is null");
 
         assertThatThrownBy(() -> new JpaToscaEventFilter((JpaToscaEventFilter) null))
-                        .hasMessage("copyConcept is marked @NonNull but is null");
+                        .isInstanceOf(NullPointerException.class);
 
         PfConceptKey efParentKey = new PfConceptKey("tParentKey", VERSION_001);
         PfReferenceKey efKey = new PfReferenceKey(efParentKey, "trigger0");
@@ -78,8 +78,7 @@ public class JpaToscaEventFilterTest {
         assertEquals(tef, tdtClone0);
         assertEquals(0, tef.compareTo(tdtClone0));
 
-        JpaToscaEventFilter tdtClone1 = new JpaToscaEventFilter();
-        tef.copyTo(tdtClone1);
+        JpaToscaEventFilter tdtClone1 = new JpaToscaEventFilter(tef);
         assertEquals(tef, tdtClone1);
         assertEquals(0, tef.compareTo(tdtClone1));
 
@@ -100,8 +99,6 @@ public class JpaToscaEventFilterTest {
         otherDt.setCapability(A_CAPABILITY);
         assertEquals(0, tef.compareTo(otherDt));
 
-        assertThatThrownBy(() -> tef.copyTo(null)).hasMessage("target is marked @NonNull but is null");
-
         assertEquals(2, tef.getKeys().size());
         assertEquals(2, new JpaToscaEventFilter().getKeys().size());
 
index 40fbc05..74a4e7c 100644 (file)
@@ -73,8 +73,7 @@ public class JpaToscaModelTest {
         assertEquals(tm, tttClone0);
         assertEquals(0, tm.compareTo(tttClone0));
 
-        JpaToscaModel tttClone1 = new JpaToscaModel();
-        tm.copyTo(tttClone1);
+        JpaToscaModel tttClone1 = new JpaToscaModel(tm);
         assertEquals(tm, tttClone1);
         assertEquals(0, tm.compareTo(tttClone1));
 
@@ -91,7 +90,8 @@ public class JpaToscaModelTest {
         otherDt.setServiceTemplates(tsts);
         assertEquals(0, tm.compareTo(otherDt));
 
-        assertThatThrownBy(() -> tm.copyTo(null)).hasMessage("targetObject is marked @NonNull but is null");
+        assertThatThrownBy(() -> new JpaToscaModel((JpaToscaModel) null))
+                        .isInstanceOf(NullPointerException.class);
 
         assertEquals(2, tm.getKeys().size());
         assertEquals(2, new JpaToscaModel().getKeys().size());
index bb96178..73e5066 100644 (file)
@@ -76,9 +76,8 @@ public class JpaToscaPolicyTest {
             new JpaToscaPolicy(null, new PfConceptKey());
         }).hasMessage(KEY_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            new JpaToscaPolicy((JpaToscaPolicy) null);
-        }).hasMessage("copyConcept is marked @NonNull but is null");
+        assertThatThrownBy(() -> new JpaToscaPolicy((JpaToscaPolicy) null))
+                        .isInstanceOf(NullPointerException.class);
 
         PfConceptKey tpKey = new PfConceptKey("tdt", VERSION_001);
         PfConceptKey ptKey = new PfConceptKey("policyType", VERSION_001);
@@ -99,8 +98,7 @@ public class JpaToscaPolicyTest {
         assertEquals(tp, tdtClone0);
         assertEquals(0, tp.compareTo(tdtClone0));
 
-        JpaToscaPolicy tdtClone1 = new JpaToscaPolicy();
-        tp.copyTo(tdtClone1);
+        JpaToscaPolicy tdtClone1 = new JpaToscaPolicy(tp);
         assertEquals(tp, tdtClone1);
         assertEquals(0, tp.compareTo(tdtClone1));
 
@@ -121,10 +119,6 @@ public class JpaToscaPolicyTest {
         otherDt.setTargets(targets);
         assertEquals(0, tp.compareTo(otherDt));
 
-        assertThatThrownBy(() -> {
-            tp.copyTo(null);
-        }).hasMessage("target is marked @NonNull but is null");
-
         assertEquals(3, tp.getKeys().size());
         assertEquals(2, new JpaToscaPolicy().getKeys().size());
 
index eb94a5e..1f2a4e1 100644 (file)
@@ -58,7 +58,7 @@ public class JpaToscaPolicyTypeTest {
                         .hasMessage("key is marked @NonNull but is null");
 
         assertThatThrownBy(() -> new JpaToscaPolicyType((JpaToscaPolicyType) null))
-                        .hasMessage("copyConcept is marked @NonNull but is null");
+                        .isInstanceOf(NullPointerException.class);
 
         PfConceptKey ptKey = new PfConceptKey("tdt", VERSION_001);
         JpaToscaPolicyType tpt = new JpaToscaPolicyType(ptKey);
@@ -96,8 +96,7 @@ public class JpaToscaPolicyTypeTest {
         assertEquals(tpt, tdtClone0);
         assertEquals(0, tpt.compareTo(tdtClone0));
 
-        JpaToscaPolicyType tdtClone1 = new JpaToscaPolicyType();
-        tpt.copyTo(tdtClone1);
+        JpaToscaPolicyType tdtClone1 = new JpaToscaPolicyType(tpt);
         assertEquals(tpt, tdtClone1);
         assertEquals(0, tpt.compareTo(tdtClone1));
 
@@ -124,8 +123,6 @@ public class JpaToscaPolicyTypeTest {
         otherDt.setTriggers(triggers);
         assertEquals(0, tpt.compareTo(otherDt));
 
-        assertThatThrownBy(() -> tpt.copyTo(null)).hasMessage("target is marked @NonNull but is null");
-
         assertEquals(6, tpt.getKeys().size());
         assertEquals(1, new JpaToscaPolicyType().getKeys().size());
 
@@ -177,7 +174,7 @@ public class JpaToscaPolicyTypeTest {
                         .hasMessage("key is marked @NonNull but is null");
 
         assertThatThrownBy(() -> new JpaToscaEntityType<ToscaPolicy>((JpaToscaEntityType<ToscaPolicy>) null))
-                        .hasMessage("copyConcept is marked @NonNull but is null");
+                        .isInstanceOf(NullPointerException.class);
 
         JpaToscaEntityType<ToscaPolicy> tet = new JpaToscaEntityType<>(tpt.getKey());
         assertEquals(-1, tet.compareTo(null));
index 70018b6..2da2090 100644 (file)
@@ -63,9 +63,6 @@ public class JpaToscaPropertyTest {
         assertThatThrownBy(() -> new JpaToscaProperty(new PfReferenceKey(), null))
                         .hasMessage("type is marked @NonNull but is null");
 
-        assertThatThrownBy(() -> new JpaToscaProperty((JpaToscaProperty) null))
-                        .hasMessage("copyConcept is marked @NonNull but is null");
-
         PfConceptKey pparentKey = new PfConceptKey("tParentKey", VERSION_001);
         PfReferenceKey pkey = new PfReferenceKey(pparentKey, "trigger0");
         PfConceptKey ptypeKey = new PfConceptKey("TTypeKey", VERSION_001);
@@ -95,8 +92,7 @@ public class JpaToscaPropertyTest {
         assertEquals(tp, tdtClone0);
         assertEquals(0, tp.compareTo(tdtClone0));
 
-        JpaToscaProperty tdtClone1 = new JpaToscaProperty();
-        tp.copyTo(tdtClone1);
+        JpaToscaProperty tdtClone1 = new JpaToscaProperty(tp);
         assertEquals(tp, tdtClone1);
         assertEquals(0, tp.compareTo(tdtClone1));
 
@@ -136,7 +132,8 @@ public class JpaToscaPropertyTest {
         otherDt.setStatus(ToscaProperty.Status.SUPPORTED);
         assertEquals(0, tp.compareTo(otherDt));
 
-        assertThatThrownBy(() -> tp.copyTo(null)).hasMessage("target is marked @NonNull but is null");
+        assertThatThrownBy(() -> new JpaToscaProperty((JpaToscaProperty) null))
+                        .isInstanceOf(NullPointerException.class);
 
         assertEquals(3, tp.getKeys().size());
         assertEquals(2, new JpaToscaProperty().getKeys().size());
index df72ce5..911f4a1 100644 (file)
@@ -61,7 +61,7 @@ public class JpaToscaServiceTemplateTest {
                         .hasMessage("toscaDefinitionsVersion is marked @NonNull but is null");
 
         assertThatThrownBy(() -> new JpaToscaServiceTemplate((JpaToscaServiceTemplate) null))
-                        .hasMessage("copyConcept is marked @NonNull but is null");
+                        .isInstanceOf(NullPointerException.class);
 
         PfConceptKey tstKey = new PfConceptKey("tst", VERSION_001);
         JpaToscaServiceTemplate tst = new JpaToscaServiceTemplate(tstKey, "Tosca Version");
@@ -93,8 +93,7 @@ public class JpaToscaServiceTemplateTest {
         assertEquals(tst, tttClone0);
         assertEquals(0, tst.compareTo(tttClone0));
 
-        JpaToscaServiceTemplate tttClone1 = new JpaToscaServiceTemplate();
-        tst.copyTo(tttClone1);
+        JpaToscaServiceTemplate tttClone1 = new JpaToscaServiceTemplate(tst);
         assertEquals(tst, tttClone1);
         assertEquals(0, tst.compareTo(tttClone1));
 
@@ -117,8 +116,6 @@ public class JpaToscaServiceTemplateTest {
         otherDt.setTopologyTemplate(ttt);
         assertEquals(0, tst.compareTo(otherDt));
 
-        assertThatThrownBy(() -> tst.copyTo(null)).hasMessage("target is marked @NonNull but is null");
-
         assertEquals(6, tst.getKeys().size());
         assertEquals(1, new JpaToscaServiceTemplate().getKeys().size());
 
index e77f120..49cf18e 100644 (file)
@@ -68,8 +68,8 @@ public class JpaToscaTimeIntervalTest {
         assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), new Date(), null))
                         .hasMessage("endTime is marked @NonNull but is null");
 
-        assertThatThrownBy(() -> new JpaToscaTimeInterval((JpaToscaTimeInterval) null))
-                        .hasMessage("copyConcept is marked @NonNull but is null");
+        assertThatThrownBy(() -> new JpaToscaServiceTemplate((JpaToscaServiceTemplate) null))
+                        .isInstanceOf(NullPointerException.class);
 
         PfConceptKey ttiParentKey = new PfConceptKey("tParentKey", "0.0.1");
         PfReferenceKey ttiKey = new PfReferenceKey(ttiParentKey, "trigger0");
@@ -81,8 +81,7 @@ public class JpaToscaTimeIntervalTest {
         assertEquals(tti, tdtClone0);
         assertEquals(0, tti.compareTo(tdtClone0));
 
-        JpaToscaTimeInterval tdtClone1 = new JpaToscaTimeInterval();
-        tti.copyTo(tdtClone1);
+        JpaToscaTimeInterval tdtClone1 = new JpaToscaTimeInterval(tti);
         assertEquals(tti, tdtClone1);
         assertEquals(0, tti.compareTo(tdtClone1));
 
@@ -101,8 +100,6 @@ public class JpaToscaTimeIntervalTest {
         otherDt.setEndTime(endTime);
         assertEquals(0, tti.compareTo(otherDt));
 
-        assertThatThrownBy(() -> tti.copyTo(null)).hasMessage("target is marked @NonNull but is null");
-
         assertEquals(1, tti.getKeys().size());
         assertEquals(1, new JpaToscaTimeInterval().getKeys().size());
 
index 7712a64..94525f0 100644 (file)
@@ -56,7 +56,7 @@ public class JpaToscaTopologyTemplateTest {
                         .hasMessage("key is marked @NonNull but is null");
 
         assertThatThrownBy(() -> new JpaToscaTopologyTemplate((JpaToscaTopologyTemplate) null))
-                        .hasMessage("copyConcept is marked @NonNull but is null");
+                        .isInstanceOf(NullPointerException.class);
 
         PfReferenceKey tttKey = new PfReferenceKey("tst", VERSION_001, "ttt");
         JpaToscaTopologyTemplate ttt = new JpaToscaTopologyTemplate(tttKey);
@@ -78,8 +78,7 @@ public class JpaToscaTopologyTemplateTest {
         assertEquals(ttt, tttClone0);
         assertEquals(0, ttt.compareTo(tttClone0));
 
-        JpaToscaTopologyTemplate tttClone1 = new JpaToscaTopologyTemplate();
-        ttt.copyTo(tttClone1);
+        JpaToscaTopologyTemplate tttClone1 = new JpaToscaTopologyTemplate(ttt);
         assertEquals(ttt, tttClone1);
         assertEquals(0, ttt.compareTo(tttClone1));
 
@@ -98,7 +97,8 @@ public class JpaToscaTopologyTemplateTest {
         otherDt.setPolicies(policies);
         assertEquals(0, ttt.compareTo(otherDt));
 
-        assertThatThrownBy(() -> ttt.copyTo(null)).hasMessage("target is marked @NonNull but is null");
+        assertThatThrownBy(() -> new JpaToscaTopologyTemplate((JpaToscaTopologyTemplate) null))
+                        .isInstanceOf(NullPointerException.class);
 
         assertEquals(4, ttt.getKeys().size());
         assertEquals(1, new JpaToscaTopologyTemplate().getKeys().size());
index 97c1b6f..0baf1e5 100644 (file)
@@ -75,7 +75,7 @@ public class JpaToscaTriggerTest {
                         .hasMessage("eventType is marked @NonNull but is null");
 
         assertThatThrownBy(() -> new JpaToscaTrigger((JpaToscaTrigger) null))
-                        .hasMessage("copyConcept is marked @NonNull but is null");
+                        .isInstanceOf(NullPointerException.class);
 
         PfConceptKey tparentKey = new PfConceptKey("tParentKey", VERSION_001);
         PfReferenceKey tkey = new PfReferenceKey(tparentKey, "trigger0");
@@ -108,8 +108,7 @@ public class JpaToscaTriggerTest {
         assertEquals(tdt, tdtClone0);
         assertEquals(0, tdt.compareTo(tdtClone0));
 
-        JpaToscaTrigger tdtClone1 = new JpaToscaTrigger();
-        tdt.copyTo(tdtClone1);
+        JpaToscaTrigger tdtClone1 = new JpaToscaTrigger(tdt);
         assertEquals(tdt, tdtClone1);
         assertEquals(0, tdt.compareTo(tdtClone1));
 
@@ -147,8 +146,6 @@ public class JpaToscaTriggerTest {
         otherDt.setEvaluations(0);
         assertEquals(0, tdt.compareTo(otherDt));
 
-        assertThatThrownBy(() -> tdt.copyTo(null)).hasMessage("target is marked @NonNull but is null");
-
         assertEquals(4, tdt.getKeys().size());
         assertEquals(1, new JpaToscaTrigger().getKeys().size());