Merge "move actors code in drools-applications to policy/models"
authorPamela Dragosh <pdragosh@research.att.com>
Tue, 2 Apr 2019 12:44:26 +0000 (12:44 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 2 Apr 2019 12:44:26 +0000 (12:44 +0000)
84 files changed:
models-base/src/main/java/org/onap/policy/models/base/PfAuthorative.java
models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java [moved from models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/mapping/package-info.java with 66% similarity]
models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyAuthorativeConcept.java [new file with mode: 0644]
models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConcept.java [new file with mode: 0644]
models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConceptContainer.java [new file with mode: 0644]
models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java
models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptContainer.java
models-pap/pom.xml
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStateChange.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdent.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdentOptVersion.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyTypeIdent.java
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java [new file with mode: 0644]
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java [new file with mode: 0644]
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdent.java
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdentOptVersion.java
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyTypeIdent.java
models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConstraint.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaDataType.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java [new file with mode: 0644]
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntrySchema.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaProperty.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapper.java [deleted file]
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java [new file with mode: 0644]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKey.java [deleted file]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalString.java [deleted file]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintOperation.java [new file with mode: 0644]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintValidValues.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/JpaToscaEntrySchema.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/JpaToscaServiceTemplates.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/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypeJsonAdapter.java [deleted file]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypesJsonAdapter.java [deleted file]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java [deleted file]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java [deleted file]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyTypeJsonAdapter.java [deleted file]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyTypesJsonAdapter.java [deleted file]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPropertiesJsonAdapter.java [deleted file]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateJsonAdapter.java [deleted file]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java [deleted file]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaTopologyTemplateJsonAdapter.java [deleted file]
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/mapping/ToscaServiceTemplateMappingTest.java [moved from models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapperTest.java with 68% similarity]
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKeyTest.java [deleted file]
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalStringTest.java [deleted file]
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.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/JpaToscaEntrySchemaTest.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/JpaToscaTriggerTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java

index fd35d20..b0610e4 100644 (file)
@@ -37,7 +37,8 @@ public interface PfAuthorative<T> {
 
     /**
      * Set an instance of the persist concept to the equivalent values as the other concept.
+     *
+     * @param authorativeConcept the authorative concept
      */
-    public void fromAuthorative(final T authorativeClass);
-
+    public void fromAuthorative(final T authorativeConcept);
 }
index 4609461..e197e13 100644 (file)
@@ -20,6 +20,9 @@
 
 package org.onap.policy.models.base;
 
+import java.lang.reflect.ParameterizedType;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -41,25 +44,26 @@ import lombok.NonNull;
 import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 
+// @formatter:off
 /**
- * This class is a concept container and holds a map of concepts. The {@link PfConceptContainer}
- * class implements the helper methods of the {@link PfConceptGetter} interface to allow
- * {@link PfConceptContainer} instances to be retrieved by calling methods directly on this class
- * without referencing the contained map.
+ * This class is a concept container and holds a map of concepts. The {@link PfConceptContainer} class implements the
+ * helper methods of the {@link PfConceptGetter} interface to allow {@link PfConceptContainer} instances to be retrieved
+ * by calling methods directly on this class without referencing the contained map.
  *
- * <p>Validation checks that the container key is not null. An error is issued if no concepts are
- * defined in the container. Each concept entry is checked to ensure that its key and value are not
- * null and that the key matches the key in the map value. Each concept entry is then validated
- * individually.
+ * <p>Validation checks that a container key is not null. An error is issued if no concepts are defined in a container.
+ * Each concept entry is checked to ensure that its key and value are not null and that the key matches the key in the
+ * map value. Each concept entry is then validated individually.
  *
  * @param C the concept being contained
  */
+//@formatter:on
 @Entity
 @Table(name = "PfConceptContainer")
 @Data
 @EqualsAndHashCode(callSuper = false)
 
-public class PfConceptContainer<C extends PfConcept> extends PfConcept implements PfConceptGetter<C> {
+public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> extends PfConcept
+        implements PfConceptGetter<C>, PfAuthorative<List<Map<String, A>>> {
     private static final long serialVersionUID = -324211738823208318L;
 
     @EmbeddedId
@@ -69,16 +73,16 @@ public class PfConceptContainer<C extends PfConcept> extends PfConcept implement
     private Map<PfConceptKey, C> conceptMap;
 
     /**
-     * The Default Constructor creates a {@link PfConceptContainer} object with a null artifact key
-     * and creates an empty concept map.
+     * The Default Constructor creates a {@link PfConceptContainer} object with a null artifact key and creates an empty
+     * concept map.
      */
     public PfConceptContainer() {
         this(new PfConceptKey());
     }
 
     /**
-     * The Key Constructor creates a {@link PfConceptContainer} object with the given artifact key
-     * and creates an empty concept map.
+     * The Key Constructor creates a {@link PfConceptContainer} object with the given artifact key and creates an empty
+     * concept map.
      *
      * @param key the concept key
      */
@@ -104,7 +108,7 @@ public class PfConceptContainer<C extends PfConcept> extends PfConcept implement
      *
      * @param copyConcept the concept to copy from
      */
-    public PfConceptContainer(@NonNull final PfConceptContainer<C> copyConcept) {
+    public PfConceptContainer(@NonNull final PfConceptContainer<C, A> copyConcept) {
         super(copyConcept);
     }
 
@@ -119,6 +123,65 @@ public class PfConceptContainer<C extends PfConcept> extends PfConcept implement
         return keyList;
     }
 
+    @Override
+    public List<Map<String, A>> toAuthorative() {
+        Map<String, A> toscaPolicyMap = new LinkedHashMap<>();
+
+        for (Entry<PfConceptKey, C> conceptEntry : getConceptMap().entrySet()) {
+            @SuppressWarnings("unchecked")
+            PfAuthorative<A> authoritiveImpl = (PfAuthorative<A>) conceptEntry.getValue();
+            toscaPolicyMap.put(conceptEntry.getKey().getName(), authoritiveImpl.toAuthorative());
+        }
+
+        List<Map<String, A>> toscaPolicyMapList = new ArrayList<>();
+        toscaPolicyMapList.add(toscaPolicyMap);
+
+        return toscaPolicyMapList;
+    }
+
+    @Override
+    public void fromAuthorative(List<Map<String, A>> authorativeList) {
+        // Clear any existing map entries
+        conceptMap.clear();
+
+        // Concepts are in lists of maps
+        for (Map<String, A> incomingConceptMap : authorativeList) {
+            // Add the map entries one by one
+            for (Entry<String, A> incomingConceptEntry : incomingConceptMap.entrySet()) {
+                C jpaConcept = getConceptNewInstance();
+
+                // This cast allows us to call the fromAuthorative method
+                @SuppressWarnings("unchecked")
+                PfAuthorative<A> authoritiveImpl = (PfAuthorative<A>) jpaConcept;
+
+                if (incomingConceptEntry.getValue().getName() == null) {
+                    incomingConceptEntry.getValue().setName(incomingConceptEntry.getKey());
+                }
+
+                // Set the key name and the rest of the values on the concept
+                authoritiveImpl.fromAuthorative(incomingConceptEntry.getValue());
+
+                // This cast gets the key of the concept
+                PfConceptKey conceptKey = (PfConceptKey) jpaConcept.getKey();
+
+                // Set the concept key of the concept
+                conceptKey.setName(incomingConceptEntry.getValue().getName());
+
+                if (incomingConceptEntry.getValue().getVersion() != null) {
+                    conceptKey.setVersion(incomingConceptEntry.getValue().getVersion());
+                }
+
+                // After all that, save the map entry
+                conceptMap.put(conceptKey, jpaConcept);
+            }
+        }
+
+        if (conceptMap.isEmpty()) {
+            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+                    "An incoming list of concepts must have at least one entry");
+        }
+    }
+
     @Override
     public void clean() {
         key.clean();
@@ -162,17 +225,19 @@ public class PfConceptContainer<C extends PfConcept> extends PfConcept implement
             if (conceptEntry.getKey().equals(PfConceptKey.getNullKey())) {
                 result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
                         "key on concept entry " + conceptEntry.getKey() + " may not be the null key"));
-            } else if (conceptEntry.getValue() == null) {
-                result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
-                        "value on concept entry " + conceptEntry.getKey() + " may not be null"));
-            } else if (!conceptEntry.getKey().equals(conceptEntry.getValue().getKey())) {
-                result.addValidationMessage(new PfValidationMessage(key, this.getClass(),
-                        ValidationResult.INVALID, "key on concept entry key " + conceptEntry.getKey()
-                        + " does not equal concept value key " + conceptEntry.getValue().getKey()));
-                result = conceptEntry.getValue().validate(result);
-            } else {
-                result = conceptEntry.getValue().validate(result);
-            }
+            } else
+                if (conceptEntry.getValue() == null) {
+                    result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+                            "value on concept entry " + conceptEntry.getKey() + " may not be null"));
+                } else
+                    if (!conceptEntry.getKey().equals(conceptEntry.getValue().getKey())) {
+                        result.addValidationMessage(new PfValidationMessage(key, this.getClass(),
+                                ValidationResult.INVALID, "key on concept entry key " + conceptEntry.getKey()
+                                        + " does not equal concept value key " + conceptEntry.getValue().getKey()));
+                        result = conceptEntry.getValue().validate(result);
+                    } else {
+                        result = conceptEntry.getValue().validate(result);
+                    }
         }
         return result;
     }
@@ -190,7 +255,7 @@ public class PfConceptContainer<C extends PfConcept> extends PfConcept implement
         }
 
         @SuppressWarnings("unchecked")
-        final PfConceptContainer<C> other = (PfConceptContainer<C>) otherConcept;
+        final PfConceptContainer<C, A> other = (PfConceptContainer<C, A>) otherConcept;
         int retVal = key.compareTo(other.key);
         if (retVal != 0) {
             return retVal;
@@ -208,12 +273,13 @@ public class PfConceptContainer<C extends PfConcept> extends PfConcept implement
         Assertions.instanceOf(target, PfConceptContainer.class);
 
         @SuppressWarnings("unchecked")
-        final PfConceptContainer<C> copy = (PfConceptContainer<C>) target;
+        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()) {
-            newConceptMap.put(new PfConceptKey(conceptMapEntry.getKey()),
-                    new ConceptCloner().cloneConcept(conceptMapEntry.getValue()));
+            C newC = getConceptNewInstance();
+            conceptMapEntry.getValue().copyTo(newC);
+            newConceptMap.put(new PfConceptKey(conceptMapEntry.getKey()), newC);
         }
         copy.setConceptMap(newConceptMap);
 
@@ -248,21 +314,19 @@ public class PfConceptContainer<C extends PfConcept> extends PfConcept implement
     }
 
     /**
-     * Private inner class that returns a clone of a concept by calling the copy constructor on the
-     * original class.
+     * Get a new empty instance of a concept for this concept map.
+     *
+     * @return the new instance
      */
-    private class ConceptCloner {
-        @SuppressWarnings("unchecked")
-        public C cloneConcept(final C originalConcept) {
-            try {
-                C clonedConcept = (C) originalConcept.getClass().newInstance();
-                originalConcept.copyTo(clonedConcept);
-                return clonedConcept;
-            } catch (Exception ex) {
-                throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
-                        "Failed to create a clone of class \"" + originalConcept.getClass().getCanonicalName() + "\"",
-                        ex);
-            }
+    @SuppressWarnings("unchecked")
+    private C getConceptNewInstance() {
+        try {
+            String conceptClassName =
+                    ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0].getTypeName();
+            return (C) Class.forName(conceptClassName).newInstance();
+        } catch (Exception ex) {
+            throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
+                    "failed to instantiate instance of container concept class", ex);
         }
     }
 }
@@ -1,8 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * ============LICENSE_END=========================================================
  */
 
+package org.onap.policy.models.base;
+
 /**
- * This package includes all the mappers used to transform plain TOSCA POJOs into internal representation
- * of TOSCA concepts with JPA annotations added.
- */
-/**
- * @author Chenfei Gao (cgao@research.att.com)
+ * An interface that forces a POJO to have getName() and getVersion() methods.
  *
+ * @author Liam Fallon (liam.fallon@est.tech)
  */
-package org.onap.policy.models.tosca.authorative.mapping;
\ No newline at end of file
+public interface PfNameVersion {
+    public String getName();
+
+    public void setName(final String name);
+
+    public String getVersion();
+
+    public void setVersion(final String version);
+}
index 0ed04c4..3ae7c4c 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.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 
 import org.junit.Test;
+import org.onap.policy.models.base.testconcepts.DummyAuthorativeConcept;
+import org.onap.policy.models.base.testconcepts.DummyBadPfConceptContainer;
 import org.onap.policy.models.base.testconcepts.DummyPfConcept;
 import org.onap.policy.models.base.testconcepts.DummyPfConceptContainer;
 import org.onap.policy.models.base.testconcepts.DummyPfConceptSub;
@@ -44,7 +49,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfConceptSub;
 public class PfConceptContainerTest {
 
     @Test
-    public void test() {
+    public void testConceptContainer() {
         DummyPfConceptContainer container = new DummyPfConceptContainer();
         assertNotNull(container);
 
@@ -179,16 +184,38 @@ public class PfConceptContainerTest {
         assertEquals(conceptKey, returnSet.iterator().next().getKey());
 
         container.getConceptMap().put(conceptKey, new DummyPfConceptSub(conceptKey));
+    }
 
-        DummyPfConceptContainer exceptionOnCopyContainer = new DummyPfConceptContainer();
-        try {
-            container.copyTo(exceptionOnCopyContainer);
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals(
-                    "Failed to create a clone of class \"org.onap.policy.models.base.testconcepts.DummyPfConceptSub\"",
-                    exc.getMessage());
-        }
+    @Test
+    public void testAuthorative() {
+        Map<String, DummyAuthorativeConcept> dacMap = new LinkedHashMap<>();
+        dacMap.put("name0", new DummyAuthorativeConcept("name0", "1.2.3", "Hello"));
+        dacMap.put("name1", new DummyAuthorativeConcept("name1", "1.2.3", "Hi"));
+        dacMap.put("name2", new DummyAuthorativeConcept("name2", "1.2.3", "Howdy"));
+
+        List<Map<String, DummyAuthorativeConcept>> authorativeList = new ArrayList<>();
+        authorativeList.add(dacMap);
+
+        DummyPfConceptContainer container = new DummyPfConceptContainer();
+        container.fromAuthorative(authorativeList);
+
+        assertEquals("Hello", container.getConceptMap().get(new PfConceptKey("name0:1.2.3")).getDescription());
+        assertEquals("Hi",    container.getConceptMap().get(new PfConceptKey("name1:1.2.3")).getDescription());
+        assertEquals("Howdy", container.getConceptMap().get(new PfConceptKey("name2:1.2.3")).getDescription());
+
+        List<Map<String, DummyAuthorativeConcept>> outMapList = container.toAuthorative();
+
+        assertEquals(dacMap, outMapList.get(0));
+
+        DummyBadPfConceptContainer badContainer = new DummyBadPfConceptContainer();
+        assertThatThrownBy(() -> {
+            badContainer.fromAuthorative(authorativeList);
+        }).hasMessage("failed to instantiate instance of container concept class");
+
+        authorativeList.clear();
+        assertThatThrownBy(() -> {
+            container.fromAuthorative(authorativeList);
+        }).hasMessage("An incoming list of concepts must have at least one entry");
     }
 
     @Test(expected = NullPointerException.class)
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyAuthorativeConcept.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyAuthorativeConcept.java
new file mode 100644 (file)
index 0000000..02ff750
--- /dev/null
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.base.testconcepts;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import org.onap.policy.models.base.PfNameVersion;
+
+/**
+ * Dummy authorative concept.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Data
+@NoArgsConstructor
+public class DummyAuthorativeConcept implements PfNameVersion {
+    private String name;
+    private String version;
+    private String description;
+
+    /**
+     * Constructor.
+     *
+     * @param name the name
+     * @param version the version
+     * @param description the description
+     */
+    public DummyAuthorativeConcept(final String name, final String version, final String description) {
+        this.name = name;
+        this.version = version;
+        this.description = description;
+    }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConcept.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConcept.java
new file mode 100644 (file)
index 0000000..05fd599
--- /dev/null
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.base.testconcepts;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfConceptKey;
+
+/**
+ * Bad dummy concept throws exception on default constructor.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class DummyBadPfConcept extends DummyPfConcept {
+    private static final long serialVersionUID = 1L;
+
+    public DummyBadPfConcept() {
+        throw new NumberFormatException();
+    }
+
+    /**
+     * The Key Constructor creates a {@link DummyPfConcept} object with the given concept key.
+     *
+     * @param key the key
+     */
+    public DummyBadPfConcept(@NonNull final PfConceptKey key) {
+        throw new NumberFormatException();
+    }
+
+    /**
+     * Copy constructor.
+     *
+     * @param copyConcept the concept to copy from
+     */
+    public DummyBadPfConcept(final DummyBadPfConcept copyConcept) {
+        throw new NumberFormatException();
+    }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConceptContainer.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConceptContainer.java
new file mode 100644 (file)
index 0000000..c328a01
--- /dev/null
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.base.testconcepts;
+
+import java.util.Map;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfConceptContainer;
+import org.onap.policy.models.base.PfConceptKey;
+
+/**
+ * Dummy container for PF concepts.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class DummyBadPfConceptContainer extends PfConceptContainer<DummyBadPfConcept, DummyAuthorativeConcept> {
+    private static final long serialVersionUID = -3018432331484294280L;
+
+
+    /**
+     * The Default Constructor creates a {@link DummyBadPfConceptContainer} object with a null artifact key
+     * and creates an empty concept map.
+     */
+    public DummyBadPfConceptContainer() {
+        super();
+    }
+
+    /**
+     * The Key Constructor creates a {@link DummyBadPfConceptContainer} object with the given artifact key and
+     * creates an empty concept map.
+     *
+     * @param key the concept key
+     */
+    public DummyBadPfConceptContainer(@NonNull final PfConceptKey key) {
+        super(key);
+    }
+
+    /**
+     * This Constructor creates an concept container with all of its fields defined.
+     *
+     * @param key the concept container key
+     * @param conceptMap the concepts to be stored in the concept container
+     */
+    public DummyBadPfConceptContainer(@NonNull final PfConceptKey key,
+            @NonNull final Map<PfConceptKey, DummyBadPfConcept> conceptMap) {
+        super(key, conceptMap);
+    }
+
+    /**
+     * Copy constructor.
+     *
+     * @param copyConcept the concept to copy from
+     */
+    public DummyBadPfConceptContainer(@NonNull final DummyBadPfConceptContainer copyConcept) {
+        super(copyConcept);
+    }
+
+}
index 9fb6b57..5e74fb2 100644 (file)
@@ -30,6 +30,7 @@ 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;
 import org.onap.policy.models.base.PfKey;
@@ -39,13 +40,31 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 
 @Data
 @EqualsAndHashCode(callSuper = false)
-public class DummyPfConcept extends PfConcept {
+public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuthorativeConcept> {
     private static final long serialVersionUID = 1L;
     @EmbeddedId
     private PfConceptKey key;
 
     private String description;
 
+
+    @Override
+    public DummyAuthorativeConcept toAuthorative() {
+        DummyAuthorativeConcept dac = new DummyAuthorativeConcept();
+        dac.setName(key.getName());
+        dac.setVersion(key.getVersion());
+        dac.setDescription(description);
+
+        return dac;
+    }
+
+    @Override
+    public void fromAuthorative(DummyAuthorativeConcept dac) {
+        key.setName(dac.getName());
+        key.setVersion(dac.getVersion());
+        description = dac.getDescription();
+    }
+
     /**
      * The Default Constructor creates a {@link DummyPfConcept} object with a null key.
      */
index ac72ef8..45de69e 100644 (file)
@@ -32,7 +32,7 @@ import org.onap.policy.models.base.PfConceptKey;
  *
  * @author Liam Fallon (liam.fallon@est.tech)
  */
-public class DummyPfConceptContainer extends PfConceptContainer<DummyPfConcept> {
+public class DummyPfConceptContainer extends PfConceptContainer<DummyPfConcept, DummyAuthorativeConcept> {
     private static final long serialVersionUID = -3018432331484294280L;
 
 
index edb8ee7..78f6df1 100644 (file)
@@ -34,7 +34,7 @@
     <dependencies>
         <dependency>
             <groupId>org.onap.policy.models</groupId>
-            <artifactId>models-pdp</artifactId>
+            <artifactId>policy-models-pdp</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
index bca162e..d8f938b 100644 (file)
@@ -28,7 +28,8 @@ import org.onap.policy.models.pdp.enums.PdpMessageType;
 import org.onap.policy.models.pdp.enums.PdpState;
 
 /**
- * Class to represent the PDP_STATE_CHANGE message that PAP will send to either PDPGroup/Subgroup or a PDP.
+ * Class to represent the PDP_STATE_CHANGE message that PAP will send to either
+ * PDPGroup/Subgroup or a PDP.
  *
  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
  */
@@ -49,4 +50,18 @@ public class PdpStateChange extends PdpMessage {
     public PdpStateChange() {
         super(PdpMessageType.PDP_STATE_CHANGE);
     }
+
+    /**
+     * Constructs the object, making a deep copy.
+     *
+     * @param source source from which to copy
+     */
+    public PdpStateChange(PdpStateChange source) {
+        super(PdpMessageType.PDP_STATE_CHANGE);
+
+        this.name = source.name;
+        this.state = source.state;
+        this.pdpGroup = source.pdpGroup;
+        this.pdpSubgroup = source.pdpSubgroup;
+    }
 }
index 5c99a56..c8c8783 100644 (file)
@@ -22,7 +22,7 @@
 package org.onap.policy.models.pdp.concepts;
 
 import java.util.List;
-
+import java.util.stream.Collectors;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.ToString;
@@ -53,4 +53,21 @@ public class PdpUpdate extends PdpMessage {
     public PdpUpdate() {
         super(PdpMessageType.PDP_UPDATE);
     }
+
+    /**
+     * Constructs the object, making a deep copy.
+     *
+     * @param source source from which to copy
+     */
+    public PdpUpdate(PdpUpdate source) {
+        super(PdpMessageType.PDP_UPDATE);
+
+        this.name = source.name;
+        this.pdpType = source.pdpType;
+        this.description = source.description;
+        this.pdpGroup = source.pdpGroup;
+        this.pdpSubgroup = source.pdpSubgroup;
+        this.policies = (source.policies == null ? null
+                        : source.policies.stream().map(ToscaPolicy::new).collect(Collectors.toList()));
+    }
 }
index 6d6b6fe..a62d900 100644 (file)
 
 package org.onap.policy.models.pdp.concepts;
 
+import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.Validated;
 
 /**
  * Identifies a policy. Both the name and version must be non-null.
  */
-@NonNull
+@Data
 @NoArgsConstructor
-public class PolicyIdent extends PfConceptKey {
-    private static final long serialVersionUID = 1L;
-    private static final Validated validator = new Validated();
+public class PolicyIdent {
 
-    public PolicyIdent(String name, String version) {
-        super(name, version);
-    }
+    @NonNull
+    private String name;
 
-    public PolicyIdent(PolicyIdent source) {
-        super(source);
+    @NonNull
+    private String version;
+
+
+    public PolicyIdent(@NonNull String name, @NonNull String version) {
+        this.name = name;
+        this.version = version;
     }
 
-    @Override
-    public PfValidationResult validate(PfValidationResult result) {
-        return super.validate(validator.validateNotNull(this, result));
+    public PolicyIdent(PolicyIdent source) {
+        this.name = source.name;
+        this.version = source.version;
     }
 }
index a68a271..f86a3c4 100644 (file)
 
 package org.onap.policy.models.pdp.concepts;
 
+import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.Validated;
 
 /**
  * Policy identifier with an optional version; only the "name" is required.
  */
-@NonNull
+@Data
 @NoArgsConstructor
-public class PolicyIdentOptVersion extends PfConceptKey {
-    private static final long serialVersionUID = 1L;
-    private static final Validated validator = new Validated();
+public class PolicyIdentOptVersion {
 
+    @NonNull
+    private String name;
+
+    private String version;
+
+
+    public PolicyIdentOptVersion(@NonNull String name, String version) {
+        this.name = name;
+        this.version = version;
+    }
 
     public PolicyIdentOptVersion(PolicyIdentOptVersion source) {
-        super(source);
+        this.name = source.name;
+        this.version = source.version;
     }
 
     /**
-     * Validates the object.
+     * Determines if the version is null/missing.
      *
-     * @param resultIn where to place any errors
-     * @return a validation result
+     * @return {@code true} if the version is null/missing, {@code false}
      */
-    public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
-        PfValidationResult result = resultIn;
-
-        String name = getName();
-        if (PfConceptKey.NULL_KEY_NAME.equals(name)) {
-            validator.addError(this, "name", result, "null");
-        }
-        result = validator.validateText(this, "name", name, PfKey.NAME_REGEXP, result);
-
-        return validator.validateText(this, "version", getVersion(), PfKey.VERSION_REGEXP, result);
+    public boolean isNullVersion() {
+        return (version == null);
     }
 }
index ef67de8..44ca168 100644 (file)
 
 package org.onap.policy.models.pdp.concepts;
 
+import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.Validated;
 
 /**
  * Identifies a policy type. Both the name and version must be non-null.
  */
-@NonNull
+@Data
 @NoArgsConstructor
-public class PolicyTypeIdent extends PfConceptKey {
-    private static final long serialVersionUID = 1L;
-    private static final Validated validator = new Validated();
+public class PolicyTypeIdent {
 
-    public PolicyTypeIdent(String name, String version) {
-        super(name, version);
-    }
+    @NonNull
+    private String name;
 
-    public PolicyTypeIdent(PolicyTypeIdent source) {
-        super(source);
+    @NonNull
+    private String version;
+
+
+    public PolicyTypeIdent(@NonNull String name, @NonNull String version) {
+        this.name = name;
+        this.version = version;
     }
 
-    @Override
-    public PfValidationResult validate(PfValidationResult result) {
-        return super.validate(validator.validateNotNull(this, result));
+    public PolicyTypeIdent(PolicyTypeIdent source) {
+        this.name = source.name;
+        this.version = source.version;
     }
 }
index fe0576d..6af2d21 100644 (file)
 
 package org.onap.policy.models.pdp.persistence.provider;
 
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
 import lombok.NonNull;
 
+import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.dao.PfDao;
+import org.onap.policy.models.pdp.concepts.PdpGroup;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 
 /**
  * This class provides the provision of information on PAP concepts in the database to callers.
@@ -36,15 +46,41 @@ public class PdpProvider {
      * Get PDP groups.
      *
      * @param dao the DAO to use to access the database
-     * @param pdpGroupFilter a filter for the get
+     * @param name the name of the policy to get, null to get all PDP groups
+     * @param version the version of the policy to get, null to get all versions of a PDP group
      * @return the PDP groups found
      * @throws PfModelException on errors getting PDP groups
      */
-    public PdpGroups getPdpGroups(@NonNull final PfDao dao, @NonNull final String pdpGroupFilter)
+    public PdpGroups getPdpGroups(@NonNull final PfDao dao, final String name, final String version)
             throws PfModelException {
         return new PdpGroups();
     }
 
+    /**
+     * Get latest PDP Groups.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the PDP group to get, null to get all PDP groups
+     * @return the PDP groups found
+     * @throws PfModelException on errors getting policies
+     */
+    public PdpGroups getLatestPdpGroups(@NonNull final PfDao dao, final String name) throws PfModelException {
+        return new PdpGroups();
+    }
+
+    /**
+     * Get a filtered list of PDP groups.
+     *
+     * @param dao the DAO to use to access the database
+     * @param pdpType The PDP type filter for the returned PDP groups
+     * @param supportedPolicyTypes a list of policy type name/version pairs that the PDP groups must support.
+     * @return the PDP groups found
+     */
+    public PdpGroups getFilteredPdpGroups(@NonNull final PfDao dao, @NonNull final String pdpType,
+            @NonNull final List<Pair<String, String>> supportedPolicyTypes) {
+        return new PdpGroups();
+    }
+
     /**
      * Creates PDP groups.
      *
@@ -71,16 +107,76 @@ public class PdpProvider {
         return new PdpGroups();
     }
 
+
+    /**
+     * Update a PDP subgroup.
+     *
+     * @param dao the DAO to use to access the database
+     * @param pdpGroupName the name of the PDP group of the PDP subgroup
+     * @param pdpGroupVersion the version of the PDP group of the PDP subgroup
+     * @param pdpSubGroup the PDP subgroup to be updated
+     * @throws PfModelException on errors updating PDP subgroups
+     */
+    public void updatePdpSubGroup(@NonNull final PfDao dao, @NonNull final String pdpGroupName,
+            @NonNull final String pdpGroupVersion, @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException {
+        // Not implemented yet
+    }
+
     /**
-     * Delete PDP groups.
+     * Delete a PDP group.
      *
      * @param dao the DAO to use to access the database
-     * @param pdpGroupFilter a filter for the get
-     * @return the PDP groups deleted
+     * @param name the name of the policy to get, null to get all PDP groups
+     * @param version the version of the policy to get, null to get all versions of a PDP group
+     * @return the PDP group deleted
      * @throws PfModelException on errors deleting PDP groups
      */
-    public PdpGroups deletePdpGroups(@NonNull final PfDao dao, @NonNull final String pdpGroupFilter)
+    public PdpGroup deletePdpGroup(@NonNull final PfDao dao, @NonNull final String name, @NonNull final String version)
             throws PfModelException {
-        return new PdpGroups();
+        return new PdpGroup();
+
+    }
+
+    /**
+     * Get PDP statistics.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the PDP group to get statistics for, null to get all PDP groups
+     * @param version the version of the PDP group to get statistics for, null to get all versions of a PDP group
+     * @return the statistics found
+     * @throws PfModelException on errors getting statistics
+     */
+    public List<PdpStatistics> getPdpStatistics(@NonNull final PfDao dao, final String name, final String version)
+            throws PfModelException {
+        return new ArrayList<>();
+    }
+
+    /**
+     * Update PDP statistics for a PDP.
+     *
+     * @param dao the DAO to use to access the database
+     * @param pdpGroupName the name of the PDP group containing the PDP that the statistics are for
+     * @param pdpGroupVersion the version of the PDP group containing the PDP that the statistics are for
+     * @param pdpType the PDP type of the subgroup containing the PDP that the statistics are for
+     * @param pdpInstanceId the instance ID of the PDP to update statistics for
+     * @throws PfModelException on errors updating statistics
+     */
+    public void updatePdpStatistics(@NonNull final PfDao dao, @NonNull final String pdpGroupName,
+            @NonNull final String pdpGroupVersion, @NonNull final String pdpType, @NonNull final String pdpInstanceId,
+            @NonNull final PdpStatistics pdppStatistics)  throws PfModelException {
+        // Not implemented yet
+    }
+
+    /**
+     * Get deployed policies.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the policy to get, null to get all policies
+     * @return the policies deployed as a map of policy lists keyed by PDP group
+     * @throws PfModelException on errors getting policies
+     */
+    public Map<PdpGroup, List<ToscaPolicy>> getDeployedPolicyList(@NonNull final PfDao dao, final String name)
+            throws PfModelException {
+        return new LinkedHashMap<>();
     }
 }
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java
new file mode 100644 (file)
index 0000000..8c843a1
--- /dev/null
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.models.pdp.enums.PdpState;
+
+/**
+ * Test the copy constructor, as {@link TestModels} tests the other methods.
+ */
+public class TestPdpStateChange {
+
+    @Test
+    public void testCopyConstructor() {
+        assertThatThrownBy(() -> new PdpStateChange(null)).isInstanceOf(NullPointerException.class);
+
+        PdpStateChange orig = new PdpStateChange();
+
+        // verify with null values
+        assertEquals("PdpStateChange(name=null, state=null, pdpGroup=null, pdpSubgroup=null)",
+                        new PdpStateChange(orig).toString());
+
+        // verify with all values
+        orig.setName("my-name");
+        orig.setPdpGroup("my-group");
+        orig.setPdpSubgroup("my-subgroup");
+        orig.setState(PdpState.SAFE);
+
+        assertEquals("PdpStateChange(name=my-name, state=SAFE, pdpGroup=my-group, pdpSubgroup=my-subgroup)",
+                        new PdpStateChange(orig).toString());
+    }
+}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java
new file mode 100644 (file)
index 0000000..5f8819b
--- /dev/null
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+
+/**
+ * Test the copy constructor, as {@link TestModels} tests the other methods.
+ */
+public class TestPdpUpdate {
+
+    @Test
+    public void testCopyConstructor() {
+        assertThatThrownBy(() -> new PdpUpdate(null)).isInstanceOf(NullPointerException.class);
+
+        PdpUpdate orig = new PdpUpdate();
+
+        // verify with null values
+        assertEquals("PdpUpdate(name=null, pdpType=null, description=null, pdpGroup=null, "
+                        + "pdpSubgroup=null, policies=null)", new PdpUpdate(orig).toString());
+
+        // verify with all values
+        orig.setDescription("my-description");
+        orig.setName("my-name");
+        orig.setPdpGroup("my-group");
+        orig.setPdpSubgroup("my-subgroup");
+        orig.setPdpType("my-type");
+
+        ToscaPolicy policy1 = new ToscaPolicy();
+        policy1.setName("policy-a");
+        policy1.setVersion("1.2.3");
+
+        ToscaPolicy policy2 = new ToscaPolicy();
+        policy2.setName("policy-b");
+        policy2.setVersion("4.5.6");
+
+        List<ToscaPolicy> policies = Arrays.asList(policy1, policy2);
+        orig.setPolicies(policies);
+
+        PdpUpdate other = new PdpUpdate(orig);
+
+        assertEquals("PdpUpdate(name=my-name, pdpType=my-type, description=my-description, "
+                        + "pdpGroup=my-group, pdpSubgroup=my-subgroup, policies=["
+                        + "ToscaPolicy(super=ToscaEntity(name=policy-a, version=1.2.3, derivedFrom=null, "
+                        + "metadata=null, description=null), type=null, typeVersion=null, properties=null), "
+                        + "ToscaPolicy(super=ToscaEntity(name=policy-b, version=4.5.6, derivedFrom=null, "
+                        + "metadata=null, description=null), type=null, typeVersion=null, properties=null)])",
+                        other.toString());
+
+        // ensure list and items are not the same object
+        assertTrue(other.getPolicies() != policies);
+        assertTrue(other.getPolicies().get(0) != policies.get(0));
+    }
+}
index 4cd5570..da94246 100644 (file)
@@ -22,11 +22,8 @@ package org.onap.policy.models.pdp.concepts;
 
 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 org.junit.Test;
-import org.onap.policy.models.base.PfValidationResult;
 
 /**
  * Test the other constructors, as {@link TestModels} tests the other methods.
@@ -62,29 +59,4 @@ public class TestPolicyIdent extends IdentTestBase<PolicyIdent> {
         orig = new PolicyIdent(NAME, VERSION);
         assertEquals(orig.toString(), new PolicyIdent(orig).toString());
     }
-
-    @Test
-    public void testValidate() throws Exception {
-        assertTrue(makeIdent(NAME, VERSION).validate(new PfValidationResult()).isValid());
-
-        // everything is null
-        PfValidationResult result = makeIdent(null, null).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(2, result.getMessageList().size());
-
-        // name is null
-        result = makeIdent(null, VERSION).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(1, result.getMessageList().size());
-
-        // version is null
-        result = makeIdent(NAME, null).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(1, result.getMessageList().size());
-
-        // version is invalid
-        result = makeIdent(NAME, "!!!" + VERSION).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(1, result.getMessageList().size());
-    }
 }
index 3428ac1..6ae7ad3 100644 (file)
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
-import org.onap.policy.models.base.PfValidationResult;
 
 /**
  * Test the other constructors, as {@link TestModels} tests the other methods.
@@ -39,6 +38,22 @@ public class TestPolicyIdentOptVersion extends IdentTestBase<PolicyIdentOptVersi
         super(PolicyIdentOptVersion.class);
     }
 
+    @Test
+    public void testAllArgsConstructor_testIsNullVersion() {
+        assertThatThrownBy(() -> new PolicyIdentOptVersion(null, VERSION)).isInstanceOf(NullPointerException.class);
+
+        // with null version
+        PolicyIdentOptVersion orig = new PolicyIdentOptVersion(NAME, null);
+        assertEquals(NAME, orig.getName());
+        assertEquals(null, orig.getVersion());
+        assertTrue(orig.isNullVersion());
+
+        orig = new PolicyIdentOptVersion(NAME, VERSION);
+        assertEquals(NAME, orig.getName());
+        assertEquals(VERSION, orig.getVersion());
+        assertFalse(orig.isNullVersion());
+    }
+
     @Test
     public void testCopyConstructor() throws Exception {
         assertThatThrownBy(() -> new PolicyIdentOptVersion(null)).isInstanceOf(NullPointerException.class);
@@ -52,36 +67,4 @@ public class TestPolicyIdentOptVersion extends IdentTestBase<PolicyIdentOptVersi
         orig = makeIdent(NAME, VERSION);
         assertEquals(orig.toString(), new PolicyIdentOptVersion(orig).toString());
     }
-
-    @Test
-    public void testValidate() throws Exception {
-        assertThatThrownBy(() -> makeIdent(NAME, VERSION).validate(null)).isInstanceOf(NullPointerException.class);
-        assertTrue(makeIdent(NAME, VERSION).validate(new PfValidationResult()).isValid());
-        assertTrue(makeIdent(NAME, null).validate(new PfValidationResult()).isValid());
-
-        // everything is null
-        PfValidationResult result = makeIdent(null, null).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(1, result.getMessageList().size());
-
-        // name is null
-        result = makeIdent(null, VERSION).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(1, result.getMessageList().size());
-
-        // name is null, version is invalid
-        result = makeIdent(null, "$$$" + VERSION).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(2, result.getMessageList().size());
-
-        // name is invalid
-        result = makeIdent("!!!invalid name$$$", VERSION).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(1, result.getMessageList().size());
-
-        // version is invalid
-        result = makeIdent(NAME, "!!!" + VERSION).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(1, result.getMessageList().size());
-    }
 }
index 5b7494e..9247544 100644 (file)
@@ -22,11 +22,8 @@ package org.onap.policy.models.pdp.concepts;
 
 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 org.junit.Test;
-import org.onap.policy.models.base.PfValidationResult;
 
 /**
  * Test the other constructors, as {@link TestModels} tests the other methods.
@@ -63,29 +60,4 @@ public class TestPolicyTypeIdent extends IdentTestBase<PolicyTypeIdent> {
         assertEquals(orig.toString(), new PolicyTypeIdent(orig).toString());
     }
 
-    @Test
-    public void testValidate() throws Exception {
-        assertTrue(makeIdent(NAME, VERSION).validate(new PfValidationResult()).isValid());
-
-        // everything is null
-        PfValidationResult result = makeIdent(null, null).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(2, result.getMessageList().size());
-
-        // name is null
-        result = makeIdent(null, VERSION).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(1, result.getMessageList().size());
-
-        // version is null
-        result = makeIdent(NAME, null).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(1, result.getMessageList().size());
-
-        // version is invalid
-        result = makeIdent(NAME, "!!!" + VERSION).validate(new PfValidationResult());
-        assertFalse(result.isValid());
-        assertEquals(1, result.getMessageList().size());
-    }
-
 }
index e390a04..b0494ff 100644 (file)
 
 package org.onap.policy.models.provider;
 
+import java.util.List;
 import java.util.Map;
 
 import lombok.NonNull;
 
-import org.onap.policy.models.base.PfConceptKey;
+import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.pdp.concepts.PdpGroup;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
 
 /**
  * This interface describes the operations that are provided to users and components for reading objects from and
@@ -49,12 +55,40 @@ public interface PolicyModelsProvider extends AutoCloseable {
     /**
      * Get policy types.
      *
-     * @param policyTypeKey the policy type key for the policy types to be retrieved. A null key name returns all policy
-     *        types. A null key version returns all versions of the policy type name specified in the key.
+     * @param name the name of the policy type to get, set to null to get all policy types
+     * @param version the version of the policy type to get, set to null to get all versions
      * @return the policy types found
      * @throws PfModelException on errors getting policy types
      */
-    public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException;
+    public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
+
+    /**
+     * Get policy types.
+     *
+     * @param name the name of the policy type to get, set to null to get all policy types
+     * @param version the version of the policy type to get, set to null to get all versions
+     * @return the policy types found
+     * @throws PfModelException on errors getting policy types
+     */
+    public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
+
+    /**
+     * Get latest policy types.
+     *
+     * @param name the name of the policy type to get, set to null to get all policy types
+     * @return the policy types found
+     * @throws PfModelException on errors getting policy types
+     */
+    public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException;
+
+    /**
+     * Get latest policy types.
+     *
+     * @param name the name of the policy type to get, set to null to get all policy types
+     * @return the policy types found
+     * @throws PfModelException on errors getting policy types
+     */
+    public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException;
 
     /**
      * Create policy types.
@@ -63,7 +97,7 @@ public interface PolicyModelsProvider extends AutoCloseable {
      * @return the TOSCA service template containing the created policy types
      * @throws PfModelException on errors creating policy types
      */
-    public JpaToscaServiceTemplate createPolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException;
 
     /**
@@ -73,28 +107,66 @@ public interface PolicyModelsProvider extends AutoCloseable {
      * @return the TOSCA service template containing the modified policy types
      * @throws PfModelException on errors updating policy types
      */
-    public JpaToscaServiceTemplate updatePolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException;
 
     /**
-     * Delete policy types.
+     * Delete policy type.
      *
-     * @param policyTypeKey the policy type key for the policy types to be deleted, if the version of the key is null,
-     *        all versions of the policy type are deleted.
-     * @return the TOSCA service template containing the policy types that were deleted
+     * @param name the name of the policy type to delete.
+     * @param version the version of the policy type to delete.
+     * @return the TOSCA service template containing the policy type that was deleted
      * @throws PfModelException on errors deleting policy types
      */
-    public JpaToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException;
+    public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
+            throws PfModelException;
 
     /**
      * Get policies.
      *
-     * @param policyKey the policy key for the policies to be retrieved. The parent name and version must be specified.
-     *        A null local name returns all policies for a parent policy type.
+     * @param name the name of the policy to get, null to get all policies
+     * @param version the version of the policy to get, null to get all versions of a policy
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
+
+    /**
+     * Get policies.
+     *
+     * @param name the name of the policy to get, null to get all policies
+     * @param version the version of the policy to get, null to get all versions of a policy
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
+
+    /**
+     * Get policies for a policy type name.
+     *
+     * @param policyTypeName the name of the policy type for which to get policies
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName) throws PfModelException;
+
+    /**
+     * Get latest policies.
+     *
+     * @param name the name of the policy to get, null to get all policies
      * @return the policies found
      * @throws PfModelException on errors getting policies
      */
-    public JpaToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException;
+    public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException;
+
+    /**
+     * Get latest policies.
+     *
+     * @param name the name of the policy to get, null to get all policies
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException;
 
     /**
      * Create policies.
@@ -103,10 +175,9 @@ public interface PolicyModelsProvider extends AutoCloseable {
      * @return the TOSCA service template containing the policy types that were created
      * @throws PfModelException on errors creating policies
      */
-    public JpaToscaServiceTemplate createPolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException;
 
-
     /**
      * Update policies.
      *
@@ -114,17 +185,19 @@ public interface PolicyModelsProvider extends AutoCloseable {
      * @return the TOSCA service template containing the policies that were updated
      * @throws PfModelException on errors updating policies
      */
-    public JpaToscaServiceTemplate updatePolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException;
 
     /**
-     * Delete policies.
+     * Delete policy.
      *
-     * @param policyKey the policy key
-     * @return the TOSCA service template containing the policy types that were deleted
-     * @throws PfModelException on errors deleting policies
+     * @param name the name of the policy to delete.
+     * @param version the version of the policy to delete.
+     * @return the TOSCA service template containing the policy that was deleted
+     * @throws PfModelException on errors deleting a policy
      */
-    public JpaToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException;
+    public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
+            throws PfModelException;
 
     /**
      * Get legacy operational policy.
@@ -206,11 +279,31 @@ public interface PolicyModelsProvider extends AutoCloseable {
     /**
      * Get PDP groups.
      *
-     * @param pdpGroupFilter a filter for the get
+     * @param name the name of the policy to get, null to get all PDP groups
+     * @param version the version of the policy to get, null to get all versions of a PDP group
      * @return the PDP groups found
      * @throws PfModelException on errors getting PDP groups
      */
-    public PdpGroups getPdpGroups(@NonNull final String pdpGroupFilter) throws PfModelException;
+    public PdpGroups getPdpGroups(final String name, final String version) throws PfModelException;
+
+    /**
+     * Get latest PDP Groups.
+     *
+     * @param name the name of the PDP group to get, null to get all PDP groups
+     * @return the PDP groups found
+     * @throws PfModelException on errors getting policies
+     */
+    public PdpGroups getLatestPdpGroups(final String name) throws PfModelException;
+
+    /**
+     * Get a filtered list of PDP groups.
+     *
+     * @param pdpType The PDP type filter for the returned PDP groups
+     * @param supportedPolicyTypes a list of policy type name/version pairs that the PDP groups must support.
+     * @return the PDP groups found
+     */
+    public PdpGroups getFilteredPdpGroups(@NonNull final String pdpType,
+            @NonNull final List<Pair<String, String>> supportedPolicyTypes);
 
     /**
      * Creates PDP groups.
@@ -230,12 +323,57 @@ public interface PolicyModelsProvider extends AutoCloseable {
      */
     public PdpGroups updatePdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException;
 
+
+    /**
+     * Update a PDP subgroup.
+     *
+     * @param pdpGroupName the name of the PDP group of the PDP subgroup
+     * @param pdpGroupVersion the version of the PDP group of the PDP subgroup
+     * @param pdpSubGroup the PDP subgroup to be updated
+     * @throws PfModelException on errors updating PDP subgroups
+     */
+    public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
+            @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException;
+
     /**
-     * Delete PDP groups.
+     * Delete a PDP group.
      *
-     * @param pdpGroupFilter a filter for the get
-     * @return the PDP groups deleted
+     * @param name the name of the policy to get, null to get all PDP groups
+     * @param version the version of the policy to get, null to get all versions of a PDP group
+     * @return the PDP group deleted
      * @throws PfModelException on errors deleting PDP groups
      */
-    public PdpGroups deletePdpGroups(@NonNull final String pdpGroupFilter) throws PfModelException;
+    public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException;
+
+    /**
+     * Get PDP statistics.
+     *
+     * @param name the name of the PDP group to get statistics for, null to get all PDP groups
+     * @param version the version of the PDP group to get statistics for, null to get all versions of a PDP group
+     * @return the statistics found
+     * @throws PfModelException on errors getting statistics
+     */
+    public List<PdpStatistics> getPdpStatistics(final String name, final String version) throws PfModelException;
+
+    /**
+     * Update PDP statistics for a PDP.
+     *
+     * @param pdpGroupName the name of the PDP group containing the PDP that the statistics are for
+     * @param pdpGroupVersion the version of the PDP group containing the PDP that the statistics are for
+     * @param pdpType the PDP type of the subgroup containing the PDP that the statistics are for
+     * @param pdpInstanceId the instance ID of the PDP to update statistics for
+     * @throws PfModelException on errors updating statistics
+     */
+    public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
+            @NonNull final String pdpType, @NonNull final String pdpInstanceId,
+            @NonNull final PdpStatistics pdppStatistics) throws PfModelException;
+
+    /**
+     * Get deployed policies.
+     *
+     * @param name the name of the policy to get, null to get all policies
+     * @return the policies deployed as a map of policy lists keyed by PDP group
+     * @throws PfModelException on errors getting policies
+     */
+    public Map<PdpGroup, List<ToscaPolicy>> getDeployedPolicyList(final String name) throws PfModelException;
 }
index 85c4d13..ee8ed73 100644 (file)
@@ -23,29 +23,35 @@ package org.onap.policy.models.provider.impl;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.util.Base64;
+import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.core.Response;
 
 import lombok.NonNull;
 
-import org.onap.policy.models.base.PfConceptKey;
+import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.dao.DaoParameters;
 import org.onap.policy.models.dao.PfDao;
 import org.onap.policy.models.dao.PfDaoFactory;
 import org.onap.policy.models.dao.impl.DefaultPfDao;
+import org.onap.policy.models.pdp.concepts.PdpGroup;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.pdp.persistence.provider.PdpProvider;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
 import org.onap.policy.models.tosca.legacy.provider.LegacyProvider;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -138,56 +144,99 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
+    public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
         assertInitilized();
-        return new SimpleToscaProvider().getPolicyTypes(pfDao, policyTypeKey);
+        return new AuthorativeToscaProvider().getPolicyTypes(pfDao, name, version);
     }
 
     @Override
-    public JpaToscaServiceTemplate createPolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+    public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
+        assertInitilized();
+        return new AuthorativeToscaProvider().getPolicyTypeList(pfDao, name, version);
+    }
+
+    @Override
+    public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException {
+        assertInitilized();
+        return new AuthorativeToscaProvider().getLatestPolicyTypes(pfDao, name);
+    }
+
+    @Override
+    public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException {
+        assertInitilized();
+        return new AuthorativeToscaProvider().getLatestPolicyTypeList(pfDao, name);
+    }
+
+    @Override
+    public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         assertInitilized();
-        return new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+        return new AuthorativeToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
     }
 
     @Override
-    public JpaToscaServiceTemplate updatePolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         assertInitilized();
-        return new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
+        return new AuthorativeToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
     }
 
     @Override
-    public JpaToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey)
+    public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
             throws PfModelException {
         assertInitilized();
-        return new SimpleToscaProvider().deletePolicyTypes(pfDao, policyTypeKey);
+        return new AuthorativeToscaProvider().deletePolicyType(pfDao, name, version);
     }
 
     @Override
-    public JpaToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
+    public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
         assertInitilized();
-        return new SimpleToscaProvider().getPolicies(pfDao, policyKey);
+        return new AuthorativeToscaProvider().getPolicies(pfDao, name, version);
     }
 
     @Override
-    public JpaToscaServiceTemplate createPolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+    public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
+        assertInitilized();
+        return new AuthorativeToscaProvider().getPolicyList(pfDao, name, version);
+    }
+
+    @Override
+    public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName) throws PfModelException {
+        assertInitilized();
+        return new AuthorativeToscaProvider().getPolicyList4PolicyType(pfDao, policyTypeName);
+    }
+
+    @Override
+    public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException {
+        assertInitilized();
+        return new AuthorativeToscaProvider().getLatestPolicies(pfDao, name);
+    }
+
+    @Override
+    public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException {
+        assertInitilized();
+        return new AuthorativeToscaProvider().getLatestPolicyList(pfDao, name);
+    }
+
+    @Override
+    public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         assertInitilized();
-        return new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate);
+        return new AuthorativeToscaProvider().createPolicies(pfDao, serviceTemplate);
     }
 
     @Override
-    public JpaToscaServiceTemplate updatePolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         assertInitilized();
-        return new SimpleToscaProvider().updatePolicies(pfDao, serviceTemplate);
+        return new AuthorativeToscaProvider().updatePolicies(pfDao, serviceTemplate);
     }
 
     @Override
-    public JpaToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
+    public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
+            throws PfModelException {
         assertInitilized();
-        return new SimpleToscaProvider().deletePolicies(pfDao, policyKey);
+        return new AuthorativeToscaProvider().deletePolicy(pfDao, name, version);
     }
 
     @Override
@@ -244,27 +293,68 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public PdpGroups getPdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
+    public PdpGroups getPdpGroups(final String name, final String version) throws PfModelException {
         assertInitilized();
-        return new PdpProvider().getPdpGroups(pfDao, pdpGroupFilter);
+        return new PdpProvider().getPdpGroups(pfDao, name, version);
     }
 
     @Override
-    public PdpGroups createPdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
+    public PdpGroups getLatestPdpGroups(final String name) throws PfModelException {
+        assertInitilized();
+        return new PdpProvider().getLatestPdpGroups(pfDao, name);
+    }
+
+    @Override
+    public PdpGroups getFilteredPdpGroups(@NonNull final String pdpType,
+            @NonNull final List<Pair<String, String>> supportedPolicyTypes) {
+        assertInitilized();
+        return new PdpProvider().getFilteredPdpGroups(pfDao, pdpType, supportedPolicyTypes);
+    }
+
+    @Override
+    public PdpGroups createPdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException {
         assertInitilized();
         return new PdpProvider().createPdpGroups(pfDao, pdpGroups);
     }
 
     @Override
-    public PdpGroups updatePdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
+    public PdpGroups updatePdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException {
         assertInitilized();
         return new PdpProvider().updatePdpGroups(pfDao, pdpGroups);
     }
 
     @Override
-    public PdpGroups deletePdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
+    public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
+            @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException {
+        assertInitilized();
+        new PdpProvider().updatePdpSubGroup(pfDao, pdpGroupName, pdpGroupVersion, pdpSubGroup);
+    }
+
+    @Override
+    public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException {
+        assertInitilized();
+        return new PdpProvider().deletePdpGroup(pfDao, name, version);
+    }
+
+    @Override
+    public List<PdpStatistics> getPdpStatistics(final String name, final String version) throws PfModelException {
+        assertInitilized();
+        return new PdpProvider().getPdpStatistics(pfDao, name, version);
+    }
+
+    @Override
+    public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
+            @NonNull final String pdpType, @NonNull final String pdpInstanceId,
+            @NonNull final PdpStatistics pdppStatistics)  throws PfModelException {
+        assertInitilized();
+        new PdpProvider().updatePdpStatistics(pfDao, pdpGroupName, pdpGroupVersion, pdpType, pdpInstanceId,
+                pdppStatistics);
+    }
+
+    @Override
+    public Map<PdpGroup, List<ToscaPolicy>> getDeployedPolicyList(final String name) throws PfModelException {
         assertInitilized();
-        return new PdpProvider().deletePdpGroups(pfDao, pdpGroupFilter);
+        return new PdpProvider().getDeployedPolicyList(pfDao, name);
     }
 
     /**
index e37b1d6..3db8e5e 100644 (file)
 
 package org.onap.policy.models.provider.impl;
 
-import com.google.gson.Gson;
-
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.core.Response;
 import lombok.NonNull;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.ResourceUtils;
-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.pdp.concepts.PdpGroup;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
 
 /**
  * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
@@ -66,47 +72,83 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
+    public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
     }
 
     @Override
-    public JpaToscaServiceTemplate createPolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+    public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
+        return new ArrayList<>();
+    }
+
+    @Override
+    public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException {
+        return new ArrayList<>();
+    }
+
+    @Override
+    public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return serviceTemplate;
     }
 
     @Override
-    public JpaToscaServiceTemplate updatePolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return serviceTemplate;
     }
 
     @Override
-    public JpaToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey)
+    public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
             throws PfModelException {
         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
     }
 
     @Override
-    public JpaToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
+    public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
         return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
     }
 
     @Override
-    public JpaToscaServiceTemplate createPolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+    public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
+        return new ArrayList<>();
+    }
+
+    @Override
+    public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName) throws PfModelException {
+        return new ArrayList<>();
+    }
+
+    @Override
+    public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException {
+        return new ArrayList<>();
+    }
+
+    @Override
+    public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return serviceTemplate;
     }
 
     @Override
-    public JpaToscaServiceTemplate updatePolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return serviceTemplate;
     }
 
     @Override
-    public JpaToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
+    public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
+            throws PfModelException {
         return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
     }
 
@@ -157,23 +199,57 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public PdpGroups getPdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
-        return new PdpGroups();
+    public PdpGroups getPdpGroups(final String name, final String version) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public PdpGroups getLatestPdpGroups(final String name) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public PdpGroups getFilteredPdpGroups(@NonNull final String pdpType,
+            @NonNull final List<Pair<String, String>> supportedPolicyTypes) {
+        return null;
+    }
+
+    @Override
+    public PdpGroups createPdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public PdpGroups updatePdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
+            @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException {
+        // Not implemented
+    }
+
+    @Override
+    public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException {
+        return null;
     }
 
     @Override
-    public PdpGroups createPdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
-        return new PdpGroups();
+    public List<PdpStatistics> getPdpStatistics(final String name, final String version) throws PfModelException {
+        return new ArrayList<>();
     }
 
     @Override
-    public PdpGroups updatePdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
-        return new PdpGroups();
+    public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
+            @NonNull final String pdpType, @NonNull final String pdpInstanceId,
+            @NonNull final PdpStatistics pdppStatistics)  throws PfModelException {
+        // Not implemented
     }
 
     @Override
-    public PdpGroups deletePdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
-        return new PdpGroups();
+    public Map<PdpGroup, List<ToscaPolicy>> getDeployedPolicyList(final String name) throws PfModelException {
+        return null;
     }
 
     /**
@@ -182,12 +258,13 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
      * @param fileName the file name containing the dummy response
      * @return the ToscaServiceTemplate with the dummy response
      */
-    protected JpaToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
-        Gson gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
-        JpaToscaServiceTemplate serviceTemplate;
+    protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
+        StandardCoder standardCoder = new StandardCoder();
+        ToscaServiceTemplate serviceTemplate;
 
         try {
-            serviceTemplate = gson.fromJson(ResourceUtils.getResourceAsString(fileName), JpaToscaServiceTemplate.class);
+            serviceTemplate =
+                    standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
             if (serviceTemplate == null) {
                 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
             }
index 3352334..d925333 100644 (file)
@@ -28,14 +28,13 @@ import java.util.Base64;
 
 import org.junit.Before;
 import org.junit.Test;
-import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderFactory;
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -120,9 +119,16 @@ public class DatabasePolicyModelsProviderTest {
         databaseProvider.init();
 
         assertThatThrownBy(() -> {
-            databaseProvider.getPolicyTypes(null);
-        }).hasMessage("policyTypeKey is marked @NonNull but is null");
+            databaseProvider.getPolicyTypes(null, null);
+        }).hasMessage("name is marked @NonNull but is null");
 
+        assertThatThrownBy(() -> {
+            databaseProvider.getPolicyTypes("aaa", null);
+        }).hasMessage("version is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.getPolicyTypes(null, "aaa");
+        }).hasMessage("name is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
             databaseProvider.createPolicyTypes(null);
@@ -133,12 +139,28 @@ public class DatabasePolicyModelsProviderTest {
         }).hasMessage("serviceTemplate is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            databaseProvider.deletePolicyTypes(null);
-        }).hasMessage("policyTypeKey is marked @NonNull but is null");
+            databaseProvider.deletePolicyType(null, null);
+        }).hasMessage("name is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.deletePolicyType("aaa", null);
+        }).hasMessage("version is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.deletePolicyType(null, "aaa");
+        }).hasMessage("name is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.getPolicies(null, null);
+        }).hasMessage("name is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            databaseProvider.getPolicies(null);
-        }).hasMessage("policyKey is marked @NonNull but is null");
+            databaseProvider.getPolicies(null, "aaa");
+        }).hasMessage("name is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.getPolicies("aaa", null);
+        }).hasMessage("version is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
             databaseProvider.createPolicies(null);
@@ -149,8 +171,16 @@ public class DatabasePolicyModelsProviderTest {
         }).hasMessage("serviceTemplate is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            databaseProvider.deletePolicies(null);
-        }).hasMessage("policyKey is marked @NonNull but is null");
+            databaseProvider.deletePolicy(null, null);
+        }).hasMessage("name is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.deletePolicy(null, "aaa");
+        }).hasMessage("name is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.deletePolicy("aaa", null);
+        }).hasMessage("version is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
             databaseProvider.getOperationalPolicy(null);
@@ -184,10 +214,6 @@ public class DatabasePolicyModelsProviderTest {
             databaseProvider.deleteGuardPolicy(null);
         }).hasMessage("policyId is marked @NonNull but is null");
 
-        assertThatThrownBy(() -> {
-            databaseProvider.getPdpGroups(null);
-        }).hasMessage("pdpGroupFilter is marked @NonNull but is null");
-
         assertThatThrownBy(() -> {
             databaseProvider.createPdpGroups(null);
         }).hasMessage("pdpGroups is marked @NonNull but is null");
@@ -197,8 +223,8 @@ public class DatabasePolicyModelsProviderTest {
         }).hasMessage("pdpGroups is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            databaseProvider.deletePdpGroups(null);
-        }).hasMessage("pdpGroupFilter is marked @NonNull but is null");
+            databaseProvider.deletePdpGroup(null, null);
+        }).hasMessage("name is marked @NonNull but is null");
 
         databaseProvider.close();
 
@@ -210,7 +236,7 @@ public class DatabasePolicyModelsProviderTest {
                 new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
 
         assertThatThrownBy(() -> {
-            databaseProvider.getPolicyTypes(new PfConceptKey());
+            databaseProvider.getPolicyTypes("name", "version");
         }).hasMessage("policy models provider is not initilaized");
     }
 
@@ -221,36 +247,36 @@ public class DatabasePolicyModelsProviderTest {
             databaseProvider.init();
 
             assertThatThrownBy(() -> {
-                databaseProvider.getPolicyTypes(new PfConceptKey());
-            }).hasMessage("policy type not found: NULL:0.0.0");
+                databaseProvider.getPolicyTypes("name", "version");
+            }).hasMessage("policy type not found: name:version");
 
             assertThatThrownBy(() -> {
-                databaseProvider.createPolicyTypes(new JpaToscaServiceTemplate());
+                databaseProvider.createPolicyTypes(new ToscaServiceTemplate());
             }).hasMessage("no policy types specified on service template");
 
             assertThatThrownBy(() -> {
-                databaseProvider.updatePolicyTypes(new JpaToscaServiceTemplate());
+                databaseProvider.updatePolicyTypes(new ToscaServiceTemplate());
             }).hasMessage("no policy types specified on service template");
 
             assertThatThrownBy(() -> {
-                databaseProvider.deletePolicyTypes(new PfConceptKey());
-            }).hasMessage("policy type not found: NULL:0.0.0");
+                databaseProvider.deletePolicyType("name", "version");
+            }).hasMessage("policy type not found: name:version");
 
             assertThatThrownBy(() -> {
-                databaseProvider.getPolicies(new PfConceptKey());
-            }).hasMessage("policy not found: NULL:0.0.0");
+                databaseProvider.getPolicies("name", "version");
+            }).hasMessage("policy not found: name:version");
 
             assertThatThrownBy(() -> {
-                databaseProvider.createPolicies(new JpaToscaServiceTemplate());
+                databaseProvider.createPolicies(new ToscaServiceTemplate());
             }).hasMessage("topology template not specified on service template");
 
             assertThatThrownBy(() -> {
-                databaseProvider.updatePolicies(new JpaToscaServiceTemplate());
+                databaseProvider.updatePolicies(new ToscaServiceTemplate());
             }).hasMessage("topology template not specified on service template");
 
             assertThatThrownBy(() -> {
-                databaseProvider.deletePolicies(new PfConceptKey());
-            }).hasMessage("policy not found: NULL:0.0.0");
+                databaseProvider.deletePolicy("name", "version");
+            }).hasMessage("policy not found: name:version");
 
             assertThatThrownBy(() -> {
                 databaseProvider.getOperationalPolicy("policy_id");
@@ -284,10 +310,10 @@ public class DatabasePolicyModelsProviderTest {
                 databaseProvider.deleteGuardPolicy("policy_id");
             }).hasMessage("no policy found for policy ID: policy_id");
 
-            assertNotNull(databaseProvider.getPdpGroups("filter"));
+            assertNotNull(databaseProvider.getPdpGroups("name", "version"));
             assertNotNull(databaseProvider.createPdpGroups(new PdpGroups()));
             assertNotNull(databaseProvider.updatePdpGroups(new PdpGroups()));
-            assertNotNull(databaseProvider.deletePdpGroups("filter"));
+            assertNotNull(databaseProvider.deletePdpGroup("name", "version"));
 
         } catch (Exception exc) {
             LOGGER.warn("test should not throw an exception", exc);
index 2ee210c..9320df5 100644 (file)
 
 package org.onap.policy.models.provider.impl;
 
+import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.core.Response;
 
 import lombok.NonNull;
 
-import org.onap.policy.models.base.PfConceptKey;
+import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.pdp.concepts.PdpGroup;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
 
 /**
  * Dummy implementation of {@link PolicyModelsProvider} with bad constructor.
@@ -53,46 +59,46 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
     public void init() throws PfModelException {}
 
     @Override
-    public JpaToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
+    public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
         return null;
     }
 
     @Override
-    public JpaToscaServiceTemplate createPolicyTypes(@NonNull JpaToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return null;
     }
 
     @Override
-    public JpaToscaServiceTemplate updatePolicyTypes(@NonNull JpaToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return null;
     }
 
     @Override
-    public JpaToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
+    public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException {
         return null;
     }
 
     @Override
-    public JpaToscaServiceTemplate getPolicies(@NonNull PfConceptKey policyKey) throws PfModelException {
+    public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
         return null;
     }
 
     @Override
-    public JpaToscaServiceTemplate createPolicies(@NonNull JpaToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return null;
     }
 
     @Override
-    public JpaToscaServiceTemplate updatePolicies(@NonNull JpaToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return null;
     }
 
     @Override
-    public JpaToscaServiceTemplate deletePolicies(@NonNull PfConceptKey policyKey) throws PfModelException {
+    public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException {
         return null;
     }
 
@@ -141,7 +147,7 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public PdpGroups getPdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
+    public PdpGroups getPdpGroups(String name, String version) throws PfModelException {
         return null;
     }
 
@@ -156,7 +162,73 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public PdpGroups deletePdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
+    public PdpGroup deletePdpGroup(@NonNull String name, @NonNull String verison) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public List<ToscaPolicyType> getPolicyTypeList(String name, String version) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public ToscaServiceTemplate getLatestPolicyTypes(String name) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public List<ToscaPolicyType> getLatestPolicyTypeList(String name) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public List<ToscaPolicy> getPolicyList(String name, String version) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull String policyTypeName) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public ToscaServiceTemplate getLatestPolicies(String name) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public List<ToscaPolicy> getLatestPolicyList(String name) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public PdpGroups getLatestPdpGroups(String name) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public PdpGroups getFilteredPdpGroups(@NonNull String pdpType,
+            @NonNull List<Pair<String, String>> supportedPolicyTypes) {
+        return null;
+    }
+
+    @Override
+    public void updatePdpSubGroup(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion,
+            @NonNull PdpSubGroup pdpSubGroup) throws PfModelException {
+    }
+
+    @Override
+    public List<PdpStatistics> getPdpStatistics(String name, String version) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public void updatePdpStatistics(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion,
+            @NonNull String pdpType, @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) {
+    }
+
+    @Override
+    public Map<PdpGroup, List<ToscaPolicy>> getDeployedPolicyList(String name) throws PfModelException {
         return null;
     }
 }
index 66c7762..797b1ac 100644 (file)
@@ -23,7 +23,7 @@ package org.onap.policy.models.provider.impl;
 import lombok.NonNull;
 
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 
 /**
  * Sub class to check getDummyResponse() method in base class.
@@ -40,11 +40,11 @@ public class DummyPolicyModelsProviderSubImpl extends DummyPolicyModelsProviderI
         super(parameters);
     }
 
-    public JpaToscaServiceTemplate getBadDummyResponse1() {
+    public ToscaServiceTemplate getBadDummyResponse1() {
         return super.getDummyResponse("/i/dont/exist");
     }
 
-    public JpaToscaServiceTemplate getBadDummyResponse2() {
+    public ToscaServiceTemplate getBadDummyResponse2() {
         return super.getDummyResponse(null);
     }
 }
index af76edb..a0b4857 100644 (file)
@@ -23,17 +23,17 @@ package org.onap.policy.models.provider.impl;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
 import org.junit.Test;
-import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderFactory;
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
 
 /**
  * Test the dummy models provider implementation.
@@ -53,10 +53,10 @@ public class DummyPolicyModelsProviderTest {
 
         dummyProvider.init();
 
-        JpaToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies(new PfConceptKey());
+        ToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies("onap.vcpe.tca", "1.0.0");
         assertNotNull(serviceTemplate);
-        assertEquals("onap.vcpe.tca:1.0.0",
-                serviceTemplate.getTopologyTemplate().getPolicies().get("onap.vcpe.tca").getId());
+        assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app",
+                serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get("onap.vcpe.tca").getType());
 
         dummyProvider.close();
     }
@@ -71,15 +71,15 @@ public class DummyPolicyModelsProviderTest {
         PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
         dummyProvider.init();
 
-        assertNotNull(dummyProvider.getPolicyTypes(new PfConceptKey()));
-        assertNotNull(dummyProvider.createPolicyTypes(new JpaToscaServiceTemplate()));
-        assertNotNull(dummyProvider.updatePolicyTypes(new JpaToscaServiceTemplate()));
-        assertNotNull(dummyProvider.deletePolicyTypes(new PfConceptKey()));
+        assertNotNull(dummyProvider.getPolicyTypes("name", "version"));
+        assertNotNull(dummyProvider.createPolicyTypes(new ToscaServiceTemplate()));
+        assertNotNull(dummyProvider.updatePolicyTypes(new ToscaServiceTemplate()));
+        assertNotNull(dummyProvider.deletePolicyType("name", "version"));
 
-        assertNotNull(dummyProvider.getPolicies(new PfConceptKey()));
-        assertNotNull(dummyProvider.createPolicies(new JpaToscaServiceTemplate()));
-        assertNotNull(dummyProvider.updatePolicies(new JpaToscaServiceTemplate()));
-        assertNotNull(dummyProvider.deletePolicies(new PfConceptKey()));
+        assertNotNull(dummyProvider.getPolicies("name", "version"));
+        assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate()));
+        assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate()));
+        assertNotNull(dummyProvider.deletePolicy("name", "version"));
 
         assertNotNull(dummyProvider.getOperationalPolicy("policy_id"));
         assertNotNull(dummyProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
@@ -91,36 +91,11 @@ public class DummyPolicyModelsProviderTest {
         assertNotNull(dummyProvider.updateGuardPolicy(new LegacyGuardPolicyInput()));
         assertNotNull(dummyProvider.deleteGuardPolicy("policy_id"));
 
-        assertNotNull(dummyProvider.getPdpGroups("filter"));
-        assertNotNull(dummyProvider.createPdpGroups(new PdpGroups()));
-        assertNotNull(dummyProvider.updatePdpGroups(new PdpGroups()));
-        assertNotNull(dummyProvider.deletePdpGroups("filter"));
+        assertNull(dummyProvider.getPdpGroups("name", "version"));
+        assertNull(dummyProvider.createPdpGroups(new PdpGroups()));
+        assertNull(dummyProvider.updatePdpGroups(new PdpGroups()));
+        assertNull(dummyProvider.deletePdpGroup("name", "version"));
 
-        assertThatThrownBy(() -> {
-            dummyProvider.getPolicyTypes(null);
-        }).hasMessage("policyTypeKey is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.createPolicyTypes(null);
-        }).hasMessage("serviceTemplate is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.updatePolicyTypes(null);
-        }).hasMessage("serviceTemplate is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.deletePolicyTypes(null);
-        }).hasMessage("policyTypeKey is marked @NonNull but is null");
-
-        assertThatThrownBy(() -> {
-            dummyProvider.getPolicies(null);
-        }).hasMessage("policyKey is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.createPolicies(null);
-        }).hasMessage("serviceTemplate is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.updatePolicies(null);
-        }).hasMessage("serviceTemplate is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.deletePolicies(null);
-        }).hasMessage("policyKey is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
             dummyProvider.getOperationalPolicy(null);
@@ -148,9 +123,6 @@ public class DummyPolicyModelsProviderTest {
             dummyProvider.deleteGuardPolicy(null);
         }).hasMessage("policyId is marked @NonNull but is null");
 
-        assertThatThrownBy(() -> {
-            dummyProvider.getPdpGroups(null);
-        }).hasMessage("pdpGroupFilter is marked @NonNull but is null");
         assertThatThrownBy(() -> {
             dummyProvider.createPdpGroups(null);
         }).hasMessage("pdpGroups is marked @NonNull but is null");
@@ -158,8 +130,8 @@ public class DummyPolicyModelsProviderTest {
             dummyProvider.updatePdpGroups(null);
         }).hasMessage("pdpGroups is marked @NonNull but is null");
         assertThatThrownBy(() -> {
-            dummyProvider.deletePdpGroups(null);
-        }).hasMessage("pdpGroupFilter is marked @NonNull but is null");
+            dummyProvider.deletePdpGroup(null, null);
+        }).hasMessage("name is marked @NonNull but is null");
 
         dummyProvider.close();
     }
index e0aba8a..b29e1d6 100644 (file)
@@ -22,29 +22,26 @@ package org.onap.policy.models.provider.impl;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 
 import java.util.Base64;
+import java.util.Map;
 
 import lombok.NonNull;
 
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderFactory;
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.yaml.snakeyaml.Yaml;
@@ -58,7 +55,7 @@ public class PolicyPersistenceTest {
     // Logger for this class
     private static final Logger LOGGER = LoggerFactory.getLogger(PolicyPersistenceTest.class);
 
-    private Gson gson;
+    private StandardCoder standardCoder;
 
     private PolicyModelsProvider databaseProvider;
 
@@ -101,7 +98,7 @@ public class PolicyPersistenceTest {
      */
     @Before
     public void setupGson() {
-        gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
+        standardCoder = new StandardCoder();
     }
 
     @After
@@ -141,19 +138,20 @@ public class PolicyPersistenceTest {
      * @throws Exception any exception thrown
      */
     public void testJsonStringPolicyPersistence(@NonNull final String policyString) throws Exception {
-        JpaToscaServiceTemplate serviceTemplate = gson.fromJson(policyString, JpaToscaServiceTemplate.class);
+        ToscaServiceTemplate serviceTemplate = standardCoder.decode(policyString, ToscaServiceTemplate.class);
 
         assertNotNull(serviceTemplate);
-        LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
-        assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
 
         databaseProvider.createPolicies(serviceTemplate);
 
-        for (PfConceptKey policyKey : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().keySet()) {
-            JpaToscaPolicy incomingPolicy = serviceTemplate.getTopologyTemplate().getPolicies().get(policyKey);
-            JpaToscaPolicy databasePolicy =
-                    databaseProvider.getPolicies(policyKey).getTopologyTemplate().getPolicies().get(policyKey);
-            assertEquals(incomingPolicy, databasePolicy);
+        for (Map<String, ToscaPolicy> policyMap : serviceTemplate.getToscaTopologyTemplate().getPolicies()) {
+            for (ToscaPolicy policy : policyMap.values()) {
+                ToscaServiceTemplate goToscaServiceTemplate =
+                        databaseProvider.getPolicies(policy.getName(), policy.getVersion());
+
+                assertEquals(goToscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0)
+                        .get(policy.getName()).getType(), policy.getType());
+            }
         }
     }
 }
index bd85358..f2b8676 100644 (file)
@@ -22,10 +22,8 @@ package org.onap.policy.models.provider.impl;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 
 import java.util.Base64;
@@ -35,16 +33,14 @@ import lombok.NonNull;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderFactory;
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.yaml.snakeyaml.Yaml;
@@ -58,7 +54,7 @@ public class PolicyToscaPersistenceTest {
     // Logger for this class
     private static final Logger LOGGER = LoggerFactory.getLogger(PolicyToscaPersistenceTest.class);
 
-    private Gson gson;
+    private StandardCoder standardCoder;
 
     private PolicyModelsProvider databaseProvider;
 
@@ -97,11 +93,11 @@ public class PolicyToscaPersistenceTest {
     }
 
     /**
-     * Set up GSON.
+     * Set up the standard coder.
      */
     @Before
-    public void setupGson() {
-        gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
+    public void setupStandardCoder() {
+        standardCoder = new StandardCoder();
     }
 
     @After
@@ -141,19 +137,18 @@ public class PolicyToscaPersistenceTest {
      * @throws Exception any exception thrown
      */
     public void testJsonStringPolicyPersistence(@NonNull final String policyString) throws Exception {
-        JpaToscaServiceTemplate serviceTemplate = gson.fromJson(policyString, JpaToscaServiceTemplate.class);
+        ToscaServiceTemplate serviceTemplate = standardCoder.decode(policyString, ToscaServiceTemplate.class);
 
         assertNotNull(serviceTemplate);
-        LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
-        assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
 
         databaseProvider.createPolicies(serviceTemplate);
 
-        for (PfConceptKey policyKey : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().keySet()) {
-            JpaToscaPolicy incomingPolicy = serviceTemplate.getTopologyTemplate().getPolicies().get(policyKey);
-            JpaToscaPolicy databasePolicy =
-                    databaseProvider.getPolicies(policyKey).getTopologyTemplate().getPolicies().get(policyKey);
-            assertEquals(incomingPolicy, databasePolicy);
+        for (String policyKey : serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).keySet()) {
+            ToscaPolicy incomingPolicy = serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey);
+            ToscaPolicy databasePolicy =
+                    databaseProvider.getPolicies(incomingPolicy.getName(), incomingPolicy.getVersion())
+                            .getToscaTopologyTemplate().getPolicies().get(0).get(policyKey);
+            assertEquals(incomingPolicy.getType(), databasePolicy.getType());
         }
     }
 }
index 13b4adf..4623b20 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -38,4 +39,17 @@ public class ToscaConstraint {
     private List<String> validValues;
 
     private String equal;
+
+    @SerializedName("greater_than")
+    private String greaterThan;
+
+    @SerializedName("greater_or_equal")
+    private String greaterOrEqual;
+
+    @SerializedName("less_than")
+    private String lessThan;
+
+    @SerializedName("less_or_equal")
+    private String lessOrEqual;
+
 }
index 9aae320..b07163b 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * 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.tosca.authorative.concepts;
 
-import com.google.gson.annotations.SerializedName;
+import java.util.List;
 import java.util.Map;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
 
 /**
  * Class to represent TOSCA data type matching input/output from/to client.
@@ -32,16 +35,10 @@ import lombok.Data;
  * @author Chenfei Gao (cgao@research.att.com)
  */
 @Data
-public class ToscaDataType {
-
-    @SerializedName("derived_from")
-    private String derivedFrom;
-
-    private String version;
-
-    private Map<String, String> metadata;
-
-    private String description;
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor
+public class ToscaDataType extends ToscaEntity {
+    private List<ToscaConstraint> constraints;
 
     private Map<String, ToscaProperty> properties;
 }
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java
new file mode 100644 (file)
index 0000000..a61f2a7
--- /dev/null
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Model
+ * ================================================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.authorative.concepts;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfNameVersion;
+
+/**
+ * Class to represent TOSCA data type matching input/output from/to client.
+ *
+ * @author Chenfei Gao (cgao@research.att.com)
+ */
+@Data
+@NoArgsConstructor
+public class ToscaEntity implements PfNameVersion {
+    private String name;
+
+    private String version;
+
+    @SerializedName("derived_from")
+    private String derivedFrom;
+
+    private Map<String, String> metadata;
+
+    private String description;
+
+    /**
+     * Copy COnstructor.
+     *
+     * @param copyObject object to copy from
+     */
+    public ToscaEntity(@NonNull ToscaEntity copyObject) {
+        this.name = copyObject.name;
+        this.version = copyObject.version;
+        this.derivedFrom = copyObject.derivedFrom;
+        this.description = copyObject.description;
+
+        if (copyObject.metadata != null) {
+            metadata = new LinkedHashMap<>();
+            for (final Entry<String, String> metadataEntry : copyObject.metadata.entrySet()) {
+                metadata.put(metadataEntry.getKey(), metadataEntry.getValue());
+            }
+        }
+    }
+
+}
index a3526f7..352dfa7 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -32,9 +33,12 @@ import lombok.Data;
  */
 @Data
 public class ToscaEntrySchema {
+    private String name;
 
     private String type;
 
+    private String typeVersion;
+
     private String description;
 
     private List<ToscaConstraint> constraints;
index e861606..38c6859 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,9 +25,13 @@ package org.onap.policy.models.tosca.authorative.concepts;
 
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.Map.Entry;
+
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
+import lombok.ToString;
 
 /**
  * Class to represent TOSCA policy matching input/output from/to client.
@@ -34,16 +39,13 @@ import lombok.NonNull;
  * @author Chenfei Gao (cgao@research.att.com)
  */
 @Data
+@EqualsAndHashCode(callSuper = true)
 @NoArgsConstructor
-public class ToscaPolicy {
-
+@ToString(callSuper = true)
+public class ToscaPolicy extends ToscaEntity {
     private String type;
 
-    private String version;
-
-    private String description;
-
-    private Map<String, String> metadata;
+    private String typeVersion;
 
     private Map<String, Object> properties;
 
@@ -53,10 +55,16 @@ public class ToscaPolicy {
      * @param copyObject the obejct to copy from.
      */
     public ToscaPolicy(@NonNull ToscaPolicy copyObject) {
+        super(copyObject);
+
         this.type = copyObject.type;
-        this.version = copyObject.version;
-        this.description = copyObject.description;
-        this.metadata = (metadata != null ? new LinkedHashMap<>(copyObject.metadata) : null);
-        this.properties = (properties != null ? new LinkedHashMap<>(copyObject.properties) : null);
+        this.typeVersion = copyObject.typeVersion;
+
+        if (copyObject.properties != null) {
+            properties = new LinkedHashMap<>();
+            for (final Entry<String, Object> propertyEntry : copyObject.properties.entrySet()) {
+                properties.put(propertyEntry.getKey(), propertyEntry.getValue());
+            }
+        }
     }
 }
index c46402b..d64a5fa 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * 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.tosca.authorative.concepts;
 
-import com.google.gson.annotations.SerializedName;
 import java.util.Map;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
 
 /**
  * Class to represent TOSCA policy type matching input/output from/to client.
@@ -32,16 +34,8 @@ import lombok.Data;
  * @author Chenfei Gao (cgao@research.att.com)
  */
 @Data
-public class ToscaPolicyType {
-
-    @SerializedName("derived_from")
-    private String derivedFrom;
-
-    private String version;
-
-    private Map<String, String> metadata;
-
-    private String description;
-
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor
+public class ToscaPolicyType extends ToscaEntity {
     private Map<String, ToscaProperty> properties;
 }
index 9eda83b..84f798b 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -33,18 +34,27 @@ import lombok.Data;
  */
 @Data
 public class ToscaProperty {
+    public enum Status {
+        SUPPORTED, UNSUPPORTED, EXPERIMENTAL, DEPRECATED
+    }
+
+    private String name;
 
     private String type;
 
-    private String description;
+    private String typeVersion;
 
-    private boolean required = false;
+    private String description;
 
     @SerializedName("default")
     private String defaultValue;
 
-    @SerializedName("entry_schema")
-    private ToscaEntrySchema entrySchema;
+    private boolean required = false;
+
+    private Status status;
 
     private List<ToscaConstraint> constraints;
+
+    @SerializedName("entry_schema")
+    private ToscaEntrySchema entrySchema;
 }
index 3d1b963..a9a1783 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,6 +27,7 @@ import com.google.gson.annotations.SerializedName;
 import java.util.List;
 import java.util.Map;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 
 /**
  * Class to represent TOSCA service template matching input/output from/to client.
@@ -33,7 +35,8 @@ import lombok.Data;
  * @author Chenfei Gao (cgao@research.att.com)
  */
 @Data
-public class ToscaServiceTemplate {
+@EqualsAndHashCode(callSuper = true)
+public class ToscaServiceTemplate extends ToscaEntity {
 
     @SerializedName("tosca_definitions_version")
     private String toscaDefinitionsVersion;
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapper.java
deleted file mode 100644 (file)
index cef8348..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * 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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.authorative.mapping;
-
-import com.google.gson.Gson;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.mapping.JpaToscaServiceTemplateMapper;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
-
-/**
- * This class maps a TOSCA service template from client input form to internal representation and vice verse.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- */
-public class PlainToscaServiceTemplateMapper
-        implements JpaToscaServiceTemplateMapper<ToscaServiceTemplate, ToscaServiceTemplate> {
-
-    private Gson defaultGson = new Gson();
-    private Gson customGson = new ToscaServiceTemplateMessageBodyHandler().getGson();
-
-    @Override
-    public JpaToscaServiceTemplate toToscaServiceTemplate(ToscaServiceTemplate otherPolicy) {
-
-        String serializedServiceTemplate = defaultGson.toJson(otherPolicy);
-        return customGson.fromJson(serializedServiceTemplate, JpaToscaServiceTemplate.class);
-
-    }
-
-    @Override
-    public ToscaServiceTemplate fromToscaServiceTemplate(JpaToscaServiceTemplate serviceTemplate) {
-
-        String serializedServiceTemplate = customGson.toJson(serviceTemplate);
-        return defaultGson.fromJson(serializedServiceTemplate, ToscaServiceTemplate.class);
-    }
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
new file mode 100644 (file)
index 0000000..e9e92d3
--- /dev/null
@@ -0,0 +1,253 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.authorative.provider;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.dao.PfDao;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
+
+/**
+ * This class provides the provision of information on TOSCA concepts in the database to callers.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class AuthorativeToscaProvider {
+    /**
+     * Get policy types.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the policy type to get.
+     * @param version the version of the policy type to get.
+     * @return the policy types found
+     * @throws PfModelException on errors getting policy types
+     */
+    public ToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, final String name, final String version)
+            throws PfModelException {
+
+        return new SimpleToscaProvider().getPolicyTypes(dao, new PfConceptKey(name, version)).toAuthorative();
+    }
+
+    /**
+     * Get policy types.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the policy type to get, set to null to get all policy types
+     * @param version the version of the policy type to get, set to null to get all versions
+     * @return the policy types found
+     * @throws PfModelException on errors getting policy types
+     */
+    public List<ToscaPolicyType> getPolicyTypeList(@NonNull final PfDao dao, final String name, final String version)
+            throws PfModelException {
+        return new ArrayList<>();
+    }
+
+    /**
+     * Get latest policy types.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the policy type to get, set to null to get all policy types
+     * @return the policy types found
+     * @throws PfModelException on errors getting policy types
+     */
+    public ToscaServiceTemplate getLatestPolicyTypes(@NonNull final PfDao dao, final String name)
+            throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Get latest policy types.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the policy type to get, set to null to get all policy types
+     * @return the policy types found
+     * @throws PfModelException on errors getting policy types
+     */
+    public List<ToscaPolicyType> getLatestPolicyTypeList(@NonNull final PfDao dao, final String name)
+            throws PfModelException {
+        return new ArrayList<>();
+    }
+
+    /**
+     * Create policy types.
+     *
+     * @param dao the DAO to use to access the database
+     * @param serviceTemplate the service template containing the definition of the policy types to be created
+     * @return the TOSCA service template containing the created policy types
+     * @throws PfModelException on errors creating policy types
+     */
+    public ToscaServiceTemplate createPolicyTypes(@NonNull final PfDao dao,
+            @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+
+        return new SimpleToscaProvider().createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate))
+                .toAuthorative();
+    }
+
+    /**
+     * Update policy types.
+     *
+     * @param dao the DAO to use to access the database
+     * @param serviceTemplate the service template containing the definition of the policy types to be modified
+     * @return the TOSCA service template containing the modified policy types
+     * @throws PfModelException on errors updating policy types
+     */
+    public ToscaServiceTemplate updatePolicyTypes(@NonNull final PfDao dao,
+            @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+
+        return new SimpleToscaProvider().updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate))
+                .toAuthorative();
+    }
+
+    /**
+     * Delete policy type.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the policy type to delete.
+     * @param version the version of the policy type to delete.
+     * @return the TOSCA service template containing the policy type that was deleted
+     * @throws PfModelException on errors deleting policy types
+     */
+    public ToscaServiceTemplate deletePolicyType(@NonNull final PfDao dao, @NonNull final String name,
+            @NonNull final String version) throws PfModelException {
+
+        return new SimpleToscaProvider().deletePolicyType(dao, new PfConceptKey(name, version)).toAuthorative();
+    }
+
+    /**
+     * Get policies.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the policy to get.
+     * @param version the version of the policy to get.
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, @NonNull final String name,
+            @NonNull final String version) throws PfModelException {
+
+        return new SimpleToscaProvider().getPolicies(dao, new PfConceptKey(name, version)).toAuthorative();
+    }
+
+    /**
+     * Get policies.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the policy to get, null to get all policies
+     * @param version the version of the policy to get, null to get all versions of a policy
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public List<ToscaPolicy> getPolicyList(@NonNull final PfDao dao, final String name, final String version)
+            throws PfModelException {
+        return new ArrayList<>();
+    }
+
+    /**
+     * Get policies for a policy type name.
+     *
+     * @param dao the DAO to use to access the database
+     * @param policyTypeName the name of the policy type for which to get policies
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final PfDao dao, @NonNull final String policyTypeName)
+            throws PfModelException {
+        return new ArrayList<>();
+    }
+
+    /**
+     * Get latest policies.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the policy to get, null to get all policies
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public ToscaServiceTemplate getLatestPolicies(@NonNull final PfDao dao, final String name) throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Get latest policies.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the policy to get, null to get all policies
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public List<ToscaPolicy> getLatestPolicyList(@NonNull final PfDao dao, final String name) throws PfModelException  {
+        return new ArrayList<>();
+    }
+
+    /**
+     * Create policies.
+     *
+     * @param dao the DAO to use to access the database
+     * @param serviceTemplate the service template containing the definitions of the new policies to be created.
+     * @return the TOSCA service template containing the policy types that were created
+     * @throws PfModelException on errors creating policies
+     */
+    public ToscaServiceTemplate createPolicies(@NonNull final PfDao dao,
+            @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+
+        return new SimpleToscaProvider().createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate))
+                .toAuthorative();
+    }
+
+    /**
+     * Update policies.
+     *
+     * @param dao the DAO to use to access the database
+     * @param serviceTemplate the service template containing the definitions of the policies to be updated.
+     * @return the TOSCA service template containing the policies that were updated
+     * @throws PfModelException on errors updating policies
+     */
+    public ToscaServiceTemplate updatePolicies(@NonNull final PfDao dao,
+            @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+
+        return new SimpleToscaProvider().updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate))
+                .toAuthorative();
+    }
+
+    /**
+     * Delete policy.
+     *
+     * @param dao the DAO to use to access the database
+     * @param name the name of the policy to delete.
+     * @param version the version of the policy to delete.
+     * @return the TOSCA service template containing the policy that weas deleted
+     * @throws PfModelException on errors deleting policies
+     */
+    public ToscaServiceTemplate deletePolicy(@NonNull final PfDao dao, @NonNull final String name,
+            @NonNull final String version) throws PfModelException {
+
+        return new SimpleToscaProvider().deletePolicy(dao, new PfConceptKey(name, version)).toAuthorative();
+    }
+}
index bde53c3..fad227c 100644 (file)
 
 package org.onap.policy.models.tosca.simple.concepts;
 
-import java.util.List;
+import java.io.Serializable;
 
-import javax.persistence.EmbeddedId;
-import javax.ws.rs.core.Response;
-
-import lombok.Data;
 import lombok.EqualsAndHashCode;
-import lombok.NonNull;
+import lombok.NoArgsConstructor;
 
-import org.onap.policy.models.base.PfConcept;
-import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.base.PfAuthorative;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
 
 /**
  * Immutable class to represent the Constraint of property in TOSCA definition.
@@ -46,80 +37,37 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
  * @author Chenfei Gao (cgao@research.att.com)
  * @author Liam Fallon (liam.fallon@est.tech)
  */
-@Data
-@EqualsAndHashCode(callSuper = false)
-public abstract class JpaToscaConstraint extends PfConcept {
-    private static final long serialVersionUID = 6426438089914347734L;
-
-    @EmbeddedId
-    private final PfReferenceKey key;
+@NoArgsConstructor
+@EqualsAndHashCode
+public abstract class JpaToscaConstraint
+        implements PfAuthorative<ToscaConstraint>, Serializable, Comparable<JpaToscaConstraint> {
+    private static final long serialVersionUID = -2689472945262507455L;
 
     /**
-     * The Default Constructor creates a {@link JpaToscaConstraint} object with a null key.
+     * Authorative constructor.
+     *
+     * @param authorativeConcept the authorative concept to copy from
      */
-    public JpaToscaConstraint() {
-        this(new PfReferenceKey());
+    public JpaToscaConstraint(final ToscaConstraint authorativeConcept) {
+        this.fromAuthorative(authorativeConcept);
     }
 
-    /**
-     * The Key Constructor creates a {@link JpaToscaConstraint} object with the given concept key.
-     *
-     * @param key the key
-     */
-    public JpaToscaConstraint(@NonNull final PfReferenceKey key) {
-        this.key = key;
+    @Override
+    public int compareTo(JpaToscaConstraint otherConstraint) {
+        return 0;
     }
 
     /**
-     * Copy constructor.
+     * Create instances of constraints of various types.
      *
-     * @param copyConcept the concept to copy from
+     * @param toscaConstraint the incoming constraint
+     * @return the constraint
      */
-    public JpaToscaConstraint(@NonNull final JpaToscaConstraint copyConcept) {
-        throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
-    }
-
-    @Override
-    public List<PfKey> getKeys() {
-        return getKey().getKeys();
-    }
-
-    @Override
-    public void clean() {
-        key.clean();
-    }
-
-    @Override
-    public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
-        PfValidationResult result = resultIn;
-
-        if (key.isNullKey()) {
-            result.addValidationMessage(
-                    new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
-        }
-
-        return key.validate(result);
-    }
-
-    @Override
-    public int compareTo(final PfConcept otherConcept) {
-        if (otherConcept == null) {
-            return -1;
-        }
-        if (this == otherConcept) {
-            return 0;
+    public static JpaToscaConstraint newInstance(final ToscaConstraint toscaConstraint) {
+        if (toscaConstraint.getValidValues() != null) {
+            return new JpaToscaConstraintValidValues(toscaConstraint);
         }
-        if (getClass() != otherConcept.getClass()) {
-            return this.hashCode() - otherConcept.hashCode();
-        }
-
-        final JpaToscaConstraint other = (JpaToscaConstraint) otherConcept;
 
-        return key.compareTo(other.key);
-    }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+        return (new JpaToscaConstraintLogical(toscaConstraint));
     }
 }
index 231e261..9841cbe 100644 (file)
 package org.onap.policy.models.tosca.simple.concepts;
 
 import javax.persistence.Column;
-import javax.ws.rs.core.Response;
 
 import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.NonNull;
 import lombok.ToString;
 
-import org.onap.policy.models.base.PfConcept;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.base.PfReferenceKey;
+import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
 
 /**
  * This class represents a logical TOSCA constraint: =,>,>=,<,<=.
@@ -38,82 +36,117 @@ import org.onap.policy.models.base.PfReferenceKey;
 @EqualsAndHashCode(callSuper = false)
 @ToString
 public class JpaToscaConstraintLogical extends JpaToscaConstraint {
-    private static final long serialVersionUID = 2562306457768745444L;
-
-    public enum Operation {
-        EQ,
-        GT,
-        GE,
-        LT,
-        LE
-    }
+    private static final long serialVersionUID = -2730203215911880756L;
 
     @Column
     @NonNull
     @Getter
-    private final Operation operation;
+    private JpaToscaConstraintOperation operation;
 
-    /**
-     * The Default Constructor creates a {@link JpaToscaConstraintLogical} object with a null key.
-     */
-    public JpaToscaConstraintLogical() {
-        this(new PfReferenceKey());
-    }
+    @Column
+    @NonNull
+    @Getter
+    private String compareTo;
 
     /**
-     * The Key Constructor creates a {@link JpaToscaConstraintLogical} object with the given concept key.
+     * Constructor to set operation.
      *
-     * @param key the key of the constraint
+     * @param operation the operation to set
+     * @param compareTo the string to compare to
      */
-    public JpaToscaConstraintLogical(final PfReferenceKey key) {
-        this(key, Operation.EQ);
+    public JpaToscaConstraintLogical(@NonNull final JpaToscaConstraintOperation operation,
+            @NonNull final String compareTo) {
+        this.operation = operation;
+        this.compareTo = compareTo;
     }
 
     /**
-     * The Key Constructor creates a {@link JpaToscaConstraintLogical} object with the given concept key and operation.
-     *
-     * @param key the key of the constraint
-     * @param operation the logical operation of the constraint
+     * Authorative constructor.
      *
+     * @param authorativeConcept the authorative concept to copy from
      */
-    public JpaToscaConstraintLogical(final PfReferenceKey key, @NonNull final Operation operation) {
-        super(key);
-        this.operation = operation;
+    public JpaToscaConstraintLogical(final ToscaConstraint authorativeConcept) {
+        super(authorativeConcept);
     }
 
-    /**
-     * Copy constructor.
-     *
-     * @param copyConcept the concept to copy from
-     */
-    public JpaToscaConstraintLogical(@NonNull final JpaToscaConstraintLogical copyConcept) {
-        throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+    @Override
+    public ToscaConstraint toAuthorative() {
+        ToscaConstraint toscaConstraint = new ToscaConstraint();
+
+        switch (operation) {
+            case EQ: {
+                toscaConstraint.setEqual(compareTo);
+                break;
+            }
+            case GT: {
+                toscaConstraint.setGreaterThan(compareTo);
+                break;
+            }
+            case GE: {
+                toscaConstraint.setGreaterOrEqual(compareTo);
+                break;
+            }
+            case LT: {
+                toscaConstraint.setLessThan(compareTo);
+                break;
+            }
+            case LE: {
+                toscaConstraint.setLessOrEqual(compareTo);
+                break;
+            }
+            default: {
+                // Can't happen
+            }
+        }
+
+        return toscaConstraint;
     }
 
     @Override
-    public int compareTo(final PfConcept otherConcept) {
-        if (otherConcept == null) {
+    public void fromAuthorative(final ToscaConstraint toscaConstraint) {
+        // @formatter:off
+        if (toscaConstraint.getEqual() != null) {
+            operation = JpaToscaConstraintOperation.EQ;
+            compareTo = toscaConstraint.getEqual();
+        }
+        else if (toscaConstraint.getGreaterThan() != null) {
+            operation = JpaToscaConstraintOperation.GT;
+            compareTo = toscaConstraint.getGreaterThan();
+        }
+        else if (toscaConstraint.getGreaterOrEqual() != null) {
+            operation = JpaToscaConstraintOperation.GE;
+            compareTo = toscaConstraint.getGreaterOrEqual();
+        }
+        else if (toscaConstraint.getLessThan() != null) {
+            operation = JpaToscaConstraintOperation.LT;
+            compareTo = toscaConstraint.getLessThan();
+        }
+        else if (toscaConstraint.getLessOrEqual() != null) {
+            operation = JpaToscaConstraintOperation.LE;
+            compareTo = toscaConstraint.getLessOrEqual();
+        }
+        // @formatter:on
+    }
+
+    @Override
+    public int compareTo(JpaToscaConstraint otherConstraint) {
+        if (otherConstraint == null) {
             return -1;
         }
-        if (this == otherConcept) {
+        if (this == otherConstraint) {
             return 0;
         }
-        if (getClass() != otherConcept.getClass()) {
-            return this.hashCode() - otherConcept.hashCode();
+        if (getClass() != otherConstraint.getClass()) {
+            return this.hashCode() - otherConstraint.hashCode();
         }
 
-        final JpaToscaConstraintLogical other = (JpaToscaConstraintLogical) otherConcept;
+        final JpaToscaConstraintLogical other = (JpaToscaConstraintLogical) otherConstraint;
 
-        int result = super.compareTo(other);
+        int result = ObjectUtils.compare(operation, other.operation);
         if (result != 0) {
             return result;
         }
 
-        return operation.compareTo(other.operation);
-    }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+        return ObjectUtils.compare(compareTo, other.compareTo);
     }
 }
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKey.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKey.java
deleted file mode 100644 (file)
index 13902db..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.concepts;
-
-import java.util.List;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Inheritance;
-import javax.persistence.InheritanceType;
-import javax.persistence.Table;
-import javax.ws.rs.core.Response;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.NonNull;
-import lombok.ToString;
-
-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.PfModelRuntimeException;
-import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
-
-/**
- * This immutable class represents a logical TOSCA constraint: =,>,>=,<,<= that compares the owner
- * of an instance of the class to the referenced key.
- */
-@Entity
-@Table(name = "ToscaConstraintLogicalKey")
-@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
-@EqualsAndHashCode(callSuper = false)
-@ToString
-public final class JpaToscaConstraintLogicalKey extends JpaToscaConstraintLogical {
-    private static final long serialVersionUID = -2420828090326264341L;
-
-    @Column
-    @NonNull
-    @Getter
-    private final PfKey compareToKey;
-
-    /**
-     * The Default Constructor creates a {@link JpaToscaConstraintLogicalKey} object with a null key.
-     */
-    public JpaToscaConstraintLogicalKey() {
-        this(new PfReferenceKey());
-    }
-
-    /**
-     * The Key Constructor creates a {@link JpaToscaConstraintLogicalKey} object with the given concept
-     * key.
-     *
-     * @param key the key of the constraint
-     */
-    public JpaToscaConstraintLogicalKey(final PfReferenceKey key) {
-        this(key, Operation.EQ, PfConceptKey.getNullKey());
-    }
-
-    /**
-     * The Key Constructor creates a {@link JpaToscaConstraintLogicalKey} object with the given concept
-     * key, operation, and compare key.
-     *
-     * @param key the key of the constraint
-     * @param operation the logical operation of the constraint
-     * @param compareToKey the key of the object to which the object that owns this constraint will
-     *        be compared
-     */
-    public JpaToscaConstraintLogicalKey(final PfReferenceKey key, @NonNull final Operation operation,
-            @NonNull final PfKey compareToKey) {
-        super(key, operation);
-        this.compareToKey = compareToKey;
-    }
-
-    /**
-     * Copy constructor.
-     *
-     * @param copyConcept the concept to copy from
-     */
-    public JpaToscaConstraintLogicalKey(@NonNull final JpaToscaConstraintLogical copyConcept) {
-        throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
-    }
-
-    @Override
-    public List<PfKey> getKeys() {
-        final List<PfKey> keyList = super.getKeys();
-        keyList.addAll(compareToKey.getKeys());
-        return keyList;
-    }
-
-    @Override
-    public void clean() {
-        super.clean();
-        compareToKey.clean();
-    }
-
-    @Override
-    public PfValidationResult validate(final PfValidationResult resultIn) {
-        PfValidationResult result = super.validate(resultIn);
-
-        if (compareToKey.isNullKey()) {
-            result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
-                    "comparison key is a null key"));
-        }
-
-        return result;
-    }
-
-    @Override
-    public int compareTo(final PfConcept otherConcept) {
-        if (otherConcept == null) {
-            return -1;
-        }
-        if (this == otherConcept) {
-            return 0;
-        }
-        if (getClass() != otherConcept.getClass()) {
-            return this.hashCode() - otherConcept.hashCode();
-        }
-
-        final JpaToscaConstraintLogicalKey other = (JpaToscaConstraintLogicalKey) otherConcept;
-
-        int result = super.compareTo(other);
-        if (result != 0) {
-            return result;
-        }
-
-        return compareToKey.compareTo(other.compareToKey);
-    }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
-    }
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalString.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalString.java
deleted file mode 100644 (file)
index 5121273..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.concepts;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Inheritance;
-import javax.persistence.InheritanceType;
-import javax.persistence.Table;
-import javax.ws.rs.core.Response;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.NonNull;
-
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
-import org.onap.policy.models.base.PfConcept;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
-
-/**
- * This class represents a logical TOSCA constraint: =,>,>=,<,<= that compares the owner of an
- * instance of the class to the given string.
- */
-@Entity
-@Table(name = "ToscaConstraintLogicalString")
-@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
-@EqualsAndHashCode(callSuper = false)
-public class JpaToscaConstraintLogicalString extends JpaToscaConstraintLogical {
-    private static final long serialVersionUID = 8167550632122339195L;
-
-    @Column
-    @NonNull
-    @Getter
-    private final String compareToString;
-
-    /**
-     * The Default Constructor creates a {@link JpaToscaConstraintLogicalString} object with a null key.
-     */
-    public JpaToscaConstraintLogicalString() {
-        this(new PfReferenceKey());
-    }
-
-    /**
-     * The Key Constructor creates a {@link JpaToscaConstraintLogicalString} object with the given concept
-     * key.
-     *
-     * @param key the key of the constraint
-     */
-    public JpaToscaConstraintLogicalString(final PfReferenceKey key) {
-        this(key, Operation.EQ, "");
-    }
-
-    /**
-     * The Key Constructor creates a {@link JpaToscaConstraintLogicalString} object with the given concept
-     * key, operation, and compare string.
-     *
-     * @param key the key of the constraint
-     * @param operation the logical operation of the constraint
-     * @param compareToString the key of the object to which the object that owns this constraint will
-     *        be compared
-     */
-    public JpaToscaConstraintLogicalString(final PfReferenceKey key, @NonNull final Operation operation,
-            @NonNull final String compareToString) {
-        super(key, operation);
-        this.compareToString = compareToString.trim();
-    }
-
-    /**
-     * Copy constructor.
-     *
-     * @param copyConcept the concept to copy from
-     */
-    public JpaToscaConstraintLogicalString(@NonNull final JpaToscaConstraintLogical copyConcept) {
-        throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
-    }
-
-    @Override
-    public PfValidationResult validate(final PfValidationResult resultIn) {
-        PfValidationResult result = super.validate(resultIn);
-
-        if (!ParameterValidationUtils.validateStringParameter(compareToString)) {
-            result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
-                    "comparison string is null or blank"));
-        }
-
-        return result;
-    }
-
-    @Override
-    public int compareTo(final PfConcept otherConcept) {
-        if (otherConcept == null) {
-            return -1;
-        }
-        if (this == otherConcept) {
-            return 0;
-        }
-        if (getClass() != otherConcept.getClass()) {
-            return this.hashCode() - otherConcept.hashCode();
-        }
-
-        final JpaToscaConstraintLogicalString other = (JpaToscaConstraintLogicalString) otherConcept;
-
-        int result = super.compareTo(other);
-        if (result != 0) {
-            return result;
-        }
-
-        return compareToString.compareTo(other.compareToString);
-    }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
-    }
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintOperation.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintOperation.java
new file mode 100644 (file)
index 0000000..0422ae2
--- /dev/null
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.concepts;
+
+/**
+ * ENUM for TOSCA constraint operations.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public enum JpaToscaConstraintOperation {
+    // @formatter:off
+    EQ("equal_to"),
+    GT("greater_than"),
+    GE("greater_or_equal"),
+    LT("less_than"),
+    LE("less_or_equal");
+    // @formatter:on
+
+    private final String toscaToken;
+
+    private JpaToscaConstraintOperation(final String toscaToken) {
+        this.toscaToken = toscaToken;
+    }
+
+    public String getToscaToken() {
+        return toscaToken;
+    }
+}
index 608605f..248ca49 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * 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.tosca.simple.concepts;
 
-import com.google.gson.annotations.SerializedName;
-
-import java.util.LinkedList;
+import java.util.ArrayList;
 import java.util.List;
 import javax.persistence.ElementCollection;
-import javax.ws.rs.core.Response;
 
-import lombok.Data;
 import lombok.EqualsAndHashCode;
+import lombok.Getter;
 import lombok.NonNull;
+import lombok.ToString;
 
-import org.onap.policy.models.base.PfConcept;
-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.tosca.authorative.concepts.ToscaConstraint;
 
 /**
  * This class represents valid_values TOSCA constraint.
@@ -41,81 +39,64 @@ import org.onap.policy.models.base.PfReferenceKey;
  * @author Chenfei Gao (cgao@research.att.com)
  */
 @EqualsAndHashCode(callSuper = false)
-@Data
+@ToString
 public class JpaToscaConstraintValidValues extends JpaToscaConstraint {
-    private static final long serialVersionUID = 3152323457560746844L;
+    private static final long serialVersionUID = -5060193250508635456L;
 
-    @SerializedName("valid_values")
-    @NonNull
     @ElementCollection
-    private final List<String> validValues;
+    @NonNull
+    @Getter
+    private List<String> validValues;
 
     /**
-     * The Default Constructor creates a {@link JpaToscaConstraintValidValues} object with a null key.
+     * Constructor to set the valid values.
+     *
+     * @param validValues the valid values that are allowed
      */
-    public JpaToscaConstraintValidValues() {
-        this(new PfReferenceKey());
+    public JpaToscaConstraintValidValues(@NonNull final List<String> validValues) {
+        this.validValues = validValues;
     }
 
     /**
-     * The Key Constructor creates a {@link JpaToscaConstraintValidValues} object with the given concept key.
+     * Authorative constructor.
      *
-     * @param key the key of the constraint
+     * @param authorativeConcept the authorative concept to copy from
      */
-    public JpaToscaConstraintValidValues(final PfReferenceKey key) {
-        super(key);
-        validValues = new LinkedList<>();
+    public JpaToscaConstraintValidValues(final ToscaConstraint authorativeConcept) {
+        super(authorativeConcept);
     }
 
-    /**
-     * The Key Constructor creates a {@link JpaToscaConstraintLogical} object with the given concept key
-     * and valid values list.
-     *
-     * @param key the key of the constraint
-     * @param validValues the valid values list of the constraint
-     *
-     */
-    public JpaToscaConstraintValidValues(final PfReferenceKey key, @NonNull final List<String> validValues) {
-        super(key);
-        this.validValues = validValues;
+    @Override
+    public ToscaConstraint toAuthorative() {
+        ToscaConstraint toscaConstraint = new ToscaConstraint();
+
+        toscaConstraint.setValidValues(validValues);
+
+        return toscaConstraint;
     }
 
-    /**
-     * Copy constructor.
-     *
-     * @param copyConcept the concept to copy from
-     */
-    public JpaToscaConstraintValidValues(@NonNull final JpaToscaConstraintValidValues copyConcept) {
-        throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+    @Override
+    public void fromAuthorative(final ToscaConstraint toscaConstraint) {
+        if (toscaConstraint.getValidValues() != null) {
+            validValues = new ArrayList<>();
+            validValues.addAll(toscaConstraint.getValidValues());
+        }
     }
 
     @Override
-    public int compareTo(final PfConcept otherConcept) {
-        if (otherConcept == null) {
+    public int compareTo(JpaToscaConstraint otherConstraint) {
+        if (otherConstraint == null) {
             return -1;
         }
-        if (this == otherConcept) {
+        if (this == otherConstraint) {
             return 0;
         }
-        if (getClass() != otherConcept.getClass()) {
-            return this.hashCode() - otherConcept.hashCode();
-        }
-
-        final JpaToscaConstraintValidValues other = (JpaToscaConstraintValidValues) otherConcept;
-
-        int result = super.compareTo(other);
-        if (result != 0) {
-            return result;
+        if (getClass() != otherConstraint.getClass()) {
+            return this.hashCode() - otherConstraint.hashCode();
         }
 
-        if (validValues.equals(other.validValues)) {
-            return 0;
-        }
-        return -1;
-    }
+        final JpaToscaConstraintValidValues other = (JpaToscaConstraintValidValues) otherConstraint;
 
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+        return PfUtils.compareObjects(validValues, other.validValues);
     }
 }
index 0035eb0..cf1150a 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;
@@ -37,13 +40,18 @@ 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;
 import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.base.PfValidationMessage;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
 
 /**
  * Class to represent custom data type in TOSCA definition.
@@ -56,14 +64,14 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = true)
-public class JpaToscaDataType extends JpaToscaEntityType {
+public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implements PfAuthorative<ToscaDataType> {
     private static final long serialVersionUID = -3922690413436539164L;
 
     @ElementCollection
     private List<JpaToscaConstraint> constraints;
 
     @ElementCollection
-    private List<JpaToscaProperty> properties;
+    private Map<String, JpaToscaProperty> properties;
 
     /**
      * The Default Constructor creates a {@link JpaToscaDataType} object with a null key.
@@ -90,18 +98,72 @@ public class JpaToscaDataType extends JpaToscaEntityType {
         super(copyConcept);
     }
 
+    /**
+     * Authorative constructor.
+     *
+     * @param authorativeConcept the authorative concept to copy from
+     */
+    public JpaToscaDataType(final ToscaDataType authorativeConcept) {
+        this.fromAuthorative(authorativeConcept);
+    }
+
     @Override
-    public List<PfKey> getKeys() {
-        final List<PfKey> keyList = super.getKeys();
+    public ToscaDataType toAuthorative() {
+        ToscaDataType toscaDataType = new ToscaDataType();
+        super.setToscaEntity(toscaDataType);
+        super.toAuthorative();
 
         if (constraints != null) {
+            List<ToscaConstraint> toscaConstraints = new ArrayList<>();
+
             for (JpaToscaConstraint constraint : constraints) {
-                keyList.addAll(constraint.getKeys());
+                toscaConstraints.add(constraint.toAuthorative());
             }
+
+            toscaDataType.setConstraints(toscaConstraints);
         }
 
         if (properties != null) {
-            for (JpaToscaProperty property : properties) {
+            Map<String, ToscaProperty> propertyMap = new LinkedHashMap<>();
+
+            for (Entry<String, JpaToscaProperty> entry : properties.entrySet()) {
+                propertyMap.put(entry.getKey(), entry.getValue().toAuthorative());
+            }
+
+            toscaDataType.setProperties(propertyMap);
+        }
+
+        return toscaDataType;
+    }
+
+    @Override
+    public void fromAuthorative(final ToscaDataType toscaDataType) {
+        super.fromAuthorative(toscaDataType);
+
+        if (toscaDataType.getConstraints() != null) {
+            constraints = new ArrayList<>();
+
+            for (ToscaConstraint toscaConstraint: toscaDataType.getConstraints()) {
+                constraints.add(JpaToscaConstraint.newInstance(toscaConstraint));
+            }
+        }
+
+        if (toscaDataType.getProperties() != null) {
+            properties = new LinkedHashMap<>();
+            for (Entry<String, ToscaProperty> toscaPropertyEntry : toscaDataType.getProperties().entrySet()) {
+                JpaToscaProperty jpaProperty = new JpaToscaProperty(toscaPropertyEntry.getValue());
+                jpaProperty.setKey(new PfReferenceKey(getKey(), toscaPropertyEntry.getKey()));
+                properties.put(toscaPropertyEntry.getKey(), jpaProperty);
+            }
+        }
+    }
+
+    @Override
+    public List<PfKey> getKeys() {
+        final List<PfKey> keyList = super.getKeys();
+
+        if (properties != null) {
+            for (JpaToscaProperty property : properties.values()) {
                 keyList.addAll(property.getKeys());
             }
         }
@@ -113,14 +175,8 @@ public class JpaToscaDataType extends JpaToscaEntityType {
     public void clean() {
         super.clean();
 
-        if (constraints != null) {
-            for (JpaToscaConstraint constraint : constraints) {
-                constraint.clean();
-            }
-        }
-
         if (properties != null) {
-            for (JpaToscaProperty property : properties) {
+            for (JpaToscaProperty property : properties.values()) {
                 property.clean();
             }
         }
@@ -154,8 +210,6 @@ public class JpaToscaDataType extends JpaToscaEntityType {
             if (constraint == null) {
                 result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
                         "data type constraint may not be null "));
-            } else {
-                result = constraint.validate(result);
             }
         }
         return result;
@@ -170,7 +224,7 @@ public class JpaToscaDataType extends JpaToscaEntityType {
     private PfValidationResult validateProperties(final PfValidationResult resultIn) {
         PfValidationResult result = resultIn;
 
-        for (JpaToscaProperty property : properties) {
+        for (JpaToscaProperty property : properties.values()) {
             if (property == null) {
                 result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
                         "data type property may not be null "));
@@ -221,8 +275,7 @@ public class JpaToscaDataType extends JpaToscaEntityType {
 
         if (constraints == null) {
             copy.setConstraints(null);
-        }
-        else {
+        } else {
             final List<JpaToscaConstraint> newConstraints = new ArrayList<>();
             for (final JpaToscaConstraint constraint : constraints) {
                 newConstraints.add(constraint); // Constraints are immutable
@@ -232,15 +285,14 @@ public class JpaToscaDataType extends JpaToscaEntityType {
 
         if (properties == null) {
             copy.setProperties(null);
-        }
-        else {
-            final List<JpaToscaProperty> newProperties = new ArrayList<>();
-            for (final JpaToscaProperty property : properties) {
-                newProperties.add(new JpaToscaProperty(property));
+        } 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;
     }
-}
\ No newline at end of file
+}
index 7fedd06..67d4ecf 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.policy.models.tosca.simple.concepts;
 
+import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -33,6 +34,7 @@ import lombok.EqualsAndHashCode;
 
 import org.onap.policy.models.base.PfConceptContainer;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
 
 /**
  * This class is a container for TOSCA data types.
@@ -44,23 +46,23 @@ import org.onap.policy.models.base.PfConceptKey;
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = true)
-public class JpaToscaDataTypes extends PfConceptContainer<JpaToscaDataType> {
+public class JpaToscaDataTypes extends PfConceptContainer<JpaToscaDataType, ToscaDataType> {
     private static final long serialVersionUID = 2941102271022190348L;
 
     public static final String DEFAULT_NAME = "ToscaDataTypesSimple";
     public static final String DEFAULT_VERSION = "1.0.0";
 
     /**
-     * The Default Constructor creates a {@link JpaToscaDataTypes} object with a null artifact key
-     * and creates an empty concept map.
+     * The Default Constructor creates a {@link JpaToscaDataTypes} object with a null artifact key and creates an empty
+     * concept map.
      */
     public JpaToscaDataTypes() {
         super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
     }
 
     /**
-     * The Key Constructor creates a {@link JpaToscaDataTypes} object with the given artifact key
-     * and creates an empty concept map.
+     * The Key Constructor creates a {@link JpaToscaDataTypes} object with the given artifact key and creates an empty
+     * concept map.
      *
      * @param key the concept key
      */
@@ -86,4 +88,13 @@ public class JpaToscaDataTypes extends PfConceptContainer<JpaToscaDataType> {
     public JpaToscaDataTypes(final JpaToscaDataTypes copyConcept) {
         super(copyConcept);
     }
+
+    /**
+     * Authorative constructor.
+     *
+     * @param authorativeConceptMapList the authorative concept to copy from
+     */
+    public JpaToscaDataTypes(final List<Map<String, ToscaDataType>> authorativeConceptMapList) {
+        this.fromAuthorative(authorativeConceptMapList);
+    }
 }
index e7d51a5..f2ab246 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.policy.models.tosca.simple.concepts;
 
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -39,6 +40,7 @@ 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;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfKey;
@@ -46,6 +48,7 @@ import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.base.PfValidationMessage;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
 
 /**
  * Class to represent the EntrySchema of list/map property in TOSCA definition.
@@ -53,7 +56,7 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 @MappedSuperclass
 @Data
 @EqualsAndHashCode(callSuper = false)
-public class JpaToscaEntityType extends PfConcept {
+public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept implements PfAuthorative<T> {
     private static final long serialVersionUID = -1330661834220739393L;
 
     @EmbeddedId
@@ -74,6 +77,8 @@ public class JpaToscaEntityType extends PfConcept {
 
     @Column
     private String description;
+
+    private transient T toscaEntity;
     // @formatter:on
 
     /**
@@ -97,10 +102,81 @@ public class JpaToscaEntityType extends PfConcept {
      *
      * @param copyConcept the concept to copy from
      */
-    public JpaToscaEntityType(final JpaToscaEntityType copyConcept) {
+    public JpaToscaEntityType(final JpaToscaEntityType<T> copyConcept) {
         super(copyConcept);
     }
 
+    /**
+     * Authorative constructor.
+     *
+     * @param authorativeConcept the authorative concept to copy from
+     */
+    public JpaToscaEntityType(final T authorativeConcept) {
+        this.fromAuthorative(authorativeConcept);
+    }
+
+    @Override
+    public T toAuthorative() {
+        toscaEntity.setName(getKey().getName());
+        toscaEntity.setVersion(getKey().getVersion());
+
+        if (derivedFrom != null) {
+            toscaEntity.setDerivedFrom(derivedFrom.getId());
+        }
+
+        if (description != null) {
+            toscaEntity.setDescription(description);
+        }
+
+        if (metadata != null) {
+            Map<String, String> metadataMap = new LinkedHashMap<>();
+
+            for (Entry<String, String> entry : metadata.entrySet()) {
+                metadataMap.put(entry.getKey(), entry.getValue());
+            }
+
+            toscaEntity.setMetadata(metadataMap);
+        }
+
+        return toscaEntity;
+    }
+
+    @Override
+    public void fromAuthorative(T toscaEntity) {
+        key =  new PfConceptKey();
+
+        if (toscaEntity.getName() != null) {
+            key.setName(toscaEntity.getName());
+        }
+
+        if (toscaEntity.getVersion() != null) {
+            key.setVersion(toscaEntity.getVersion());
+        }
+
+
+        if (toscaEntity.getDerivedFrom() != null) {
+            // CHeck if the derived from field contains a name-version ID
+            if (toscaEntity.getDerivedFrom().contains(":")) {
+                derivedFrom = new PfConceptKey(toscaEntity.getDerivedFrom());
+            }
+            else {
+                derivedFrom = new PfConceptKey(toscaEntity.getDerivedFrom(), PfKey.NULL_KEY_VERSION);
+            }
+        }
+
+        if (toscaEntity.getDescription() != null) {
+            description = toscaEntity.getDescription();
+        }
+
+        if (toscaEntity.getMetadata() != null) {
+            metadata = new LinkedHashMap<>();
+
+            for (Entry<String, String> metadataEntry : toscaEntity.getMetadata().entrySet()) {
+                metadata.put(metadataEntry.getKey(), metadataEntry.getValue());
+            }
+        }
+    }
+
     @Override
     public List<PfKey> getKeys() {
         final List<PfKey> keyList = getKey().getKeys();
@@ -176,7 +252,8 @@ public class JpaToscaEntityType extends PfConcept {
             return this.hashCode() - otherConcept.hashCode();
         }
 
-        final JpaToscaEntityType other = (JpaToscaEntityType) otherConcept;
+        @SuppressWarnings("unchecked")
+        final JpaToscaEntityType<T> other = (JpaToscaEntityType<T>) otherConcept;
         if (!key.equals(other.key)) {
             return key.compareTo(other.key);
         }
@@ -199,7 +276,8 @@ public class JpaToscaEntityType extends PfConcept {
         final Object copyObject = target;
         Assertions.instanceOf(copyObject, PfConcept.class);
 
-        final JpaToscaEntityType copy = ((JpaToscaEntityType) copyObject);
+        @SuppressWarnings("unchecked")
+        final JpaToscaEntityType<T> copy = ((JpaToscaEntityType<T>) copyObject);
         copy.setKey(new PfConceptKey(key));
         copy.setDerivedFrom(derivedFrom != null ? new PfConceptKey(derivedFrom) : null);
 
index e5ae20e..1177368 100644 (file)
 
 package org.onap.policy.models.tosca.simple.concepts;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
 import javax.persistence.Column;
 import javax.persistence.ElementCollection;
-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.NoArgsConstructor;
 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.PfAuthorative;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.base.PfValidationMessage;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaEntrySchema;
 
 
 /**
@@ -56,17 +54,13 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
  * @author Chenfei Gao (cgao@research.att.com)
  * @author Liam Fallon (liam.fallon@est.tech)
  */
-@Entity
-@Table(name = "ToscaEntrySchema")
-@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = false)
-public class JpaToscaEntrySchema extends PfConcept {
+@NoArgsConstructor
+public class JpaToscaEntrySchema
+        implements PfAuthorative<ToscaEntrySchema>, Serializable, Comparable<JpaToscaEntrySchema> {
     private static final long serialVersionUID = 3645882081163287058L;
 
-    @EmbeddedId
-    private PfReferenceKey key;
-
     @Column
     private PfConceptKey type;
 
@@ -76,30 +70,12 @@ public class JpaToscaEntrySchema extends PfConcept {
     @ElementCollection
     private List<JpaToscaConstraint> constraints;
 
-    /**
-     * The Default Constructor creates a {@link JpaToscaEntrySchema} object with a null key.
-     */
-    public JpaToscaEntrySchema() {
-        this(new PfReferenceKey());
-    }
-
-    /**
-     * The Key Constructor creates a {@link JpaToscaEntrySchema} object with the given concept key.
-     *
-     * @param key the key
-     */
-    public JpaToscaEntrySchema(@NonNull final PfReferenceKey key) {
-        this(key, new PfConceptKey());
-    }
-
     /**
      * The full constructor creates a {@link JpaToscaEntrySchema} object with mandatory fields.
      *
-     * @param key the key
      * @param type the type of the entry schema
      */
-    public JpaToscaEntrySchema(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey type) {
-        this.key = key;
+    public JpaToscaEntrySchema(@NonNull final PfConceptKey type) {
         this.type = type;
     }
 
@@ -108,68 +84,95 @@ public class JpaToscaEntrySchema extends PfConcept {
      *
      * @param copyConcept the concept to copy from
      */
-    public JpaToscaEntrySchema(final JpaToscaEntrySchema copyConcept) {
-        super(copyConcept);
+    public JpaToscaEntrySchema(@NonNull final JpaToscaEntrySchema copyConcept) {
+        copyConcept.copyTo(this);
+    }
+
+    /**
+     * Authorative constructor.
+     *
+     * @param authorativeConcept the authorative concept to copy from
+     */
+    public JpaToscaEntrySchema(final ToscaEntrySchema authorativeConcept) {
+        this.fromAuthorative(authorativeConcept);
     }
 
     @Override
-    public List<PfKey> getKeys() {
-        final List<PfKey> keyList = getKey().getKeys();
+    public ToscaEntrySchema toAuthorative() {
+        ToscaEntrySchema toscaEntrySchema = new ToscaEntrySchema();
 
-        keyList.addAll(type.getKeys());
+        toscaEntrySchema.setType(type.getName());
+        toscaEntrySchema.setTypeVersion(type.getVersion());
+
+        toscaEntrySchema.setDescription(description);
 
         if (constraints != null) {
+            List<ToscaConstraint> toscaConstraints = new ArrayList<>();
+
             for (JpaToscaConstraint constraint : constraints) {
-                keyList.addAll(constraint.getKeys());
+                toscaConstraints.add(constraint.toAuthorative());
             }
+
+            toscaEntrySchema.setConstraints(toscaConstraints);
         }
 
-        return keyList;
+        return toscaEntrySchema;
     }
 
     @Override
-    public void clean() {
-        key.clean();
+    public void fromAuthorative(final ToscaEntrySchema toscaEntrySchema) {
+        if (toscaEntrySchema.getTypeVersion() != null) {
+            type = new PfConceptKey(toscaEntrySchema.getType(), toscaEntrySchema.getTypeVersion());
+        } else {
+            type = new PfConceptKey(toscaEntrySchema.getType(), PfKey.NULL_KEY_VERSION);
+        }
 
-        type.clean();
-        description = (description != null ? description.trim() : null);
+        description = toscaEntrySchema.getDescription();
 
-        if (constraints != null) {
-            for (JpaToscaConstraint constraint : constraints) {
-                constraint.clean();
+        if (toscaEntrySchema.getConstraints() != null) {
+            constraints = new ArrayList<>();
+
+            for (ToscaConstraint toscaConstraint : toscaEntrySchema.getConstraints()) {
+                constraints.add(JpaToscaConstraint.newInstance(toscaConstraint));
             }
         }
     }
 
-    @Override
-    public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
-        PfValidationResult result = resultIn;
+    public List<PfKey> getKeys() {
+        return type.getKeys();
+    }
 
-        if (key.isNullKey()) {
-            result.addValidationMessage(
-                    new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
-        }
+    public void clean() {
+        type.clean();
+        description = (description != null ? description.trim() : null);
+    }
 
-        result = key.validate(result);
+    /**
+     * Validate the entry schema.
+     *
+     * @param resultIn the incoming result
+     * @return the ooutput result witht he result of this validation
+     */
+    public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+        PfValidationResult result = resultIn;
 
         if (type == null || type.isNullKey()) {
-            result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
-                    "entry schema type may not be null"));
+            result.addValidationMessage(new PfValidationMessage(new PfConceptKey("EntrySchema", PfKey.NULL_KEY_VERSION),
+                    this.getClass(), ValidationResult.INVALID, "entry schema type may not be null"));
         }
 
         if (description != null && description.trim().length() == 0) {
-            result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
-                    "entry schema description may not be blank"));
+            result.addValidationMessage(new PfValidationMessage(new PfConceptKey("EntrySchema", PfKey.NULL_KEY_VERSION),
+                    this.getClass(), ValidationResult.INVALID, "entry schema description may not be blank"));
         }
 
 
         if (constraints != null) {
             for (JpaToscaConstraint constraint : constraints) {
                 if (constraint == null) {
-                    result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
-                            "property constraint may not be null "));
-                } else {
-                    result = constraint.validate(result);
+                    result.addValidationMessage(
+                            new PfValidationMessage(new PfConceptKey("EntrySchema", PfKey.NULL_KEY_VERSION),
+                                    this.getClass(), ValidationResult.INVALID, "property constraint may not be null "));
                 }
             }
         }
@@ -178,25 +181,13 @@ public class JpaToscaEntrySchema extends PfConcept {
     }
 
     @Override
-    public int compareTo(final PfConcept otherConcept) {
-        if (otherConcept == null) {
+    public int compareTo(final JpaToscaEntrySchema other) {
+        if (other == null) {
             return -1;
         }
-        if (this == otherConcept) {
+        if (this == other) {
             return 0;
         }
-        if (getClass() != otherConcept.getClass()) {
-            return this.hashCode() - otherConcept.hashCode();
-        }
-
-        final JpaToscaEntrySchema other = (JpaToscaEntrySchema) otherConcept;
-        if (!key.equals(other.key)) {
-            return key.compareTo(other.key);
-        }
-
-        if (!type.equals(other.type)) {
-            return type.compareTo(other.type);
-        }
 
         int result = ObjectUtils.compare(description, other.description);
         if (result != 0) {
@@ -206,12 +197,16 @@ public class JpaToscaEntrySchema extends PfConcept {
         return PfUtils.compareObjects(constraints, other.constraints);
     }
 
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
+    /**
+     * Copy this entry schema to another.
+     *
+     * @param target the other schemaa
+     * @return the copied concept
+     */
+    public JpaToscaEntrySchema copyTo(@NonNull final JpaToscaEntrySchema target) {
         Assertions.instanceOf(target, JpaToscaEntrySchema.class);
 
-        final JpaToscaEntrySchema copy = ((JpaToscaEntrySchema) target);
-        copy.setKey(new PfReferenceKey(key));
+        final JpaToscaEntrySchema copy = (target);
         copy.setType(new PfConceptKey(type));
         copy.setDescription(description);
 
index d59f470..012d8a2 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.policy.models.tosca.simple.concepts;
 
+import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -31,8 +32,10 @@ import javax.persistence.Table;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
+import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConceptContainer;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 
 /**
  * This class is a container for TOSCA data types.
@@ -44,23 +47,24 @@ import org.onap.policy.models.base.PfConceptKey;
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = true)
-public class JpaToscaPolicies extends PfConceptContainer<JpaToscaPolicy> {
+public class JpaToscaPolicies extends PfConceptContainer<JpaToscaPolicy, ToscaPolicy>
+        implements PfAuthorative<List<Map<String, ToscaPolicy>>> {
     private static final long serialVersionUID = -7526648702327776101L;
 
     public static final String DEFAULT_NAME = "ToscaPoliciesSimple";
     public static final String DEFAULT_VERSION = "1.0.0";
 
     /**
-     * The Default Constructor creates a {@link JpaToscaPolicies} object with a null artifact key and
-     * creates an empty concept map.
+     * The Default Constructor creates a {@link JpaToscaPolicies} object with a null artifact key and creates an empty
+     * concept map.
      */
     public JpaToscaPolicies() {
         super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
     }
 
     /**
-     * The Key Constructor creates a {@link JpaToscaPolicies} object with the given artifact key and
-     * creates an empty concept map.
+     * The Key Constructor creates a {@link JpaToscaPolicies} object with the given artifact key and creates an empty
+     * concept map.
      *
      * @param key the concept key
      */
@@ -86,4 +90,13 @@ public class JpaToscaPolicies extends PfConceptContainer<JpaToscaPolicy> {
     public JpaToscaPolicies(final JpaToscaPolicies copyConcept) {
         super(copyConcept);
     }
+
+    /**
+     * Authorative constructor.
+     *
+     * @param authorativeConceptMapList the authorative concept to copy from
+     */
+    public JpaToscaPolicies(final List<Map<String, ToscaPolicy>> authorativeConceptMapList) {
+        this.fromAuthorative(authorativeConceptMapList);
+    }
 }
index e889192..67a833c 100644 (file)
@@ -24,6 +24,7 @@
 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;
@@ -43,6 +44,7 @@ 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;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfKey;
@@ -50,6 +52,7 @@ import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.base.PfValidationMessage;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 
 /**
  * Class to represent the policy in TOSCA definition.
@@ -62,7 +65,7 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = true)
-public class JpaToscaPolicy extends JpaToscaEntityType {
+public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements PfAuthorative<ToscaPolicy> {
     private static final long serialVersionUID = 3265174757061982805L;
 
     // @formatter:off
@@ -119,6 +122,66 @@ public class JpaToscaPolicy extends JpaToscaEntityType {
         super(copyConcept);
     }
 
+    /**
+     * Authorative constructor.
+     *
+     * @param authorativeConcept the authorative concept to copy from
+     */
+    public JpaToscaPolicy(final ToscaPolicy authorativeConcept) {
+        this.fromAuthorative(authorativeConcept);
+    }
+
+    @Override
+    public ToscaPolicy toAuthorative() {
+        ToscaPolicy toscaPolicy = new ToscaPolicy();
+        super.setToscaEntity(toscaPolicy);
+        super.toAuthorative();
+
+        toscaPolicy.setType(type.getName());
+
+        if (!PfKey.NULL_KEY_VERSION.equals(type.getVersion())) {
+            toscaPolicy.setTypeVersion(type.getVersion());
+        }
+        else {
+            toscaPolicy.setTypeVersion(null);
+        }
+
+        if (properties != null) {
+            Map<String, Object> propertyMap = new LinkedHashMap<>();
+
+            for (Entry<String, String> entry : properties.entrySet()) {
+                propertyMap.put(entry.getKey(), entry.getValue());
+            }
+
+            toscaPolicy.setProperties(propertyMap);
+        }
+
+        return toscaPolicy;
+    }
+
+    @Override
+    public void fromAuthorative(@NonNull final ToscaPolicy toscaPolicy) {
+        super.fromAuthorative(toscaPolicy);
+
+        type.setName(toscaPolicy.getType());
+        type.setVersion(toscaPolicy.getTypeVersion());
+        if (type.getVersion() == null) {
+            type.setVersion(PfKey.NULL_KEY_VERSION);
+        }
+
+        if (toscaPolicy.getProperties() != null) {
+            properties = new LinkedHashMap<>();
+
+            for (Entry<String, Object> propertyEntry : toscaPolicy.getProperties().entrySet()) {
+                // TODO: This is a HACK, we need to validate the properties against their
+                // TODO: their data type in their policy type definition in TOSCA, which means reading
+                // TODO: the policy type from the database and parsing the property value object correctly
+                // TODO: Here we are simply serializing the property value into a string and storing it
+                // TODO: unvalidated into the database
+                properties.put(propertyEntry.getKey(), propertyEntry.getValue().toString());
+            }
+        }
+    }
 
     @Override
     public List<PfKey> getKeys() {
index 610987c..fc98296 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;
@@ -37,13 +40,17 @@ 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;
 import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.base.PfValidationMessage;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
 
 /**
  * Class to represent the policy type in TOSCA definition.
@@ -57,11 +64,11 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = true)
-public class JpaToscaPolicyType extends JpaToscaEntityType {
+public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> implements PfAuthorative<ToscaPolicyType> {
     private static final long serialVersionUID = -563659852901842616L;
 
     @ElementCollection
-    private List<JpaToscaProperty> properties;
+    private Map<String, JpaToscaProperty> properties;
 
     @ElementCollection
     private List<PfConceptKey> targets;
@@ -94,13 +101,55 @@ public class JpaToscaPolicyType extends JpaToscaEntityType {
         super(copyConcept);
     }
 
+    /**
+     * Authorative constructor.
+     *
+     * @param authorativeConcept the authorative concept to copy from
+     */
+    public JpaToscaPolicyType(final ToscaPolicyType authorativeConcept) {
+        this.fromAuthorative(authorativeConcept);
+    }
+
+    @Override
+    public ToscaPolicyType toAuthorative() {
+        ToscaPolicyType toscaPolicyType = new ToscaPolicyType();
+        super.setToscaEntity(toscaPolicyType);
+        super.toAuthorative();
+
+        if (properties != null) {
+            Map<String, ToscaProperty> propertyMap = new LinkedHashMap<>();
+
+            for (Entry<String, JpaToscaProperty> entry : properties.entrySet()) {
+                propertyMap.put(entry.getKey(), entry.getValue().toAuthorative());
+            }
+
+            toscaPolicyType.setProperties(propertyMap);
+        }
+
+        return toscaPolicyType;
+    }
+
+    @Override
+    public void fromAuthorative(final ToscaPolicyType toscaPolicyType) {
+        super.fromAuthorative(toscaPolicyType);
+
+        // Set properties
+        if (toscaPolicyType.getProperties() != null) {
+            properties = new LinkedHashMap<>();
+            for (Entry<String, ToscaProperty> toscaPropertyEntry : toscaPolicyType.getProperties().entrySet()) {
+                JpaToscaProperty jpaProperty = new JpaToscaProperty(toscaPropertyEntry.getValue());
+                jpaProperty.setKey(new PfReferenceKey(getKey(), toscaPropertyEntry.getKey()));
+                properties.put(toscaPropertyEntry.getKey(), jpaProperty);
+            }
+        }
+    }
 
     @Override
     public List<PfKey> getKeys() {
         final List<PfKey> keyList = super.getKeys();
 
         if (properties != null) {
-            for (JpaToscaProperty property : properties) {
+            for (JpaToscaProperty property : properties.values()) {
                 keyList.addAll(property.getKeys());
             }
         }
@@ -123,7 +172,7 @@ public class JpaToscaPolicyType extends JpaToscaEntityType {
         super.clean();
 
         if (properties != null) {
-            for (JpaToscaProperty property : properties) {
+            for (JpaToscaProperty property : properties.values()) {
                 property.clean();
             }
         }
@@ -169,7 +218,7 @@ public class JpaToscaPolicyType extends JpaToscaEntityType {
     private PfValidationResult validateProperties(final PfValidationResult resultIn) {
         PfValidationResult result = resultIn;
 
-        for (JpaToscaProperty property : properties) {
+        for (JpaToscaProperty property : properties.values()) {
             if (property == null) {
                 result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
                         "policy property may not be null "));
@@ -258,13 +307,12 @@ public class JpaToscaPolicyType extends JpaToscaEntityType {
         final JpaToscaPolicyType copy = ((JpaToscaPolicyType) copyObject);
         super.copyTo(target);
 
-        final List<JpaToscaProperty> newProperties = new ArrayList<>();
-
         if (properties == null) {
             copy.setProperties(null);
         } else {
-            for (final JpaToscaProperty property : properties) {
-                newProperties.add(new JpaToscaProperty(property));
+            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);
         }
index ce3a813..af8a21a 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.policy.models.tosca.simple.concepts;
 
+import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -33,6 +34,7 @@ import lombok.EqualsAndHashCode;
 
 import org.onap.policy.models.base.PfConceptContainer;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
 
 /**
  * This class is a container for TOSCA policy types.
@@ -44,23 +46,23 @@ import org.onap.policy.models.base.PfConceptKey;
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = true)
-public class JpaToscaPolicyTypes extends PfConceptContainer<JpaToscaPolicyType> {
+public class JpaToscaPolicyTypes extends PfConceptContainer<JpaToscaPolicyType, ToscaPolicyType> {
     private static final long serialVersionUID = -4157979965271220098L;
 
     public static final String DEFAULT_NAME = "ToscaPolicyTypesSimple";
     public static final String DEFAULT_VERSION = "1.0.0";
 
     /**
-     * The Default Constructor creates a {@link JpaToscaPolicyTypes} object with a null artifact key
-     * and creates an empty concept map.
+     * The Default Constructor creates a {@link JpaToscaPolicyTypes} object with a null artifact key and creates an
+     * empty concept map.
      */
     public JpaToscaPolicyTypes() {
         super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
     }
 
     /**
-     * The Key Constructor creates a {@link JpaToscaPolicyTypes} object with the given artifact key and
-     * creates an empty concept map.
+     * The Key Constructor creates a {@link JpaToscaPolicyTypes} object with the given artifact key and creates an empty
+     * concept map.
      *
      * @param key the concept key
      */
@@ -86,4 +88,13 @@ public class JpaToscaPolicyTypes extends PfConceptContainer<JpaToscaPolicyType>
     public JpaToscaPolicyTypes(final JpaToscaPolicyTypes copyConcept) {
         super(copyConcept);
     }
+
+    /**
+     * Authorative constructor.
+     *
+     * @param authorativeConceptMapList the authorative concept to copy from
+     */
+    public JpaToscaPolicyTypes(final List<Map<String, ToscaPolicyType>> authorativeConceptMapList) {
+        this.fromAuthorative(authorativeConceptMapList);
+    }
 }
index 376c2b3..38d5c09 100644 (file)
@@ -23,8 +23,7 @@
 
 package org.onap.policy.models.tosca.simple.concepts;
 
-import com.google.gson.annotations.SerializedName;
-
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.persistence.Column;
@@ -41,6 +40,7 @@ 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;
 import org.onap.policy.models.base.PfKey;
@@ -49,6 +49,9 @@ import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.base.PfValidationMessage;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty.Status;
 
 /**
  * Class to represent the property in TOSCA definition.
@@ -61,13 +64,9 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = false)
-public class JpaToscaProperty extends PfConcept {
+public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaProperty> {
     private static final long serialVersionUID = 1675770231921107988L;
 
-    public enum Status {
-        SUPPORTED, UNSUPPORTED, EXPERIMENTAL, DEPRECATED
-    }
-
     @EmbeddedId
     private PfReferenceKey key;
 
@@ -81,7 +80,6 @@ public class JpaToscaProperty extends PfConcept {
     private boolean required = false;
 
     @Column(name = "default")
-    @SerializedName("default")
     private String defaultValue;
 
     @Column
@@ -92,7 +90,6 @@ public class JpaToscaProperty extends PfConcept {
     private List<JpaToscaConstraint> constraints;
 
     @Column
-    @SerializedName("entry_schema")
     private JpaToscaEntrySchema entrySchema;
 
     /**
@@ -131,18 +128,81 @@ public class JpaToscaProperty extends PfConcept {
         super(copyConcept);
     }
 
+    /**
+     * Authorative constructor.
+     *
+     * @param authorativeConcept the authorative concept to copy from
+     */
+    public JpaToscaProperty(final ToscaProperty authorativeConcept) {
+        this.fromAuthorative(authorativeConcept);
+    }
+
     @Override
-    public List<PfKey> getKeys() {
-        final List<PfKey> keyList = getKey().getKeys();
+    public ToscaProperty toAuthorative() {
+        ToscaProperty toscaProperty = new ToscaProperty();
 
-        keyList.addAll(type.getKeys());
+        toscaProperty.setName(key.getLocalName());
+
+        toscaProperty.setType(type.getName());
+        toscaProperty.setTypeVersion(type.getVersion());
+
+        toscaProperty.setDescription(description);
+        toscaProperty.setRequired(required);
+        toscaProperty.setDefaultValue(defaultValue);
+        toscaProperty.setStatus(status);
 
         if (constraints != null) {
+            List<ToscaConstraint> toscaConstraints = new ArrayList<>();
+
             for (JpaToscaConstraint constraint : constraints) {
-                keyList.addAll(constraint.getKeys());
+                toscaConstraints.add(constraint.toAuthorative());
+            }
+
+            toscaProperty.setConstraints(toscaConstraints);
+        }
+
+        if (entrySchema != null) {
+            toscaProperty.setEntrySchema(entrySchema.toAuthorative());
+        }
+
+        return toscaProperty;
+    }
+
+    @Override
+    public void fromAuthorative(ToscaProperty toscaProperty) {
+        this.setKey(new PfReferenceKey());
+        getKey().setLocalName(toscaProperty.getName());
+
+        if (toscaProperty.getTypeVersion() != null) {
+            type = new PfConceptKey(toscaProperty.getType(), toscaProperty.getTypeVersion());
+        } else {
+            type = new PfConceptKey(toscaProperty.getType(), PfKey.NULL_KEY_VERSION);
+        }
+
+        description = toscaProperty.getDescription();
+        required = toscaProperty.isRequired();
+        defaultValue = toscaProperty.getDefaultValue();
+        status = toscaProperty.getStatus();
+
+        if (toscaProperty.getConstraints() != null) {
+            constraints = new ArrayList<>();
+
+            for (ToscaConstraint toscaConstraint : toscaProperty.getConstraints()) {
+                constraints.add(JpaToscaConstraint.newInstance(toscaConstraint));
             }
         }
 
+        if (toscaProperty.getEntrySchema() != null) {
+            entrySchema = new JpaToscaEntrySchema(toscaProperty.getEntrySchema());
+        }
+    }
+
+    @Override
+    public List<PfKey> getKeys() {
+        final List<PfKey> keyList = getKey().getKeys();
+
+        keyList.addAll(type.getKeys());
+
         if (entrySchema != null) {
             keyList.addAll(entrySchema.getKeys());
         }
@@ -164,12 +224,6 @@ public class JpaToscaProperty extends PfConcept {
             defaultValue = defaultValue.trim();
         }
 
-        if (constraints != null) {
-            for (JpaToscaConstraint constraint : constraints) {
-                constraint.clean();
-            }
-        }
-
         if (entrySchema != null) {
             entrySchema.clean();
         }
@@ -218,8 +272,6 @@ public class JpaToscaProperty extends PfConcept {
                 if (constraint == null) {
                     result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
                             "property constraint may not be null "));
-                } else {
-                    result = constraint.validate(result);
                 }
             }
         }
@@ -247,8 +299,7 @@ public class JpaToscaProperty extends PfConcept {
     }
 
     /**
-     * Compare the fields of this ToscaProperty object with the fields of the other ToscaProperty
-     * object.
+     * Compare the fields of this ToscaProperty object with the fields of the other ToscaProperty object.
      *
      * @param other the other ToscaProperty object
      */
@@ -296,7 +347,17 @@ public class JpaToscaProperty extends PfConcept {
         copy.setRequired(required);
         copy.setDefaultValue(defaultValue);
         copy.setStatus(status);
-        copy.constraints = constraints; // Constraints are immutable
+
+        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 fa2d2aa..fda0c80 100644 (file)
@@ -39,16 +39,18 @@ 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;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfKey;
 import org.onap.policy.models.base.PfValidationMessage;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 
 /**
- * This class holds a full TOSCA service template. Note: Only the policy specific parts of the TOSCA
- * service template are implemented.
+ * This class holds a full TOSCA service template. Note: Only the policy specific parts of the TOSCA service template
+ * are implemented.
  *
  * @author Liam Fallon (liam.fallon@est.tech)
  */
@@ -57,7 +59,8 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = true)
-public class JpaToscaServiceTemplate extends JpaToscaEntityType {
+public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemplate>
+        implements PfAuthorative<ToscaServiceTemplate> {
     private static final long serialVersionUID = 8084846046148349401L;
 
     public static final String DEFAULT_NAME = "ToscaServiceTemplateSimple";
@@ -96,8 +99,7 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType {
     }
 
     /**
-     * The full constructor creates a {@link JpaToscaServiceTemplate} object with all mandatory
-     * parameters.
+     * The full constructor creates a {@link JpaToscaServiceTemplate} object with all mandatory parameters.
      *
      * @param key the key
      * @param toscaDefinitionsVersion the TOSCA version string
@@ -116,6 +118,70 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType {
         super(copyConcept);
     }
 
+    /**
+     * Authorative constructor.
+     *
+     * @param authorativeConcept the authorative concept to copy from
+     */
+    public JpaToscaServiceTemplate(final ToscaServiceTemplate authorativeConcept) {
+        this.fromAuthorative(authorativeConcept);
+    }
+
+    @Override
+    public ToscaServiceTemplate toAuthorative() {
+        final ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate();
+
+        super.setToscaEntity(toscaServiceTemplate);
+        super.toAuthorative();
+
+        toscaServiceTemplate.setToscaDefinitionsVersion(toscaDefinitionsVersion);
+
+        if (dataTypes != null) {
+            toscaServiceTemplate.setDataTypes(dataTypes.toAuthorative());
+        }
+
+        if (policyTypes != null) {
+            toscaServiceTemplate.setPolicyTypes(policyTypes.toAuthorative());
+        }
+
+        if (topologyTemplate != null) {
+            toscaServiceTemplate.setToscaTopologyTemplate(topologyTemplate.toAuthorative());
+        }
+
+        return toscaServiceTemplate;
+    }
+
+    @Override
+    public void fromAuthorative(ToscaServiceTemplate toscaServiceTemplate) {
+        super.fromAuthorative(toscaServiceTemplate);
+
+        if (getKey().getName() == PfKey.NULL_KEY_NAME) {
+            getKey().setName(DEFAULT_NAME);
+        }
+
+        if (getKey().getVersion() == PfKey.NULL_KEY_VERSION) {
+            getKey().setVersion(DEFAULT_VERSION);
+        }
+
+        toscaDefinitionsVersion = toscaServiceTemplate.getToscaDefinitionsVersion();
+
+        if (toscaServiceTemplate.getDataTypes() != null) {
+            dataTypes = new JpaToscaDataTypes();
+            dataTypes.fromAuthorative(toscaServiceTemplate.getDataTypes());
+        }
+
+        if (toscaServiceTemplate.getPolicyTypes() != null) {
+            policyTypes = new JpaToscaPolicyTypes();
+            policyTypes.fromAuthorative(toscaServiceTemplate.getPolicyTypes());
+        }
+
+
+        if (toscaServiceTemplate.getToscaTopologyTemplate() != null) {
+            topologyTemplate = new JpaToscaTopologyTemplate();
+            topologyTemplate.fromAuthorative(toscaServiceTemplate.getToscaTopologyTemplate());
+        }
+    }
+
     @Override
     public List<PfKey> getKeys() {
         final List<PfKey> keyList = super.getKeys();
index 39e5531..08624f6 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.policy.models.tosca.simple.concepts;
 
+import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -33,6 +34,7 @@ import lombok.EqualsAndHashCode;
 
 import org.onap.policy.models.base.PfConceptContainer;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 
 /**
  * This class is a container for TOSCA service templates.
@@ -44,7 +46,7 @@ import org.onap.policy.models.base.PfConceptKey;
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = true)
-public class JpaToscaServiceTemplates extends PfConceptContainer<JpaToscaServiceTemplate> {
+public class JpaToscaServiceTemplates extends PfConceptContainer<JpaToscaServiceTemplate, ToscaServiceTemplate> {
     private static final long serialVersionUID = -3053257884307604114L;
 
     /**
@@ -84,4 +86,13 @@ public class JpaToscaServiceTemplates extends PfConceptContainer<JpaToscaService
     public JpaToscaServiceTemplates(final JpaToscaServiceTemplates copyConcept) {
         super(copyConcept);
     }
+
+    /**
+     * Authorative constructor.
+     *
+     * @param authorativeConceptMapList the authorative concept to copy from
+     */
+    public JpaToscaServiceTemplates(final List<Map<String, ToscaServiceTemplate>> authorativeConceptMapList) {
+        this.fromAuthorative(authorativeConceptMapList);
+    }
 }
index 095435a..3476258 100644 (file)
@@ -37,12 +37,14 @@ 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;
 import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfValidationMessage;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
 
 /**
  * This class holds a TOSCA topology template. Note: Only the policy specific parts of the TOSCA topology template are
@@ -55,7 +57,7 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = false)
-public class JpaToscaTopologyTemplate extends PfConcept {
+public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative<ToscaTopologyTemplate> {
     private static final long serialVersionUID = 8969698734673232603L;
 
     public static final String DEFAULT_LOCAL_NAME = "ToscaTopologyTemplateSimple";
@@ -96,6 +98,38 @@ public class JpaToscaTopologyTemplate extends PfConcept {
         super(copyConcept);
     }
 
+    /**
+     * Authorative constructor.
+     *
+     * @param authorativeConcept the authorative concept to copy from
+     */
+    public JpaToscaTopologyTemplate(final ToscaTopologyTemplate authorativeConcept) {
+        this.fromAuthorative(authorativeConcept);
+    }
+
+    @Override
+    public ToscaTopologyTemplate toAuthorative() {
+        final ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate();
+
+        toscaTopologyTemplate.setDescription(description);
+
+        if (policies != null) {
+            toscaTopologyTemplate.setPolicies(policies.toAuthorative());
+        }
+
+        return toscaTopologyTemplate;
+    }
+
+    @Override
+    public void fromAuthorative(ToscaTopologyTemplate toscaTopologyTemplate) {
+        description = toscaTopologyTemplate.getDescription();
+
+        if (toscaTopologyTemplate.getPolicies() != null) {
+            policies = new JpaToscaPolicies();
+            policies.fromAuthorative(toscaTopologyTemplate.getPolicies());
+        }
+    }
+
     @Override
     public List<PfKey> getKeys() {
         final List<PfKey> keyList = getKey().getKeys();
index 0a32701..551dbe5 100644 (file)
@@ -148,12 +148,6 @@ public class JpaToscaTrigger extends PfConcept {
         if (targetFilter != null) {
             keyList.addAll(targetFilter.getKeys());
         }
-        if (condition != null) {
-            keyList.addAll(condition.getKeys());
-        }
-        if (constraint != null) {
-            keyList.addAll(constraint.getKeys());
-        }
         return keyList;
     }
 
@@ -170,12 +164,6 @@ public class JpaToscaTrigger extends PfConcept {
         if (targetFilter != null) {
             targetFilter.clean();
         }
-        if (condition != null) {
-            condition.clean();
-        }
-        if (constraint != null) {
-            constraint.clean();
-        }
 
         method = (method != null ? method.trim() : method);
         action = action.trim();
@@ -233,8 +221,6 @@ public class JpaToscaTrigger extends PfConcept {
 
         result = (schedule != null ? schedule.validate(result) : result);
         result = (targetFilter != null ? targetFilter.validate(result) : result);
-        result = (condition != null ? condition.validate(result) : result);
-        result = (constraint != null ? constraint.validate(result) : result);
 
         return result;
     }
index 6e356d0..e7e8160 100644 (file)
@@ -143,7 +143,7 @@ public class SimpleToscaProvider {
      * @return the TOSCA service template containing the policy types that were deleted
      * @throws PfModelException on errors deleting policy types
      */
-    public JpaToscaServiceTemplate deletePolicyTypes(@NonNull final PfDao dao,
+    public JpaToscaServiceTemplate deletePolicyType(@NonNull final PfDao dao,
             @NonNull final PfConceptKey policyTypeKey)
             throws PfModelException {
 
@@ -251,7 +251,7 @@ public class SimpleToscaProvider {
      * @return the TOSCA service template containing the policies that were deleted
      * @throws PfModelException on errors deleting policies
      */
-    public JpaToscaServiceTemplate deletePolicies(@NonNull final PfDao dao, @NonNull final PfConceptKey policyKey)
+    public JpaToscaServiceTemplate deletePolicy(@NonNull final PfDao dao, @NonNull final PfConceptKey policyKey)
             throws PfModelException {
 
         JpaToscaServiceTemplate serviceTemplate = getPolicies(dao, policyKey);
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypeJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypeJsonAdapter.java
deleted file mode 100644 (file)
index 6b00b20..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.serialization;
-
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-
-import java.lang.reflect.Type;
-import javax.ws.rs.core.Response;
-
-import lombok.NonNull;
-
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * GSON type adapter for TOSCA data types.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- */
-public class ToscaDataTypeJsonAdapter implements JsonSerializer<JpaToscaDataType>, JsonDeserializer<JpaToscaDataType> {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(ToscaDataTypeJsonAdapter.class);
-
-    private static final String DERIVED_FROM = "derived_from";
-    private static final String DESCRIPTION = "description";
-    private static final String VERSION = "version";
-    private static final String PROPERTIES = "properties";
-    private static final String DEFAULT_VERSION = "1.0.0";
-
-    @Override
-    public JpaToscaDataType deserialize(@NonNull final JsonElement dataTypeElement, @NonNull final Type type,
-            @NonNull final JsonDeserializationContext context) {
-
-        // The incoming JSON
-        final JsonObject dataTypeJsonMapObject = dataTypeElement.getAsJsonObject();
-
-        // We should only have a single entry for the policy type
-        if (dataTypeJsonMapObject.entrySet().size() != 1) {
-            String errorMessage = "a policy type list entry may only contain one and only one policy type";
-            LOGGER.debug(errorMessage);
-            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
-        }
-
-        final String dataTypeName = dataTypeJsonMapObject.entrySet().iterator().next().getKey();
-        final JsonObject dataTypeJsonObject = dataTypeJsonMapObject.entrySet().iterator().next()
-                                            .getValue().getAsJsonObject();
-
-        // Set keys
-        PfConceptKey dataTypeKey;
-        if (dataTypeJsonObject.get(VERSION) == null) {
-            dataTypeKey = new PfConceptKey(dataTypeName, DEFAULT_VERSION);
-        } else {
-            dataTypeKey = new PfConceptKey(dataTypeName, dataTypeJsonObject.get(VERSION).getAsString());
-        }
-        JpaToscaDataType dataType = new JpaToscaDataType(dataTypeKey);
-
-        // Set derived_from
-        dataType.setDerivedFrom(new PfConceptKey(dataTypeJsonObject.get(DERIVED_FROM).getAsString(),
-                DEFAULT_VERSION));
-
-        // Set description
-        if (dataTypeJsonObject.has(DESCRIPTION)) {
-            final String dataTypeDescription = dataTypeJsonObject.get(DESCRIPTION).getAsString();
-            dataType.setDescription(dataTypeDescription);
-        }
-
-        // Set properties
-        if (dataTypeJsonObject.has(PROPERTIES)) {
-            dataType.setProperties(
-                    new ToscaPropertiesJsonAdapter().deserializeProperties(dataTypeJsonObject.get(PROPERTIES)));
-            for (JpaToscaProperty property : dataType.getProperties()) {
-                property.getKey().setParentConceptKey(dataTypeKey);
-                property.getType().setVersion(dataType.getKey().getVersion());
-            }
-        }
-
-        return dataType;
-    }
-
-    @Override
-    public JsonElement serialize(@NonNull final JpaToscaDataType dataType, @NonNull final Type type,
-            @NonNull final JsonSerializationContext context) {
-
-        JsonObject dataTypeValJsonObject = new JsonObject();
-
-        // Add derived_from
-        if (dataType.getDerivedFrom() != null) {
-            dataTypeValJsonObject.addProperty(DERIVED_FROM, dataType.getDerivedFrom().getName());
-        }
-
-        // Add description
-        if (dataType.getDescription() != null) {
-            dataTypeValJsonObject.addProperty(DESCRIPTION, dataType.getDescription());
-        }
-
-        // Add version
-        if (dataType.getKey().getVersion() != null) {
-            dataTypeValJsonObject.addProperty(VERSION, dataType.getKey().getVersion());
-        }
-
-        // Add properties
-        if (dataType.getProperties() != null) {
-            JsonElement propertiesJsonElement = new ToscaPropertiesJsonAdapter()
-                    .serializeProperties(dataType.getProperties());
-            dataTypeValJsonObject.add(PROPERTIES, propertiesJsonElement);
-        }
-
-        JsonObject dataTypeJsonObject = new JsonObject();
-        dataTypeJsonObject.add(dataType.getKey().getName(), dataTypeValJsonObject);
-        return dataTypeJsonObject;
-    }
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypesJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypesJsonAdapter.java
deleted file mode 100644 (file)
index 6131581..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.serialization;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-
-import java.lang.reflect.Type;
-import java.util.Iterator;
-import javax.ws.rs.core.Response;
-import lombok.NonNull;
-
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * GSON type adapter for TOSCA data types.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- */
-public class ToscaDataTypesJsonAdapter
-        implements JsonSerializer<JpaToscaDataTypes>, JsonDeserializer<JpaToscaDataTypes> {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(ToscaDataTypesJsonAdapter.class);
-
-    @Override
-    public JpaToscaDataTypes deserialize(@NonNull final JsonElement dataTypesElement, @NonNull final Type type,
-            @NonNull final JsonDeserializationContext context) {
-
-        // The incoming JSON
-        final JsonArray dataTypesJsonArray = dataTypesElement.getAsJsonArray();
-
-        // The outgoing object
-        final PfConceptKey dataTypesKey = new PfConceptKey("IncomingDataTypes", "0.0.1");
-        final JpaToscaDataTypes dataTypes = new JpaToscaDataTypes(dataTypesKey);
-
-        // Get the dataTypes
-        Iterator<JsonElement> dataTypesIterator = dataTypesJsonArray.iterator();
-        while (dataTypesIterator.hasNext()) {
-            JpaToscaDataType dataType = new ToscaDataTypeJsonAdapter().deserialize(dataTypesIterator.next(),
-                    JpaToscaDataType.class, context);
-
-            dataTypes.getConceptMap().put(dataType.getKey(), dataType);
-        }
-
-        return dataTypes;
-    }
-
-    @Override
-    public JsonElement serialize(@NonNull final JpaToscaDataTypes dataTypes, @NonNull final Type type,
-            @NonNull final JsonSerializationContext context) {
-
-        JsonArray dataTypesJsonArray = new JsonArray();
-
-        if (dataTypes.getConceptMap().isEmpty()) {
-            String errorMessage = "data type list is empty";
-            LOGGER.debug(errorMessage);
-            throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage);
-        }
-
-        for (JpaToscaDataType dataType : dataTypes.getConceptMap().values()) {
-            JsonElement dataTypeEntry = new ToscaDataTypeJsonAdapter().serialize(dataType, type, context);
-            dataTypesJsonArray.add(dataTypeEntry);
-        }
-
-        return dataTypesJsonArray;
-    }
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java
deleted file mode 100644 (file)
index ca0e3d9..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- *  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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.serialization;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-
-import java.lang.reflect.Type;
-import java.util.Iterator;
-import lombok.NonNull;
-
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
-
-/**
- * GSON type adapter for TOSCA policies.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- * @author Chenfei Gao (cgao@research.att.com)
- */
-public class ToscaPoliciesJsonAdapter implements JsonSerializer<JpaToscaPolicies>, JsonDeserializer<JpaToscaPolicies> {
-
-    @Override
-    public JpaToscaPolicies deserialize(@NonNull final JsonElement policiesElement, @NonNull final Type type,
-            @NonNull final JsonDeserializationContext context) {
-        // The incoming JSON
-        final JsonArray policiesJsonArray = policiesElement.getAsJsonArray();
-
-        // The outgoing object
-        final PfConceptKey policiesKey = new PfConceptKey("IncomingPolicies", "0.0.1");
-        final JpaToscaPolicies policies = new JpaToscaPolicies(policiesKey);
-
-        // Get the policies
-        for (Iterator<JsonElement> policiesIterator = policiesJsonArray.iterator(); policiesIterator.hasNext(); ) {
-            JpaToscaPolicy policy = new ToscaPolicyJsonAdapter()
-                    .deserialize(policiesIterator.next(), JpaToscaPolicy.class, context);
-
-            policies.getConceptMap().put(policy.getKey(), policy);
-        }
-
-        return policies;
-    }
-
-    @Override
-    public JsonElement serialize(@NonNull final JpaToscaPolicies policies, @NonNull final Type type,
-            @NonNull final JsonSerializationContext context) {
-
-        JsonArray policiesJsonArray = new JsonArray();
-
-        for (JpaToscaPolicy policy: policies.getConceptMap().values()) {
-            policiesJsonArray.add(new ToscaPolicyJsonAdapter().serialize(policy, type, context));
-        }
-        return policiesJsonArray;
-    }
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java
deleted file mode 100644 (file)
index 6b666e2..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- *  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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.serialization;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import javax.ws.rs.core.Response;
-
-import lombok.NonNull;
-
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * GSON type adapter for TOSCA policies.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- * @author Chenfei Gao (cgao@research.att.com)
- */
-public class ToscaPolicyJsonAdapter implements JsonSerializer<JpaToscaPolicy>, JsonDeserializer<JpaToscaPolicy> {
-    // Logger for this class
-    private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyJsonAdapter.class);
-
-    private static final String TYPE = "type";
-    private static final String DESCRIPTION = "description";
-    private static final String VERSION = "version";
-    private static final String METADATA = "metadata";
-    private static final String PROPERTIES = "properties";
-
-    private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
-
-    @Override
-    public JpaToscaPolicy deserialize(@NonNull final JsonElement policyElement, @NonNull final Type type,
-            @NonNull final JsonDeserializationContext context) {
-
-        // The incoming JSON
-        final JsonObject policyJsonMapObject = policyElement.getAsJsonObject();
-
-        // We should only have a single entry for the policy
-        if (policyJsonMapObject.entrySet().size() != 1) {
-            String errorMessage = "a policy list entry may only contain one and only one policy";
-            LOGGER.debug(errorMessage);
-            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
-        }
-
-        final String policyName = policyJsonMapObject.entrySet().iterator().next().getKey();
-        final JsonObject policyJsonObject = policyJsonMapObject.entrySet().iterator().next()
-                                            .getValue().getAsJsonObject();
-
-        // Set keys
-        PfConceptKey policyKey = new PfConceptKey(policyName, policyJsonObject.get(VERSION).getAsString());
-        PfConceptKey policyTypeKey = new PfConceptKey(
-                policyJsonObject.get(TYPE).getAsString(),
-                policyJsonObject.get(VERSION).getAsString());
-        JpaToscaPolicy policy = new JpaToscaPolicy(policyKey, policyTypeKey);
-
-        // Set description
-        if (policyJsonObject.has(DESCRIPTION)) {
-            final String policyDescription = policyJsonObject.get(DESCRIPTION).getAsString();
-            policy.setDescription(policyDescription);
-        }
-
-        // Set metadata
-        if (policyJsonObject.has(METADATA)) {
-            final JsonObject policyMetadataMapObject = policyJsonObject.get(METADATA).getAsJsonObject();
-            Map<String, String> policyMetadataMap = new HashMap<>();
-            for (Entry<String, JsonElement> entry : policyMetadataMapObject.entrySet()) {
-                policyMetadataMap.put(entry.getKey(), entry.getValue().getAsString());
-            }
-            policy.setMetadata(policyMetadataMap);
-        }
-
-        // Set properties
-        if (policyJsonObject.has(PROPERTIES)) {
-            final JsonObject policyPropertiesMapObject = policyJsonObject.get(PROPERTIES).getAsJsonObject();
-            Map<String, String> propertiesMap = new HashMap<>();
-            for (Entry<String, JsonElement> entry : policyPropertiesMapObject.entrySet()) {
-                // TODO: This is a HACK, we need to validate the properties against their
-                // TODO: their data type in their policy type definition in TOSCA, which means reading
-                // TODO: the policy type from the database and parsing the property value object correctly
-                // TODO: Here we are simply serializing the property value into a string and storing it
-                // TODO: unvalidated into the database
-                propertiesMap.put(entry.getKey(), gson.toJson(entry.getValue()));
-            }
-            policy.setProperties(propertiesMap);
-        }
-        return policy;
-    }
-
-    @Override
-    public JsonElement serialize(@NonNull final JpaToscaPolicy policy, @NonNull final Type type,
-            @NonNull final JsonSerializationContext context) {
-
-        JsonObject policyValJsonObject = new JsonObject();
-
-        // Add type
-        policyValJsonObject.addProperty(TYPE, policy.getType().getName());
-
-        // Add version
-        policyValJsonObject.addProperty(VERSION, policy.getType().getVersion());
-
-        // Add description
-        if (policy.getDescription() != null) {
-            policyValJsonObject.addProperty(DESCRIPTION, policy.getDescription());
-        }
-
-        // Add metadata
-        if (policy.getMetadata() != null) {
-            JsonObject metadataMapObject = new JsonObject();
-            for (Entry<String, String> entry : policy.getMetadata().entrySet()) {
-                metadataMapObject.addProperty(entry.getKey(), entry.getValue());
-            }
-            policyValJsonObject.add(METADATA, metadataMapObject);
-        }
-
-        // Add properties
-        if (policy.getProperties() != null) {
-            JsonObject propertiesMapObject = new JsonObject();
-            for (Entry<String, String> entry : policy.getProperties().entrySet()) {
-                // TODO: This is the other direction of the HACK
-                JsonElement valueObject = gson.fromJson(entry.getValue(), JsonElement.class);
-                propertiesMapObject.add(entry.getKey(), valueObject);
-            }
-            policyValJsonObject.add(PROPERTIES, propertiesMapObject);
-        }
-
-        JsonObject policyJsonObject = new JsonObject();
-        policyJsonObject.add(policy.getKey().getName(), policyValJsonObject);
-        return policyJsonObject;
-    }
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyTypeJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyTypeJsonAdapter.java
deleted file mode 100644 (file)
index a966422..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.serialization;
-
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-import java.lang.reflect.Type;
-import javax.ws.rs.core.Response;
-
-import lombok.NonNull;
-
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * GSON type adapter for TOSCA policy types.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- */
-public class ToscaPolicyTypeJsonAdapter
-        implements JsonSerializer<JpaToscaPolicyType>, JsonDeserializer<JpaToscaPolicyType> {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyTypeJsonAdapter.class);
-
-    private static final String DERIVED_FROM = "derived_from";
-    private static final String DESCRIPTION = "description";
-    private static final String VERSION = "version";
-    private static final String PROPERTIES = "properties";
-    private static final String DEFAULT_VERSION = "1.0.0";
-
-    @Override
-    public JpaToscaPolicyType deserialize(@NonNull final JsonElement policyTypeElement, @NonNull final Type type,
-            @NonNull final JsonDeserializationContext context) {
-
-        // The incoming JSON
-        final JsonObject policyTypeJsonMapObject = policyTypeElement.getAsJsonObject();
-
-        // We should only have a single entry for the policy type
-        if (policyTypeJsonMapObject.entrySet().size() != 1) {
-            String errorMessage = "a policy type list entry may only contain one and only one policy type";
-            LOGGER.debug(errorMessage);
-            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
-        }
-
-        final String policyTypeName = policyTypeJsonMapObject.entrySet().iterator().next().getKey();
-        final JsonObject policyTypeJsonObject =
-                policyTypeJsonMapObject.entrySet().iterator().next().getValue().getAsJsonObject();
-
-        // Set keys
-        PfConceptKey policyTypeKey;
-        if (policyTypeJsonObject.get(VERSION) == null) {
-            policyTypeKey = new PfConceptKey(policyTypeName, DEFAULT_VERSION);
-        } else {
-            policyTypeKey = new PfConceptKey(policyTypeName, policyTypeJsonObject.get(VERSION).getAsString());
-        }
-        JpaToscaPolicyType policyType = new JpaToscaPolicyType(policyTypeKey);
-
-        // Set derived_from
-        policyType.setDerivedFrom(
-                new PfConceptKey(policyTypeJsonObject.get(DERIVED_FROM).getAsString(), DEFAULT_VERSION));
-
-        // Set description
-        if (policyTypeJsonObject.has(DESCRIPTION)) {
-            final String policyTypeDescription = policyTypeJsonObject.get(DESCRIPTION).getAsString();
-            policyType.setDescription(policyTypeDescription);
-        }
-
-        // Set properties
-        if (policyTypeJsonObject.has(PROPERTIES)) {
-            policyType.setProperties(
-                    new ToscaPropertiesJsonAdapter().deserializeProperties(policyTypeJsonObject.get(PROPERTIES)));
-            for (JpaToscaProperty property : policyType.getProperties()) {
-                property.getKey().setParentConceptKey(policyTypeKey);
-                property.getType().setVersion(policyType.getKey().getVersion());
-            }
-        }
-
-        return policyType;
-    }
-
-    @Override
-    public JsonElement serialize(@NonNull final JpaToscaPolicyType policyType, @NonNull final Type type,
-            @NonNull final JsonSerializationContext context) {
-
-        JsonObject policyTypeValJsonObject = new JsonObject();
-
-        // Add derived_from
-        if (policyType.getDerivedFrom() != null) {
-            policyTypeValJsonObject.addProperty(DERIVED_FROM, policyType.getDerivedFrom().getName());
-        }
-
-        // Add description
-        if (policyType.getDescription() != null) {
-            policyTypeValJsonObject.addProperty(DESCRIPTION, policyType.getDescription());
-        }
-
-        // Add version
-        if (policyType.getKey().getVersion() != null) {
-            policyTypeValJsonObject.addProperty(VERSION, policyType.getKey().getVersion());
-        }
-
-        // Add properties
-        if (policyType.getProperties() != null) {
-            JsonElement propertiesJsonElement =
-                    new ToscaPropertiesJsonAdapter().serializeProperties(policyType.getProperties());
-            policyTypeValJsonObject.add(PROPERTIES, propertiesJsonElement);
-        }
-
-        JsonObject policyTypeJsonObject = new JsonObject();
-        policyTypeJsonObject.add(policyType.getKey().getName(), policyTypeValJsonObject);
-        return policyTypeJsonObject;
-    }
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyTypesJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyTypesJsonAdapter.java
deleted file mode 100644 (file)
index ac6d8e5..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.serialization;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-
-import java.lang.reflect.Type;
-import java.util.Iterator;
-import javax.ws.rs.core.Response;
-import lombok.NonNull;
-
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * GSON type adapter for TOSCA policy types.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- */
-public class ToscaPolicyTypesJsonAdapter implements JsonSerializer<JpaToscaPolicyTypes>,
-                                                    JsonDeserializer<JpaToscaPolicyTypes> {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyTypesJsonAdapter.class);
-
-    @Override
-    public JpaToscaPolicyTypes deserialize(@NonNull final JsonElement policyTypesElement, @NonNull final Type type,
-            @NonNull final JsonDeserializationContext context) {
-
-        // The incoming JSON
-        final JsonArray policyTypesJsonArray = policyTypesElement.getAsJsonArray();
-
-        // The outgoing object
-        final PfConceptKey policyTypesKey = new PfConceptKey("IncomingPolicyTypes", "0.0.1");
-        final JpaToscaPolicyTypes policyTypes = new JpaToscaPolicyTypes(policyTypesKey);
-
-        // Get the policyTypes
-        Iterator<JsonElement> policyTypesIterator = policyTypesJsonArray.iterator();
-        while (policyTypesIterator.hasNext()) {
-            JpaToscaPolicyType policyType = new ToscaPolicyTypeJsonAdapter()
-                    .deserialize(policyTypesIterator.next(), JpaToscaPolicyType.class, context);
-
-            policyTypes.getConceptMap().put(policyType.getKey(), policyType);
-        }
-
-        return policyTypes;
-    }
-
-    @Override
-    public JsonElement serialize(@NonNull final JpaToscaPolicyTypes policyTypes, @NonNull final Type type,
-            @NonNull final JsonSerializationContext context) {
-
-        JsonArray policyTypesJsonArray = new JsonArray();
-
-        if (policyTypes.getConceptMap().isEmpty()) {
-            String errorMessage = "policy type list is empty";
-            LOGGER.debug(errorMessage);
-            throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage);
-        }
-
-        for (JpaToscaPolicyType policyType: policyTypes.getConceptMap().values()) {
-            JsonElement policyTypeEntry = new  ToscaPolicyTypeJsonAdapter().serialize(policyType, type, context);
-            policyTypesJsonArray.add(policyTypeEntry);
-        }
-
-        return policyTypesJsonArray;
-    }
-}
\ No newline at end of file
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPropertiesJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPropertiesJsonAdapter.java
deleted file mode 100644 (file)
index b5c8755..0000000
+++ /dev/null
@@ -1,284 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.serialization;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map.Entry;
-import javax.ws.rs.core.Response;
-
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * GSON type adapter for TOSCA properties.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- */
-public class ToscaPropertiesJsonAdapter {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPropertiesJsonAdapter.class);
-
-    private static final String DESCRIPTION = "description";
-    private static final String REQUIRED = "required";
-    private static final String DEFAULT = "default";
-    private static final String TYPE = "type";
-    private static final String ENTRY_SCHEMA = "entry_schema";
-    private static final String CONSTRAINTS = "constraints";
-    private static final String EQUAL = "equal";
-    private static final String VALID_VALUES = "valid_values";
-    private static final String DEFAULT_VERSION = "1.0.0";
-
-    /**
-     * Deserializes the properties.
-     *
-     * @param propertiesElement the properties in JsonElement
-     *
-     * @return deserialized ToscaProperty list
-     */
-    public List<JpaToscaProperty> deserializeProperties(JsonElement propertiesElement) {
-
-        final JsonObject propertiesMapObject = propertiesElement.getAsJsonObject();
-        List<JpaToscaProperty> properties = new LinkedList<>();
-
-        for (Entry<String, JsonElement> entry : propertiesMapObject.entrySet()) {
-            final String propertyEntryKey = entry.getKey();
-            final JsonElement propertyEntryVal = entry.getValue();
-
-            // Set property: key and type
-            JpaToscaProperty property = new JpaToscaProperty(
-                    new PfReferenceKey(new PfConceptKey(), propertyEntryKey),
-                    new PfConceptKey(propertyEntryVal.getAsJsonObject().get(TYPE).getAsString(), DEFAULT_VERSION));
-
-            // Set property: description
-            JsonObject propertyJsonObject = propertyEntryVal.getAsJsonObject();
-            if (propertyJsonObject.has(DESCRIPTION)) {
-                property.setDescription(propertyJsonObject.get(DESCRIPTION).getAsString());
-            }
-
-            // Set property: required
-            if (propertyJsonObject.has(REQUIRED)) {
-                property.setRequired(propertyJsonObject.get(REQUIRED).getAsBoolean());
-            }
-
-            // Set property: default
-            if (propertyJsonObject.has(DEFAULT)) {
-                property.setDefaultValue(propertyJsonObject.get(DEFAULT).getAsString());
-            }
-
-            // Set property: entry_schema
-            if (propertyJsonObject.has(ENTRY_SCHEMA)) {
-                checkEntrySchemaCompatibility(property.getType().getName());
-                property.setEntrySchema(deserializeEntrySchema(propertyJsonObject.get(ENTRY_SCHEMA)));
-                property.getEntrySchema().getKey().setParentConceptKey(property.getType());
-                property.getEntrySchema().getType().setVersion(property.getType().getVersion());
-            }
-
-            // Set property: constraints
-            if (propertyJsonObject.has(CONSTRAINTS)) {
-                property.setConstraints(deserializeConstraints(propertyJsonObject.get(CONSTRAINTS)));
-                for (JpaToscaConstraint c : property.getConstraints()) {
-                    c.getKey().setParentConceptKey(property.getType());
-                }
-            }
-
-            // Add property to properties list
-            properties.add(property);
-        }
-
-        return properties;
-    }
-
-    /**
-     * Serializes the properties.
-     *
-     * @param properties the list of ToscaProperty
-     *
-     * @return serialized JsonElement
-     */
-    public JsonElement serializeProperties(List<JpaToscaProperty> properties) {
-
-        JsonObject propertiesJsonObject = new JsonObject();
-
-        for (JpaToscaProperty property : properties) {
-            JsonObject propertyValJsonObject = new JsonObject();
-
-            // Add type
-            propertyValJsonObject.addProperty(TYPE, property.getType().getName());
-
-            // Add description
-            if (property.getDescription() != null) {
-                propertyValJsonObject.addProperty(DESCRIPTION, property.getDescription());
-            }
-
-            // Add required
-            propertyValJsonObject.addProperty(REQUIRED, property.isRequired());
-
-            // Add defaultValue
-            if (property.getDefaultValue() != null) {
-                propertyValJsonObject.addProperty(DEFAULT, property.getDefaultValue());
-            }
-
-            // Add constraints
-            if (property.getConstraints() != null) {
-                propertyValJsonObject.add(CONSTRAINTS, serializeConstraints(property.getConstraints()));
-            }
-
-            // Add entry_schema
-            if (property.getEntrySchema() != null) {
-                propertyValJsonObject.add(ENTRY_SCHEMA, serializeEntrySchema(property.getEntrySchema()));
-            }
-
-            propertiesJsonObject.add(property.getKey().getLocalName(), propertyValJsonObject);
-        }
-
-        return propertiesJsonObject;
-    }
-
-    private JsonElement serializeConstraints(List<JpaToscaConstraint> constraints) {
-
-        JsonArray constraintsValJsonArray = new JsonArray();
-
-        for (JpaToscaConstraint c : constraints) {
-            JsonObject constraintJsonObject = new JsonObject();
-
-            // Check which type of constraint it is
-            // TODO: here we only support valid_values and equal
-            if (c instanceof JpaToscaConstraintValidValues) {
-                JsonArray validValuesJsonArray = new JsonArray();
-                for (String validValue : ((JpaToscaConstraintValidValues)c).getValidValues()) {
-                    validValuesJsonArray.add(validValue);
-                }
-                constraintJsonObject.add(VALID_VALUES, validValuesJsonArray);
-            } else if (c instanceof JpaToscaConstraintLogicalString) {
-                constraintJsonObject.addProperty(EQUAL, ((JpaToscaConstraintLogicalString)c).getCompareToString());
-            } else {
-                String errorMessage = "constraint is neither valid_values nor equal";
-                LOGGER.debug(errorMessage);
-                throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage);
-            }
-
-            constraintsValJsonArray.add(constraintJsonObject);
-        }
-
-        return constraintsValJsonArray;
-    }
-
-    private JsonElement serializeEntrySchema(JpaToscaEntrySchema entrySchema) {
-
-        JsonObject entrySchemaValJsonObject = new JsonObject();
-
-        // Add type
-        entrySchemaValJsonObject.addProperty(TYPE, entrySchema.getType().getName());
-
-        // Add description
-        if (entrySchema.getDescription() != null) {
-            entrySchemaValJsonObject.addProperty(DESCRIPTION, entrySchema.getDescription());
-        }
-
-        // Add constraints
-        if (entrySchema.getConstraints() != null) {
-            entrySchemaValJsonObject.add(CONSTRAINTS, serializeConstraints(entrySchema.getConstraints()));
-        }
-
-        return entrySchemaValJsonObject;
-    }
-
-    private JpaToscaEntrySchema deserializeEntrySchema(JsonElement entrySchemaElement) {
-
-        JsonObject entrySchemaJsonObject = entrySchemaElement.getAsJsonObject();
-
-        // Set entry_schema: key and type
-        JpaToscaEntrySchema entrySchema = new JpaToscaEntrySchema(
-                new PfReferenceKey(new PfConceptKey(), ENTRY_SCHEMA),
-                new PfConceptKey(entrySchemaJsonObject.get(TYPE).getAsString(), DEFAULT_VERSION));
-
-        // Set entry_schema: description
-        if (entrySchemaJsonObject.has(DESCRIPTION)) {
-            entrySchema.setDescription(entrySchemaJsonObject.get(DESCRIPTION).getAsString());
-        }
-
-        // Set entry_schema: constraints
-        if (entrySchemaJsonObject.has(CONSTRAINTS)) {
-            entrySchema.setConstraints(deserializeConstraints(entrySchemaJsonObject.get(CONSTRAINTS)));
-            for (JpaToscaConstraint c : entrySchema.getConstraints()) {
-                c.getKey().setParentConceptKey(entrySchema.getType());
-            }
-        }
-
-        return entrySchema;
-    }
-
-    private List<JpaToscaConstraint> deserializeConstraints(JsonElement constraintsElement) {
-
-        JsonArray constraintsJsonArray = constraintsElement.getAsJsonArray();
-        List<JpaToscaConstraint> constraints = new LinkedList<>();
-
-        for (Iterator<JsonElement> constraintsIter = constraintsJsonArray.iterator(); constraintsIter.hasNext(); ) {
-            JsonObject constraintJsonObject = constraintsIter.next().getAsJsonObject();
-            // Check which type of constraint it is
-            // TODO: here we only check 'valid_values' and 'equal'
-            if (constraintJsonObject.get(VALID_VALUES) != null) {
-                List<String> validValues = new LinkedList<>();
-                for (Iterator<JsonElement> validValuesIter = constraintJsonObject.get(VALID_VALUES).getAsJsonArray()
-                        .iterator(); validValuesIter.hasNext(); ) {
-                    validValues.add(validValuesIter.next().getAsString());
-                }
-                JpaToscaConstraint constraint = new JpaToscaConstraintValidValues(
-                        new PfReferenceKey(new PfConceptKey(), VALID_VALUES), validValues);
-                constraints.add(constraint);
-            } else if (constraintJsonObject.get(EQUAL) != null) {
-                JpaToscaConstraint constraint = new JpaToscaConstraintLogicalString(new PfReferenceKey(
-                        new PfConceptKey(), EQUAL), Operation.EQ, constraintJsonObject.get(EQUAL).getAsString());
-                constraints.add(constraint);
-            } else {
-                String errorMessage = "specified constraint is neither valid_values nor equal";
-                LOGGER.debug(errorMessage);
-                throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
-            }
-        }
-
-        return constraints;
-    }
-
-    private void checkEntrySchemaCompatibility(String type) {
-        if (!("list".equalsIgnoreCase(type)) && !("map".equalsIgnoreCase(type))) {
-            String errorMessage = "entry schema can only be specified for list or map property";
-            LOGGER.debug(errorMessage);
-            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
-        }
-    }
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateJsonAdapter.java
deleted file mode 100644 (file)
index bb2ace8..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- *  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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.serialization;
-
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-
-import java.lang.reflect.Type;
-
-import lombok.NonNull;
-
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
-
-/**
- * GSON type adapter for TOSCA policies.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- * @author Chenfei Gao (cgao@research.att.com)
- */
-public class ToscaServiceTemplateJsonAdapter
-        implements JsonSerializer<JpaToscaServiceTemplate>, JsonDeserializer<JpaToscaServiceTemplate> {
-
-    private static final String TOPOLOGY_TEMPLATE = "topology_template";
-    private static final String TOSCA_DEFINITIONS_VERSION = "tosca_definitions_version";
-    private static final String POLICY_TYPES = "policy_types";
-    private static final String DATA_TYPES = "data_types";
-
-    @Override
-    public JpaToscaServiceTemplate deserialize(@NonNull final JsonElement serviceTemplateElement,
-            @NonNull final Type type, @NonNull final JsonDeserializationContext context) {
-
-        // The incoming JSON
-        final JsonObject serviceTemplateJsonObject = serviceTemplateElement.getAsJsonObject();
-
-        // The outgoing object
-        final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
-        serviceTemplate
-                .setToscaDefinitionsVersion(serviceTemplateJsonObject.get(TOSCA_DEFINITIONS_VERSION).getAsString());
-
-        // Set topology_template
-        if (serviceTemplateJsonObject.has(TOPOLOGY_TEMPLATE)) {
-            serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplateJsonAdapter().deserialize(
-                    serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE), JpaToscaTopologyTemplate.class, context));
-        }
-
-        // Set policy_types
-        if (serviceTemplateJsonObject.has(POLICY_TYPES)) {
-            serviceTemplate.setPolicyTypes(new ToscaPolicyTypesJsonAdapter()
-                    .deserialize(serviceTemplateJsonObject.get(POLICY_TYPES), JpaToscaPolicyTypes.class, context));
-        }
-
-        // Set data_types
-        if (serviceTemplateJsonObject.has(DATA_TYPES)) {
-            serviceTemplate.setDataTypes(new ToscaDataTypesJsonAdapter()
-                    .deserialize(serviceTemplateJsonObject.get(DATA_TYPES), JpaToscaDataTypes.class, context));
-        }
-
-        return serviceTemplate;
-    }
-
-    @Override
-    public JsonElement serialize(@NonNull final JpaToscaServiceTemplate serviceTemplate, @NonNull final Type type,
-            @NonNull final JsonSerializationContext context) {
-
-        JsonObject serviceTemplateJsonObject = new JsonObject();
-
-        // Serialize tosca_definitions_version
-        if (serviceTemplate.getToscaDefinitionsVersion() != null) {
-            serviceTemplateJsonObject.addProperty(TOSCA_DEFINITIONS_VERSION,
-                    serviceTemplate.getToscaDefinitionsVersion());
-        }
-
-        // Serialize topoligy_template
-        if (serviceTemplate.getTopologyTemplate() != null) {
-            JsonElement topologyTemplateJsonElement = new ToscaTopologyTemplateJsonAdapter()
-                    .serialize(serviceTemplate.getTopologyTemplate(), type, context);
-            serviceTemplateJsonObject.add(TOPOLOGY_TEMPLATE, topologyTemplateJsonElement);
-        }
-
-        // Serialize policy_types
-        if (serviceTemplate.getPolicyTypes() != null) {
-            JsonElement policyTypesJsonElement =
-                    new ToscaPolicyTypesJsonAdapter().serialize(serviceTemplate.getPolicyTypes(), type, context);
-            serviceTemplateJsonObject.add(POLICY_TYPES, policyTypesJsonElement);
-        }
-
-        // Serialize data_types
-        if (serviceTemplate.getDataTypes() != null) {
-            JsonElement dataTypesJsonElement =
-                    new ToscaDataTypesJsonAdapter().serialize(serviceTemplate.getDataTypes(), type, context);
-            serviceTemplateJsonObject.add(DATA_TYPES, dataTypesJsonElement);
-        }
-
-        return serviceTemplateJsonObject;
-    }
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java
deleted file mode 100644 (file)
index b15a830..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.serialization;
-
-import com.google.gson.GsonBuilder;
-
-import org.onap.policy.common.gson.GsonMessageBodyHandler;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Provider used to serialize and deserialize TOSCA objects using GSON.
- */
-public class ToscaServiceTemplateMessageBodyHandler extends GsonMessageBodyHandler {
-
-    public static final Logger logger = LoggerFactory.getLogger(ToscaServiceTemplateMessageBodyHandler.class);
-
-    /**
-     * Constructs the object.
-     */
-    public ToscaServiceTemplateMessageBodyHandler() {
-        this(new GsonBuilder());
-
-        logger.info("Using GSON with TOSCA for REST calls");
-    }
-
-    /**
-     * Constructs the object.
-     *
-     * @param builder builder to use to create the gson object
-     */
-    public ToscaServiceTemplateMessageBodyHandler(final GsonBuilder builder) {
-        // @formatter:off
-        super(builder
-                .registerTypeAdapter(JpaToscaServiceTemplate.class, new ToscaServiceTemplateJsonAdapter())
-                .registerTypeAdapter(JpaToscaTopologyTemplate.class, new ToscaTopologyTemplateJsonAdapter())
-                .registerTypeAdapter(JpaToscaPolicies.class, new ToscaPoliciesJsonAdapter())
-                .registerTypeAdapter(JpaToscaPolicy.class, new ToscaPolicyJsonAdapter())
-                .registerTypeAdapter(JpaToscaPolicyTypes.class, new ToscaPolicyTypesJsonAdapter())
-                .registerTypeAdapter(JpaToscaPolicyType.class, new ToscaPolicyTypeJsonAdapter())
-                .registerTypeAdapter(JpaToscaDataTypes.class, new ToscaDataTypesJsonAdapter())
-                .registerTypeAdapter(JpaToscaDataType.class, new ToscaDataTypeJsonAdapter())
-                .setPrettyPrinting()
-                .create()
-        );
-        // @formatter:on
-    }
-
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaTopologyTemplateJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaTopologyTemplateJsonAdapter.java
deleted file mode 100644 (file)
index df8ebb5..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- *  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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.serialization;
-
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-
-import java.lang.reflect.Type;
-
-import lombok.NonNull;
-
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
-
-/**
- * GSON type adapter for TOSCA policies.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- * @author Chenfei Gao (cgao@research.att.com)
- */
-public class ToscaTopologyTemplateJsonAdapter
-        implements JsonSerializer<JpaToscaTopologyTemplate>, JsonDeserializer<JpaToscaTopologyTemplate> {
-
-    private static final String POLICIES = "policies";
-    private static final String DESCRIPTION = "description";
-
-    @Override
-    public JpaToscaTopologyTemplate deserialize(@NonNull final JsonElement toplogyTemplateElement,
-            @NonNull final Type type, @NonNull final JsonDeserializationContext context) {
-
-        // The incoming JSON
-        final JsonObject topologyTemplateJsonObject = toplogyTemplateElement.getAsJsonObject();
-
-        // The outgoing object
-        final PfReferenceKey topologyTemplateKey = new PfReferenceKey(new PfConceptKey(), "IncomingTopologyTemplate");
-        final JpaToscaTopologyTemplate topologyTemplate = new JpaToscaTopologyTemplate(topologyTemplateKey);
-
-        if (topologyTemplateJsonObject.has(DESCRIPTION)) {
-            topologyTemplate.setDescription(topologyTemplateJsonObject.get(DESCRIPTION).getAsString());
-        }
-
-        if (topologyTemplateJsonObject.has(POLICIES)) {
-            topologyTemplate.setPolicies(new ToscaPoliciesJsonAdapter()
-                    .deserialize(topologyTemplateJsonObject.get(POLICIES), JpaToscaPolicies.class, context));
-        }
-
-        return topologyTemplate;
-    }
-
-    @Override
-    public JsonElement serialize(@NonNull final JpaToscaTopologyTemplate topologyTemplate, @NonNull final Type type,
-            @NonNull final JsonSerializationContext context) {
-
-        JsonObject topologyTemplateJsonObject = new JsonObject();
-        JsonElement policiesJsonElement = new ToscaPoliciesJsonAdapter()
-                .serialize(topologyTemplate.getPolicies(), type, context);
-
-        topologyTemplateJsonObject.add(POLICIES, policiesJsonElement);
-
-        if (topologyTemplate.getDescription() != null) {
-            topologyTemplateJsonObject.addProperty(DESCRIPTION, topologyTemplate.getDescription());
-        }
-
-        return topologyTemplateJsonObject;
-    }
-}
@@ -3,6 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,6 +23,7 @@
 
 package org.onap.policy.models.tosca.authorative.mapping;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -30,8 +32,11 @@ import org.junit.Test;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.yaml.snakeyaml.Yaml;
 
 /**
@@ -39,15 +44,14 @@ import org.yaml.snakeyaml.Yaml;
  *
  * @author Chenfei Gao (cgao@research.att.com)
  */
-public class PlainToscaServiceTemplateMapperTest {
+public class ToscaServiceTemplateMappingTest {
+    private static final Logger LOGGER = LoggerFactory.getLogger(ToscaServiceTemplateMappingTest.class);
 
     private StandardCoder standardCoder;
-    private PlainToscaServiceTemplateMapper mapper;
 
     @Before
     public void setUp() {
         standardCoder = new StandardCoder();
-        mapper = new PlainToscaServiceTemplateMapper();
     }
 
     @Test
@@ -56,12 +60,19 @@ public class PlainToscaServiceTemplateMapperTest {
             String inputJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json");
 
             ToscaServiceTemplate plainPolicies = standardCoder.decode(inputJson, ToscaServiceTemplate.class);
-            JpaToscaServiceTemplate internalPolicies = mapper.toToscaServiceTemplate(plainPolicies);
+            JpaToscaServiceTemplate internalPolicies = new JpaToscaServiceTemplate();
+            internalPolicies.fromAuthorative(plainPolicies);
+
             assertTrue(internalPolicies.validate(new PfValidationResult()).isValid());
-            ToscaServiceTemplate plainPolicies2 = mapper.fromToscaServiceTemplate(internalPolicies);
-            assertTrue(plainPolicies.equals(plainPolicies2));
+            ToscaServiceTemplate plainPolicies2 = internalPolicies.toAuthorative();
+
+            ToscaPolicy pp1 = plainPolicies.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
+            ToscaPolicy pp2 = plainPolicies2.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
+
+            assertEquals(pp1.getProperties().keySet(), pp2.getProperties().keySet());
 
         } catch (Exception e) {
+            LOGGER.warn("no exception should be thrown", e);
             fail("no exception should be thrown");
         }
     }
@@ -77,14 +88,17 @@ public class PlainToscaServiceTemplateMapperTest {
 
             ToscaServiceTemplate plainPolicyTypes = standardCoder.decode(yamlAsJsonString,
                     ToscaServiceTemplate.class);
-            JpaToscaServiceTemplate internalPolicyTypes = mapper.toToscaServiceTemplate(plainPolicyTypes);
+            JpaToscaServiceTemplate internalPolicyTypes = new JpaToscaServiceTemplate();
+            internalPolicyTypes.fromAuthorative(plainPolicyTypes);
             assertTrue(internalPolicyTypes.validate(new PfValidationResult()).isValid());
-            ToscaServiceTemplate plainPolicyTypes2 = mapper.fromToscaServiceTemplate(internalPolicyTypes);
-            JpaToscaServiceTemplate internalPolicyTypes2 = mapper.toToscaServiceTemplate(plainPolicyTypes2);
+            ToscaServiceTemplate plainPolicyTypes2 = internalPolicyTypes.toAuthorative();
+            JpaToscaServiceTemplate internalPolicyTypes2 = new JpaToscaServiceTemplate();
+            internalPolicyTypes2.fromAuthorative(plainPolicyTypes2);
             assertTrue(internalPolicyTypes2.validate(new PfValidationResult()).isValid());
             assertTrue(internalPolicyTypes.compareTo(internalPolicyTypes2) == 0);
 
         } catch (Exception e) {
+            LOGGER.warn("no exception should be thrown", e);
             fail("no exception should be thrown");
         }
 
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKeyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKeyTest.java
deleted file mode 100644 (file)
index 98d7dcf..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.concepts;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.junit.Test;
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalKey;
-
-/**
- * DAO test for ToscaConstraintLogicalKey.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- */
-public class JpaToscaConstraintLogicalKeyTest {
-
-    @Test
-    public void testConstraintLogicalKeyPojo() {
-        assertNotNull(new JpaToscaConstraintLogicalKey());
-        assertNotNull(new JpaToscaConstraintLogicalKey(new PfReferenceKey()));
-        assertNotNull(new JpaToscaConstraintLogicalKey(new PfReferenceKey(), JpaToscaConstraintLogicalKey.Operation.EQ,
-                new PfConceptKey()));
-
-        try {
-            new JpaToscaConstraintLogicalKey((PfReferenceKey) null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("key is marked @NonNull but is null", exc.getMessage());
-        }
-
-        try {
-            new JpaToscaConstraintLogicalKey((JpaToscaConstraintLogicalKey) null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
-        }
-
-        PfConceptKey tclParentKey = new PfConceptKey("tParentKey", "0.0.1");
-        PfReferenceKey tclKey = new PfReferenceKey(tclParentKey, "trigger0");
-        PfConceptKey constraintKey = new PfConceptKey("tParentKey", "0.0.1");
-        JpaToscaConstraintLogicalKey tcl =
-                new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.Operation.EQ, constraintKey);
-
-        try {
-            new JpaToscaConstraintLogicalKey(tcl);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("cannot copy an immutable constraint", exc.getMessage());
-        }
-
-        JpaToscaConstraintLogicalKey tclClone1 = new JpaToscaConstraintLogicalKey();
-        try {
-            tcl.copyTo(tclClone1);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("cannot copy an immutable constraint", exc.getMessage());
-        }
-        tclClone1 = new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.Operation.EQ, constraintKey);
-
-        assertEquals(tcl, tclClone1);
-        assertEquals(0, tcl.compareTo(tclClone1));
-
-        assertEquals(-1, tcl.compareTo(null));
-        assertEquals(0, tcl.compareTo(tcl));
-        assertFalse(tcl.compareTo(tcl.getKey()) == 0);
-
-        JpaToscaConstraintLogicalKey differentTcl = new JpaToscaConstraintLogicalKey(new PfReferenceKey(),
-                JpaToscaConstraintLogicalKey.Operation.EQ, constraintKey);
-        assertFalse(tcl.compareTo(differentTcl) == 0);
-
-        JpaToscaConstraintLogicalKey otherTc =
-                new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.Operation.EQ, constraintKey);
-        assertEquals(0, tcl.compareTo(otherTc));
-
-        try {
-            tcl.copyTo(null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("target is marked @NonNull but is null", exc.getMessage());
-        }
-
-        assertEquals(2, tcl.getKeys().size());
-        assertEquals(2, new JpaToscaConstraintLogicalKey().getKeys().size());
-
-        new JpaToscaConstraintLogicalKey().clean();
-        tcl.clean();
-        assertEquals(tclClone1, tcl);
-
-        assertFalse(new JpaToscaConstraintLogicalKey().validate(new PfValidationResult()).isValid());
-        assertTrue(tcl.validate(new PfValidationResult()).isValid());
-
-        try {
-            tcl.validate(null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
-        }
-
-        try {
-            new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.Operation.EQ, null)
-                    .validate(new PfValidationResult());
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("compareToKey is marked @NonNull but is null", exc.getMessage());
-        }
-
-        assertFalse(
-                new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.Operation.EQ, new PfConceptKey())
-                        .validate(new PfValidationResult()).isValid());
-    }
-}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalStringTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalStringTest.java
deleted file mode 100644 (file)
index c27ec26..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.simple.concepts;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.junit.Test;
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
-
-/**
- * DAO test for ToscaConstraintLogicalString.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- */
-public class JpaToscaConstraintLogicalStringTest {
-
-    @Test
-    public void testConstraintLogicalStringPojo() {
-        assertNotNull(new JpaToscaConstraintLogicalString());
-        assertNotNull(new JpaToscaConstraintLogicalString(new PfReferenceKey()));
-        assertNotNull(new JpaToscaConstraintLogicalString(new PfReferenceKey(),
-                JpaToscaConstraintLogicalString.Operation.EQ, "Constraint"));
-
-        try {
-            new JpaToscaConstraintLogicalString((PfReferenceKey) null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("key is marked @NonNull but is null", exc.getMessage());
-        }
-
-        try {
-            new JpaToscaConstraintLogicalString((JpaToscaConstraintLogicalString) null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
-        }
-
-        PfConceptKey tclParentKey = new PfConceptKey("tParentKey", "0.0.1");
-        PfReferenceKey tclKey = new PfReferenceKey(tclParentKey, "trigger0");
-        JpaToscaConstraintLogicalString tcl =
-                new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.Operation.EQ, "Constraint");
-
-        try {
-            new JpaToscaConstraintLogicalString(tcl);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("cannot copy an immutable constraint", exc.getMessage());
-        }
-
-        JpaToscaConstraintLogicalString tclClone1 = new JpaToscaConstraintLogicalString();
-        try {
-            tcl.copyTo(tclClone1);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("cannot copy an immutable constraint", exc.getMessage());
-        }
-        tclClone1 =
-                new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.Operation.EQ, "Constraint");
-
-        assertEquals(tcl, tclClone1);
-        assertEquals(0, tcl.compareTo(tclClone1));
-
-        assertEquals(-1, tcl.compareTo(null));
-        assertEquals(0, tcl.compareTo(tcl));
-        assertFalse(tcl.compareTo(tcl.getKey()) == 0);
-
-        JpaToscaConstraintLogicalString differentTcl = new JpaToscaConstraintLogicalString(new PfReferenceKey(),
-                JpaToscaConstraintLogicalString.Operation.EQ, "Constraint");
-        assertFalse(tcl.compareTo(differentTcl) == 0);
-
-        JpaToscaConstraintLogicalString otherTc =
-                new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.Operation.EQ, "Constraint");
-        assertEquals(0, tcl.compareTo(otherTc));
-
-        try {
-            tcl.copyTo(null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("target is marked @NonNull but is null", exc.getMessage());
-        }
-
-        assertEquals(1, tcl.getKeys().size());
-        assertEquals(1, new JpaToscaConstraintLogicalString().getKeys().size());
-
-        new JpaToscaConstraintLogicalString().clean();
-        tcl.clean();
-        assertEquals(tclClone1, tcl);
-
-        assertFalse(new JpaToscaConstraintLogicalString().validate(new PfValidationResult()).isValid());
-        assertTrue(tcl.validate(new PfValidationResult()).isValid());
-
-        try {
-            tcl.validate(null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
-        }
-
-        try {
-            new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.Operation.EQ, null)
-                    .validate(new PfValidationResult());
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("compareToString is marked @NonNull but is null", exc.getMessage());
-        }
-
-        assertFalse(new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.Operation.EQ, "")
-                .validate(new PfValidationResult()).isValid());
-    }
-}
index 2da46a7..de0c813 100644 (file)
 package org.onap.policy.models.tosca.simple.concepts;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import org.junit.Test;
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
-import org.onap.policy.models.tosca.simple.concepts.testconcepts.DummyToscaConstraint;
 
 /**
- * DAO test for ToscaConstraintLogical.
+ * DAO test for ToscaConstraintLogicalString.
  *
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class JpaToscaConstraintLogicalTest {
 
     @Test
-    public void testConstraintLogicalPojo() {
-        assertNotNull(new JpaToscaConstraintLogical());
-        assertNotNull(new JpaToscaConstraintLogical(new PfReferenceKey()));
+    public void testConstraintLogicalStringPojo() {
+        assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"));
 
         try {
-            new JpaToscaConstraintLogical((PfReferenceKey) null);
+            new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, null);
             fail("test should throw an exception");
         } catch (Exception exc) {
-            assertEquals("key is marked @NonNull but is null", exc.getMessage());
+            assertEquals("operation is marked @NonNull but is null", exc.getMessage());
         }
 
         try {
-            new JpaToscaConstraintLogical((JpaToscaConstraintLogical) null);
+            new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, "Hello");
             fail("test should throw an exception");
         } catch (Exception exc) {
-            assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+            assertEquals("operation is marked @NonNull but is null", exc.getMessage());
         }
 
-        PfConceptKey tclParentKey = new PfConceptKey("tParentKey", "0.0.1");
-        PfReferenceKey tclKey = new PfReferenceKey(tclParentKey, "trigger0");
-        JpaToscaConstraintLogical tcl = new JpaToscaConstraintLogical(tclKey, JpaToscaConstraintLogical.Operation.EQ);
-
-        try {
-            new JpaToscaConstraintLogical(tcl);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("cannot copy an immutable constraint", exc.getMessage());
-        }
-
-        JpaToscaConstraintLogical tclClone1 = new JpaToscaConstraintLogical();
-        try {
-            tcl.copyTo(tclClone1);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("cannot copy an immutable constraint", exc.getMessage());
-        }
-        tclClone1 = new JpaToscaConstraintLogical(tclKey, JpaToscaConstraintLogical.Operation.EQ);
-
-        assertEquals(tcl, tclClone1);
-        assertEquals(0, tcl.compareTo(tclClone1));
-
-        assertEquals(-1, tcl.compareTo(null));
-        assertEquals(0, tcl.compareTo(tcl));
-        assertFalse(tcl.compareTo(tcl.getKey()) == 0);
-
-        JpaToscaConstraintLogical differentTcl =
-                new JpaToscaConstraintLogical(new PfReferenceKey(), JpaToscaConstraintLogical.Operation.EQ);
-        assertFalse(tcl.compareTo(differentTcl) == 0);
-
-        JpaToscaConstraintLogical otherTc =
-                new JpaToscaConstraintLogical(tclKey, JpaToscaConstraintLogical.Operation.EQ);
-        assertEquals(0, tcl.compareTo(otherTc));
-
-        try {
-            tcl.copyTo(null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("target is marked @NonNull but is null", exc.getMessage());
-        }
-
-        assertEquals(1, tcl.getKeys().size());
-        assertEquals(1, new JpaToscaConstraintLogical().getKeys().size());
-
-        JpaToscaConstraintLogical tclClone0 = new JpaToscaConstraintLogical();
-        new JpaToscaConstraintLogical().clean();
-        tcl.clean();
-        assertEquals(tclClone0, tcl);
-
-        assertFalse(new JpaToscaConstraintLogical().validate(new PfValidationResult()).isValid());
-        assertTrue(tcl.validate(new PfValidationResult()).isValid());
-
-        try {
-            tcl.validate(null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
-        }
-
-        DummyToscaConstraint dtc = new DummyToscaConstraint();
-        try {
-            new DummyToscaConstraint(dtc);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("cannot copy an immutable constraint", exc.getMessage());
-        }
-
-        try {
-            new DummyToscaConstraint((PfReferenceKey) null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("key is marked @NonNull but is null", exc.getMessage());
-        }
-
-        try {
-            new DummyToscaConstraint((DummyToscaConstraint) null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
-        }
-
-        DummyToscaConstraint dtcClone = new DummyToscaConstraint();
-
-        assertEquals(dtc, dtcClone);
-        assertEquals(dtc, dtc);
-        assertEquals(0, dtc.compareTo(dtcClone));
-        assertEquals(0, dtc.compareTo(dtc));
-        assertEquals(-1, dtc.compareTo(null));
-        assertEquals(0, dtc.compareTo(dtcClone));
-        assertFalse(dtc.compareTo(dtcClone.getKey()) == 0);
-
         try {
-            dtc.copyTo(null);
+            new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, null);
             fail("test should throw an exception");
         } catch (Exception exc) {
-            assertEquals("target is marked @NonNull but is null", exc.getMessage());
+            assertEquals("compareTo is marked @NonNull but is null", exc.getMessage());
         }
 
-        try {
-            dtc.copyTo(dtcClone);
-            fail("target should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("cannot copy an immutable constraint", exc.getMessage());
-        }
+        assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"));
     }
 }
index bf710e8..efdddcc 100644 (file)
@@ -27,15 +27,15 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
 
@@ -70,15 +70,14 @@ public class JpaToscaDataTypeTest {
         JpaToscaDataType tdt = new JpaToscaDataType(dtKey);
 
         List<JpaToscaConstraint> constraints = new ArrayList<>();
-        JpaToscaConstraintLogicalString lsc =
-                new JpaToscaConstraintLogicalString(new PfReferenceKey(dtKey, "sc"), Operation.EQ, "hello");
+        JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
         constraints.add(lsc);
         tdt.setConstraints(constraints);
         assertEquals(constraints, tdt.getConstraints());
 
-        List<JpaToscaProperty> properties = new ArrayList<>();
+        Map<String, JpaToscaProperty> properties = new LinkedHashMap<>();
         JpaToscaProperty tp = new JpaToscaProperty(new PfReferenceKey(dtKey, "pr"), new PfConceptKey("type", "0.0.1"));
-        properties.add(tp);
+        properties.put(tp.getKey().getLocalName(), tp);
         tdt.setProperties(properties);
         assertEquals(properties, tdt.getProperties());
 
@@ -113,7 +112,7 @@ public class JpaToscaDataTypeTest {
             assertEquals("target is marked @NonNull but is null", exc.getMessage());
         }
 
-        assertEquals(4, tdt.getKeys().size());
+        assertEquals(3, tdt.getKeys().size());
         assertEquals(1, new JpaToscaDataType().getKeys().size());
 
         new JpaToscaDataType().clean();
@@ -128,7 +127,7 @@ public class JpaToscaDataTypeTest {
         tdt.getConstraints().remove(null);
         assertTrue(tdt.validate(new PfValidationResult()).isValid());
 
-        tdt.getProperties().add(null);
+        tdt.getProperties().put(null, null);
         assertFalse(tdt.validate(new PfValidationResult()).isValid());
         tdt.getProperties().remove(null);
         assertTrue(tdt.validate(new PfValidationResult()).isValid());
index a69b9a7..4a9bdbe 100644 (file)
@@ -31,11 +31,8 @@ import java.util.List;
 
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
 
 /**
@@ -47,16 +44,14 @@ public class JpaToscaEntrySchemaTest {
 
     @Test
     public void testEntrySchemaPojo() {
-        assertNotNull(new JpaToscaEntrySchema());
-        assertNotNull(new JpaToscaEntrySchema(new PfReferenceKey()));
-        assertNotNull(new JpaToscaEntrySchema(new PfReferenceKey(), new PfConceptKey()));
-        assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema()));
+        assertNotNull(new JpaToscaEntrySchema(new PfConceptKey()));
+        assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema(new PfConceptKey())));
 
         try {
-            new JpaToscaEntrySchema((PfReferenceKey) null);
+            new JpaToscaEntrySchema((PfConceptKey) null);
             fail("test should throw an exception");
         } catch (Exception exc) {
-            assertEquals("key is marked @NonNull but is null", exc.getMessage());
+            assertEquals("type is marked @NonNull but is null", exc.getMessage());
         }
 
         try {
@@ -66,16 +61,14 @@ public class JpaToscaEntrySchemaTest {
             assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
         }
 
-        PfReferenceKey esKey = new PfReferenceKey("entrySchemaParent", "0.0.1", "entrySchema");
         PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
-        JpaToscaEntrySchema tes = new JpaToscaEntrySchema(esKey, typeKey);
+        JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
 
         tes.setDescription("A Description");
         assertEquals("A Description", tes.getDescription());
 
         List<JpaToscaConstraint> constraints = new ArrayList<>();
-        JpaToscaConstraintLogicalString lsc =
-                new JpaToscaConstraintLogicalString(new PfReferenceKey(esKey, "sc"), Operation.EQ, "hello");
+        JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
         constraints.add(lsc);
         tes.setConstraints(constraints);
         assertEquals(constraints, tes.getConstraints());
@@ -84,20 +77,15 @@ public class JpaToscaEntrySchemaTest {
         assertEquals(tes, tdtClone0);
         assertEquals(0, tes.compareTo(tdtClone0));
 
-        JpaToscaEntrySchema tdtClone1 = new JpaToscaEntrySchema();
-        tes.copyTo(tdtClone1);
+        JpaToscaEntrySchema tdtClone1 = new JpaToscaEntrySchema(tes);
         assertEquals(tes, tdtClone1);
         assertEquals(0, tes.compareTo(tdtClone1));
 
         assertEquals(-1, tes.compareTo(null));
         assertEquals(0, tes.compareTo(tes));
-        assertFalse(tes.compareTo(tes.getKey()) == 0);
 
-        PfReferenceKey otherEsKey = new PfReferenceKey("entrySchemaParent", "0.0.1", "otherEntrySchema");
-        JpaToscaEntrySchema otherEs = new JpaToscaEntrySchema(otherEsKey);
+        JpaToscaEntrySchema otherEs = new JpaToscaEntrySchema(typeKey);
 
-        assertFalse(tes.compareTo(otherEs) == 0);
-        otherEs.setKey(esKey);
         assertFalse(tes.compareTo(otherEs) == 0);
         otherEs.setType(typeKey);
         assertFalse(tes.compareTo(otherEs) == 0);
@@ -113,14 +101,14 @@ public class JpaToscaEntrySchemaTest {
             assertEquals("target is marked @NonNull but is null", exc.getMessage());
         }
 
-        assertEquals(3, tes.getKeys().size());
-        assertEquals(2, new JpaToscaEntrySchema().getKeys().size());
+        assertEquals(1, tes.getKeys().size());
+        assertEquals(1, new JpaToscaEntrySchema(typeKey).getKeys().size());
 
-        new JpaToscaEntrySchema().clean();
+        new JpaToscaEntrySchema(typeKey).clean();
         tes.clean();
         assertEquals(tdtClone0, tes);
 
-        assertFalse(new JpaToscaEntrySchema().validate(new PfValidationResult()).isValid());
+        assertTrue(new JpaToscaEntrySchema(typeKey).validate(new PfValidationResult()).isValid());
         assertTrue(tes.validate(new PfValidationResult()).isValid());
 
         tes.setType(PfConceptKey.getNullKey());
index 7dac268..870640e 100644 (file)
@@ -28,6 +28,7 @@ import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -35,6 +36,7 @@ import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
@@ -46,7 +48,6 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class JpaToscaPolicyTypeTest {
-
     @Test
     public void testPolicyTypePojo() {
         assertNotNull(new JpaToscaPolicyType());
@@ -81,9 +82,9 @@ public class JpaToscaPolicyTypeTest {
         tpt.setDescription("A Description");
 
         PfConceptKey propTypeKey = new PfConceptKey("propType", "0.0.1");
-        List<JpaToscaProperty> properties = new ArrayList<>();
+        Map<String, JpaToscaProperty> properties = new LinkedHashMap<>();
         JpaToscaProperty tp = new JpaToscaProperty(new PfReferenceKey(ptKey, "aProp"), propTypeKey);
-        properties.add(tp);
+        properties.put(tp.getKey().getLocalName(), tp);
         tpt.setProperties(properties);
         assertEquals(properties, tpt.getProperties());
 
@@ -148,7 +149,7 @@ public class JpaToscaPolicyTypeTest {
         assertFalse(new JpaToscaPolicyType().validate(new PfValidationResult()).isValid());
         assertTrue(tpt.validate(new PfValidationResult()).isValid());
 
-        tpt.getProperties().add(null);
+        tpt.getProperties().put(null, null);
         assertFalse(tpt.validate(new PfValidationResult()).isValid());
         tpt.getProperties().remove(null);
         assertTrue(tpt.validate(new PfValidationResult()).isValid());
@@ -191,20 +192,20 @@ public class JpaToscaPolicyTypeTest {
         }
 
         try {
-            new JpaToscaEntityType((PfConceptKey) null);
+            new JpaToscaEntityType<ToscaPolicy>((PfConceptKey) null);
             fail("test should throw an exception");
         } catch (Exception exc) {
             assertEquals("key is marked @NonNull but is null", exc.getMessage());
         }
 
         try {
-            new JpaToscaEntityType((JpaToscaEntityType) null);
+            new JpaToscaEntityType<ToscaPolicy>((JpaToscaEntityType<ToscaPolicy>) null);
             fail("test should throw an exception");
         } catch (Exception exc) {
             assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
         }
 
-        JpaToscaEntityType tet = new JpaToscaEntityType(tpt.getKey());
+        JpaToscaEntityType<ToscaPolicy> tet = new JpaToscaEntityType<ToscaPolicy>(tpt.getKey());
         assertEquals(-1, tet.compareTo(null));
         assertEquals(0, tet.compareTo(tet));
         assertFalse(tet.compareTo(tet.getKey()) == 0);
index 8d46c95..83100cc 100644 (file)
@@ -33,11 +33,8 @@ import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
 
 /**
  * DAO test for ToscaProperty.
@@ -101,18 +98,16 @@ public class JpaToscaPropertyTest {
 
         tp.setDefaultValue("defaultKey");
 
-        tp.setStatus(JpaToscaProperty.Status.SUPPORTED);
+        tp.setStatus(ToscaProperty.Status.SUPPORTED);
 
         List<JpaToscaConstraint> constraints = new ArrayList<>();
-        JpaToscaConstraintLogicalString lsc =
-                new JpaToscaConstraintLogicalString(new PfReferenceKey(pkey, "sc"), Operation.EQ, "hello");
+        JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
         constraints.add(lsc);
         tp.setConstraints(constraints);
         assertEquals(constraints, tp.getConstraints());
 
-        PfReferenceKey esKey = new PfReferenceKey(pkey, "entrySchema");
         PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
-        JpaToscaEntrySchema tes = new JpaToscaEntrySchema(esKey, typeKey);
+        JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
         tp.setEntrySchema(tes);
 
         JpaToscaProperty tdtClone0 = new JpaToscaProperty(tp);
@@ -142,7 +137,7 @@ public class JpaToscaPropertyTest {
         assertFalse(tp.compareTo(otherDt) == 0);
         otherDt.setDefaultValue("defaultKey");
         assertFalse(tp.compareTo(otherDt) == 0);
-        otherDt.setStatus(JpaToscaProperty.Status.SUPPORTED);
+        otherDt.setStatus(ToscaProperty.Status.SUPPORTED);
         assertFalse(tp.compareTo(otherDt) == 0);
         assertFalse(tp.compareTo(otherDt) == 0);
         otherDt.setConstraints(constraints);
@@ -155,9 +150,9 @@ public class JpaToscaPropertyTest {
         otherDt.setRequired(false);
         assertEquals(0, tp.compareTo(otherDt));
 
-        otherDt.setStatus(JpaToscaProperty.Status.UNSUPPORTED);
+        otherDt.setStatus(ToscaProperty.Status.UNSUPPORTED);
         assertFalse(tp.compareTo(otherDt) == 0);
-        otherDt.setStatus(JpaToscaProperty.Status.SUPPORTED);
+        otherDt.setStatus(ToscaProperty.Status.SUPPORTED);
         assertEquals(0, tp.compareTo(otherDt));
 
         try {
@@ -167,7 +162,7 @@ public class JpaToscaPropertyTest {
             assertEquals("target is marked @NonNull but is null", exc.getMessage());
         }
 
-        assertEquals(5, tp.getKeys().size());
+        assertEquals(3, tp.getKeys().size());
         assertEquals(2, new JpaToscaProperty().getKeys().size());
 
         new JpaToscaProperty().clean();
index 661882a..0f69cb3 100644 (file)
@@ -33,8 +33,6 @@ import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaEventFilter;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaTimeInterval;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger;
@@ -128,8 +126,7 @@ public class JpaToscaTriggerTest {
                 new JpaToscaEventFilter(new PfReferenceKey(tkey, "filter"), new PfConceptKey("NodeName", "0.0.1"));
         tdt.setTargetFilter(targetFilter);
 
-        JpaToscaConstraintLogicalString lsc =
-                new JpaToscaConstraintLogicalString(new PfReferenceKey(tkey, "sc"), Operation.EQ, "hello");
+        JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
         tdt.setCondition(lsc);
         assertEquals(lsc, tdt.getCondition());
         tdt.setConstraint(lsc);
@@ -194,7 +191,7 @@ public class JpaToscaTriggerTest {
             assertEquals("target is marked @NonNull but is null", exc.getMessage());
         }
 
-        assertEquals(6, tdt.getKeys().size());
+        assertEquals(4, tdt.getKeys().size());
         assertEquals(1, new JpaToscaTrigger().getKeys().size());
 
         new JpaToscaTrigger().clean();
index b3bdedf..e5be498 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,7 +27,6 @@ import com.openpojo.reflection.filters.FilterPackageInfo;
 import com.openpojo.validation.Validator;
 import com.openpojo.validation.ValidatorBuilder;
 import com.openpojo.validation.rule.impl.GetterMustExistRule;
-import com.openpojo.validation.rule.impl.SetterMustExistRule;
 import com.openpojo.validation.test.impl.GetterTester;
 import com.openpojo.validation.test.impl.SetterTester;
 
@@ -45,9 +45,16 @@ public class TestPojos {
 
     @Test
     public void testPojos() {
-        final Validator validator = ValidatorBuilder.create().with(new ToStringTester())
-                .with(new SetterMustExistRule()).with(new GetterMustExistRule()).with(new SetterTester())
-                .with(new GetterTester()).build();
+        // @formatter:off
+        final Validator validator = ValidatorBuilder
+                .create()
+                .with(new ToStringTester())
+                .with(new GetterMustExistRule())
+                .with(new SetterTester())
+                .with(new GetterTester())
+                .build();
+        // @formatter:on
+
         validator.validate(POJO_PACKAGE, new FilterPackageInfo());
     }
 }
index a743e28..b13cb4b 100644 (file)
 
 package org.onap.policy.models.tosca.simple.concepts.testconcepts;
 
-import javax.ws.rs.core.Response;
-
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
 
 /**
@@ -38,25 +35,14 @@ public class DummyToscaConstraint extends JpaToscaConstraint {
      * The Default Constructor creates a {@link DummyToscaConstraint} object with a null key.
      */
     public DummyToscaConstraint() {
-        super(new PfReferenceKey());
     }
 
-    /**
-     * The Key Constructor creates a {@link DummyToscaConstraint} object with the given concept key.
-     *
-     * @param key the key of the constraint
-     */
-    public DummyToscaConstraint(final PfReferenceKey key) {
-        super(key);
+    @Override
+    public ToscaConstraint toAuthorative() {
+        return null;
     }
 
-    /**
-     * Copy constructor.
-     *
-     * @param copyConcept the concept to copy from
-     */
-    public DummyToscaConstraint(final DummyToscaConstraint copyConcept) {
-        super(copyConcept);
-        throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+    @Override
+    public void fromAuthorative(ToscaConstraint authorativeConcept) {
     }
 }
index 029c7a7..0d486e3 100644 (file)
@@ -24,14 +24,13 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
-import com.google.gson.Gson;
-
 import java.sql.Connection;
 import java.sql.DriverManager;
 
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelException;
@@ -39,10 +38,10 @@ import org.onap.policy.models.dao.DaoParameters;
 import org.onap.policy.models.dao.PfDao;
 import org.onap.policy.models.dao.PfDaoFactory;
 import org.onap.policy.models.dao.impl.DefaultPfDao;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
 
 /**
  * Test the {@link SimpleToscaProvider} class.
@@ -52,7 +51,7 @@ import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMes
 public class SimpleToscaProviderTest {
     private Connection connection;
     private PfDao pfDao;
-    private Gson gson;
+    private StandardCoder standardCoder;
 
 
     /**
@@ -82,7 +81,7 @@ public class SimpleToscaProviderTest {
      */
     @Before
     public void setupGson() {
-        gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
+        standardCoder = new StandardCoder();
     }
 
     @After
@@ -92,7 +91,7 @@ public class SimpleToscaProviderTest {
     }
 
     @Test
-    public void testPoliciesGet() throws PfModelException {
+    public void testPoliciesGet() throws Exception {
         try {
             new SimpleToscaProvider().getPolicies(null, null);
             fail("test should throw an exception here");
@@ -114,9 +113,12 @@ public class SimpleToscaProviderTest {
             assertEquals("policyKey is marked @NonNull but is null", exc.getMessage());
         }
 
-        JpaToscaServiceTemplate originalServiceTemplate =
-                gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
-                        JpaToscaServiceTemplate.class);
+        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
+                ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+                ToscaServiceTemplate.class);
+
+        JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
+        originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
         assertNotNull(originalServiceTemplate);
         JpaToscaServiceTemplate createdServiceTemplate =
@@ -135,7 +137,7 @@ public class SimpleToscaProviderTest {
     }
 
     @Test
-    public void testPolicyCreate() throws PfModelException {
+    public void testPolicyCreate() throws Exception {
         try {
             new SimpleToscaProvider().createPolicies(null, null);
             fail("test should throw an exception here");
@@ -157,9 +159,12 @@ public class SimpleToscaProviderTest {
             assertEquals("serviceTemplate is marked @NonNull but is null", exc.getMessage());
         }
 
-        JpaToscaServiceTemplate originalServiceTemplate =
-                gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
-                        JpaToscaServiceTemplate.class);
+        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
+                ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+                ToscaServiceTemplate.class);
+
+        JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
+        originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
         assertNotNull(originalServiceTemplate);
         JpaToscaServiceTemplate createdServiceTemplate =
@@ -169,7 +174,7 @@ public class SimpleToscaProviderTest {
     }
 
     @Test
-    public void testPolicyUpdate() throws PfModelException {
+    public void testPolicyUpdate() throws Exception {
         try {
             new SimpleToscaProvider().updatePolicies(null, null);
             fail("test should throw an exception here");
@@ -191,9 +196,12 @@ public class SimpleToscaProviderTest {
             assertEquals("serviceTemplate is marked @NonNull but is null", exc.getMessage());
         }
 
-        JpaToscaServiceTemplate originalServiceTemplate =
-                gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
-                        JpaToscaServiceTemplate.class);
+        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
+                ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+                ToscaServiceTemplate.class);
+
+        JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
+        originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
         assertNotNull(originalServiceTemplate);
         JpaToscaServiceTemplate updatedServiceTemplate =
@@ -203,31 +211,34 @@ public class SimpleToscaProviderTest {
     }
 
     @Test
-    public void testPoliciesDelete() throws PfModelException {
+    public void testPoliciesDelete() throws Exception {
         try {
-            new SimpleToscaProvider().deletePolicies(null, null);
+            new SimpleToscaProvider().deletePolicy(null, null);
             fail("test should throw an exception here");
         } catch (Exception exc) {
             assertEquals("dao is marked @NonNull but is null", exc.getMessage());
         }
 
         try {
-            new SimpleToscaProvider().deletePolicies(null, new PfConceptKey());
+            new SimpleToscaProvider().deletePolicy(null, new PfConceptKey());
             fail("test should throw an exception here");
         } catch (Exception exc) {
             assertEquals("dao is marked @NonNull but is null", exc.getMessage());
         }
 
         try {
-            new SimpleToscaProvider().deletePolicies(pfDao, null);
+            new SimpleToscaProvider().deletePolicy(pfDao, null);
             fail("test should throw an exception here");
         } catch (Exception exc) {
             assertEquals("policyKey is marked @NonNull but is null", exc.getMessage());
         }
 
-        JpaToscaServiceTemplate originalServiceTemplate =
-                gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
-                        JpaToscaServiceTemplate.class);
+        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
+                ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+                ToscaServiceTemplate.class);
+
+        JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
+        originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
         assertNotNull(originalServiceTemplate);
         JpaToscaServiceTemplate createdServiceTemplate =
@@ -238,7 +249,7 @@ public class SimpleToscaProviderTest {
         PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
 
         JpaToscaServiceTemplate deletedServiceTemplate =
-                new SimpleToscaProvider().deletePolicies(pfDao, new PfConceptKey(policyKey));
+                new SimpleToscaProvider().deletePolicy(pfDao, new PfConceptKey(policyKey));
 
         assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey),
                 deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey));
index 1f17a43..5f0cbb3 100644 (file)
@@ -26,23 +26,21 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import com.google.gson.Gson;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
-import com.google.gson.JsonSyntaxException;
 
-import java.io.IOException;
 import java.util.Map;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.yaml.snakeyaml.Yaml;
@@ -64,11 +62,11 @@ public class MonitoringPolicySerializationTest {
     private static final String VFW_MON_INPUT_JSON = "policies/vFirewall.policy.monitoring.input.tosca.json";
     private static final String VFW_MON_INPUT_YAML = "policies/vFirewall.policy.monitoring.input.tosca.yaml";
 
-    private Gson gson;
+    private StandardCoder standardCoder;
 
     @Before
     public void setUp() {
-        gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
+        standardCoder = new StandardCoder();
     }
 
     @Test
@@ -93,6 +91,7 @@ public class MonitoringPolicySerializationTest {
             assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0);
 
         } catch (Exception e) {
+            LOGGER.warn("No exception should be thrown", e);
             fail("No exception should be thrown");
         }
     }
@@ -122,11 +121,13 @@ public class MonitoringPolicySerializationTest {
     }
 
     private JpaToscaServiceTemplate deserializeMonitoringInputJson(String resourcePath)
-            throws JsonSyntaxException, IOException {
+            throws Exception {
 
         String policyJson = ResourceUtils.getResourceAsString(resourcePath);
-        JpaToscaServiceTemplate serviceTemplate = gson.fromJson(policyJson, JpaToscaServiceTemplate.class);
-        return serviceTemplate;
+        ToscaServiceTemplate serviceTemplate = standardCoder.decode(policyJson, ToscaServiceTemplate.class);
+        JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+        jpaToscaServiceTemplate.fromAuthorative(serviceTemplate);
+        return jpaToscaServiceTemplate;
     }
 
     private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath)
@@ -136,12 +137,15 @@ public class MonitoringPolicySerializationTest {
         String policyYaml = ResourceUtils.getResourceAsString(resourcePath);
         Object yamlObject = yaml.load(policyYaml);
         String yamlAsJsonString = new StandardCoder().encode(yamlObject);
-        JpaToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, JpaToscaServiceTemplate.class);
-        return serviceTemplate;
+        ToscaServiceTemplate serviceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+        JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+        jpaToscaServiceTemplate.fromAuthorative(serviceTemplate);
+        return jpaToscaServiceTemplate;
     }
 
-    private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) {
-        return gson.toJson(serviceTemplate);
+    private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) throws CoderException {
+        return standardCoder.encode(serviceTemplate.toAuthorative());
     }
 
     private void verifyVcpeMonitoringInputDeserialization(JpaToscaServiceTemplate serviceTemplate) {
index b494199..569e1ad 100644 (file)
@@ -26,26 +26,24 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import com.google.gson.Gson;
-import com.google.gson.JsonSyntaxException;
-
-import java.io.IOException;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.yaml.snakeyaml.Yaml;
@@ -63,11 +61,11 @@ public class MonitoringPolicyTypeSerializationTest {
     private static final String MONITORING_COLLECTORS_YAML =
             "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml";
 
-    private Gson gson;
+    private StandardCoder coder;
 
     @Before
     public void setUp() {
-        gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
+        coder = new StandardCoder();
     }
 
     @Test
@@ -82,6 +80,7 @@ public class MonitoringPolicyTypeSerializationTest {
             verifyCollectorInputDeserialization(serviceTemplateFromYaml);
 
         } catch (Exception e) {
+            LOGGER.warn("No exception should be thrown", e);
             fail("No exception should be thrown");
         }
     }
@@ -90,34 +89,47 @@ public class MonitoringPolicyTypeSerializationTest {
     public void testSerialization() {
         try {
             // TCA
-            JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
-            String serializedServiceTemplate1 = serializeMonitoringServiceTemplate(serviceTemplateFromYaml);
-            JpaToscaServiceTemplate serviceTemplateFromJson = gson.fromJson(serializedServiceTemplate1,
-                    JpaToscaServiceTemplate.class);
-            String serializedServiceTemplate2 = serializeMonitoringServiceTemplate(serviceTemplateFromJson);
-            assertEquals(serializedServiceTemplate1, serializedServiceTemplate2);
+            JpaToscaServiceTemplate tcaServiceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
+            String serializedServiceTemplateTca = serializeMonitoringServiceTemplate(tcaServiceTemplateFromYaml);
+
+            ToscaServiceTemplate toscaServiceTemplateFromJsonTca =
+                    coder.decode(serializedServiceTemplateTca, ToscaServiceTemplate.class);
+
+            JpaToscaServiceTemplate serviceTemplateFromJsonTca = new JpaToscaServiceTemplate();
+            serviceTemplateFromJsonTca.fromAuthorative(toscaServiceTemplateFromJsonTca);
+            String serializedServiceTemplateTcaOut = serializeMonitoringServiceTemplate(serviceTemplateFromJsonTca);
+            assertEquals(serializedServiceTemplateTca, serializedServiceTemplateTcaOut);
 
             // Collector
-            serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
-            serializedServiceTemplate1 = serializeMonitoringServiceTemplate(serviceTemplateFromYaml);
-            serviceTemplateFromJson = gson.fromJson(serializedServiceTemplate1, JpaToscaServiceTemplate.class);
-            serializedServiceTemplate2 = serializeMonitoringServiceTemplate(serviceTemplateFromJson);
-            assertEquals(serializedServiceTemplate1, serializedServiceTemplate2);
+            JpaToscaServiceTemplate collectorServiceTemplateFromYaml =
+                    deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
+            String serializedServiceTemplateCollector =
+                    serializeMonitoringServiceTemplate(collectorServiceTemplateFromYaml);
+            ToscaServiceTemplate toscaServiceTemplateFromJsonCollector =
+                    coder.decode(serializedServiceTemplateCollector, ToscaServiceTemplate.class);
+            JpaToscaServiceTemplate serviceTemplateFromJsonCollector = new JpaToscaServiceTemplate();
+            serviceTemplateFromJsonCollector.fromAuthorative(toscaServiceTemplateFromJsonCollector);
+            String serializedServiceTemplateCollectorsOut =
+                    serializeMonitoringServiceTemplate(serviceTemplateFromJsonCollector);
+            assertEquals(serializedServiceTemplateCollector, serializedServiceTemplateCollectorsOut);
 
         } catch (Exception e) {
+            LOGGER.warn("No exception should be thrown", e);
             fail("No exception should be thrown");
         }
     }
 
-    private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath)
-            throws JsonSyntaxException, IOException {
+    private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) throws Exception {
 
         Yaml yaml = new Yaml();
         String policyTypeYaml = ResourceUtils.getResourceAsString(resourcePath);
         Object yamlObject = yaml.load(policyTypeYaml);
-        String yamlAsJsonString = new Gson().toJson(yamlObject);
-        JpaToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, JpaToscaServiceTemplate.class);
-        return serviceTemplate;
+        String yamlAsJsonString = coder.encode(yamlObject);
+        ToscaServiceTemplate serviceTemplate = coder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+        JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+        jpaToscaServiceTemplate.fromAuthorative(serviceTemplate);
+        return jpaToscaServiceTemplate;
     }
 
     private void verifyTcaInputDeserialization(JpaToscaServiceTemplate serviceTemplate) {
@@ -137,7 +149,7 @@ public class MonitoringPolicyTypeSerializationTest {
 
         Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
         assertEquals("onap.policies.Monitoring", firstPolicyType.getKey().getName());
-        assertEquals("1.0.0", firstPolicyType.getKey().getVersion());
+        assertEquals("0.0.0", firstPolicyType.getKey().getVersion());
         assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName());
         assertEquals("a base policy type for all policies that governs monitoring provisioning",
                 firstPolicyType.getValue().getDescription());
@@ -148,7 +160,7 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName());
         assertTrue(secondPolicyType.getValue().getProperties().size() == 1);
 
-        JpaToscaProperty property = secondPolicyType.getValue().getProperties().iterator().next();
+        JpaToscaProperty property = secondPolicyType.getValue().getProperties().values().iterator().next();
         assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName());
         assertEquals("1.0.0", property.getKey().getParentKeyVersion());
         assertEquals("tca_policy", property.getKey().getLocalName());
@@ -156,9 +168,6 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("TCA Policy JSON", property.getDescription());
 
         JpaToscaEntrySchema entrySchema = property.getEntrySchema();
-        assertEquals("map", entrySchema.getKey().getParentKeyName());
-        assertEquals("1.0.0", entrySchema.getKey().getParentKeyVersion());
-        assertEquals("entry_schema", entrySchema.getKey().getLocalName());
         assertEquals("onap.datatypes.monitoring.tca_policy", entrySchema.getType().getName());
 
         // Check data_types
@@ -170,81 +179,74 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataType.getKey().getName());
         JpaToscaDataType firstDataTypeVal = firstDataType.getValue();
         assertEquals("tosca.datatypes.Root", firstDataTypeVal.getDerivedFrom().getName());
-        assertEquals("1.0.0", firstDataTypeVal.getDerivedFrom().getVersion());
+        assertEquals("0.0.0", firstDataTypeVal.getDerivedFrom().getVersion());
         assertTrue(firstDataTypeVal.getProperties().size() == 6);
-        Iterator<JpaToscaProperty> firstDataTypePropertiesIter = firstDataTypeVal.getProperties().iterator();
+        Iterator<JpaToscaProperty> firstDataTypePropertiesIter = firstDataTypeVal.getProperties().values().iterator();
 
         JpaToscaProperty firstDataTypeFirstProperty = firstDataTypePropertiesIter.next();
-        assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeFirstProperty.getKey()
-                .getParentKeyName());
+        assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+                firstDataTypeFirstProperty.getKey().getParentKeyName());
         assertEquals("controlLoopSchemaType", firstDataTypeFirstProperty.getKey().getLocalName());
         assertEquals("string", firstDataTypeFirstProperty.getType().getName());
         assertTrue(firstDataTypeFirstProperty.isRequired());
         assertEquals("Specifies Control Loop Schema Type for the event Name e.g. VNF, VM",
                 firstDataTypeFirstProperty.getDescription());
         assertTrue(firstDataTypeFirstProperty.getConstraints().size() == 1);
-        assertEquals("valid_values", firstDataTypeFirstProperty.getConstraints().iterator().next().getKey()
-                .getLocalName());
-        assertEquals("string", firstDataTypeFirstProperty.getConstraints().iterator().next().getKey()
-                .getParentKeyName());
-        assertTrue(firstDataTypeFirstProperty.getConstraints().iterator().next()
-                instanceof JpaToscaConstraintValidValues);
-        assertTrue(((JpaToscaConstraintValidValues)(firstDataTypeFirstProperty.getConstraints().iterator().next()))
+        assertEquals("org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues",
+                firstDataTypeFirstProperty.getConstraints().iterator().next().getClass().getCanonicalName());
+        assertTrue(((JpaToscaConstraintValidValues) (firstDataTypeFirstProperty.getConstraints().iterator().next()))
                 .getValidValues().size() == 2);
 
         JpaToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next();
-        assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeSecondProperty.getKey()
-                .getParentKeyName());
+        assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+                firstDataTypeSecondProperty.getKey().getParentKeyName());
         assertEquals("eventName", firstDataTypeSecondProperty.getKey().getLocalName());
         assertEquals("string", firstDataTypeSecondProperty.getType().getName());
         assertTrue(firstDataTypeSecondProperty.isRequired());
-        assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty
-                .getDescription());
+        assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty.getDescription());
 
         JpaToscaProperty firstDataTypeThirdProperty = firstDataTypePropertiesIter.next();
-        assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeThirdProperty.getKey()
-                .getParentKeyName());
+        assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+                firstDataTypeThirdProperty.getKey().getParentKeyName());
         assertEquals("policyName", firstDataTypeThirdProperty.getKey().getLocalName());
         assertEquals("string", firstDataTypeThirdProperty.getType().getName());
         assertTrue(firstDataTypeThirdProperty.isRequired());
         assertEquals("TCA Policy Scope Name", firstDataTypeThirdProperty.getDescription());
 
         JpaToscaProperty firstDataTypeFourthProperty = firstDataTypePropertiesIter.next();
-        assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeFourthProperty.getKey()
-                .getParentKeyName());
+        assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+                firstDataTypeFourthProperty.getKey().getParentKeyName());
         assertEquals("policyScope", firstDataTypeFourthProperty.getKey().getLocalName());
         assertEquals("string", firstDataTypeFourthProperty.getType().getName());
         assertTrue(firstDataTypeFourthProperty.isRequired());
         assertEquals("TCA Policy Scope", firstDataTypeFourthProperty.getDescription());
 
         JpaToscaProperty firstDataTypeFifthProperty = firstDataTypePropertiesIter.next();
-        assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeFifthProperty.getKey()
-                .getParentKeyName());
+        assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+                firstDataTypeFifthProperty.getKey().getParentKeyName());
         assertEquals("policyVersion", firstDataTypeFifthProperty.getKey().getLocalName());
         assertEquals("string", firstDataTypeFifthProperty.getType().getName());
         assertTrue(firstDataTypeFifthProperty.isRequired());
         assertEquals("TCA Policy Scope Version", firstDataTypeFifthProperty.getDescription());
 
         JpaToscaProperty firstDataTypeSixthProperty = firstDataTypePropertiesIter.next();
-        assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeSixthProperty.getKey()
-                .getParentKeyName());
+        assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+                firstDataTypeSixthProperty.getKey().getParentKeyName());
         assertEquals("thresholds", firstDataTypeSixthProperty.getKey().getLocalName());
         assertEquals("list", firstDataTypeSixthProperty.getType().getName());
         assertTrue(firstDataTypeSixthProperty.isRequired());
         assertEquals("Thresholds associated with eventName", firstDataTypeSixthProperty.getDescription());
         assertNotNull(firstDataTypeSixthProperty.getEntrySchema());
-        assertEquals("entry_schema", firstDataTypeSixthProperty.getEntrySchema().getKey().getLocalName());
-        assertEquals("list", firstDataTypeSixthProperty.getEntrySchema().getKey().getParentKeyName());
-        assertEquals("onap.datatypes.monitoring.thresholds", firstDataTypeSixthProperty.getEntrySchema().getType()
-                .getName());
+        assertEquals("onap.datatypes.monitoring.thresholds",
+                firstDataTypeSixthProperty.getEntrySchema().getType().getName());
 
         Entry<PfConceptKey, JpaToscaDataType> secondDataType = dataTypesIter.next();
         assertEquals("onap.datatypes.monitoring.tca_policy", secondDataType.getKey().getName());
         JpaToscaDataType secondDataTypeVal = secondDataType.getValue();
         assertEquals("tosca.datatypes.Root", secondDataTypeVal.getDerivedFrom().getName());
-        assertEquals("1.0.0", secondDataTypeVal.getDerivedFrom().getVersion());
+        assertEquals("0.0.0", secondDataTypeVal.getDerivedFrom().getVersion());
         assertTrue(secondDataTypeVal.getProperties().size() == 2);
-        Iterator<JpaToscaProperty> secondDataTypePropertiesIter = secondDataTypeVal.getProperties().iterator();
+        Iterator<JpaToscaProperty> secondDataTypePropertiesIter = secondDataTypeVal.getProperties().values().iterator();
 
         JpaToscaProperty secondDataTypeFirstProperty = secondDataTypePropertiesIter.next();
         assertEquals("onap.datatypes.monitoring.tca_policy", secondDataTypeFirstProperty.getKey().getParentKeyName());
@@ -254,13 +256,10 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("Domain name to which TCA needs to be applied", secondDataTypeFirstProperty.getDescription());
         assertEquals("measurementsForVfScaling", secondDataTypeFirstProperty.getDefaultValue());
         assertTrue(secondDataTypeFirstProperty.getConstraints().size() == 1);
-        assertEquals("string", secondDataTypeFirstProperty.getConstraints().iterator().next().getKey()
-                .getParentKeyName());
-        assertEquals("equal", secondDataTypeFirstProperty.getConstraints().iterator().next().getKey().getLocalName());
-        assertTrue(secondDataTypeFirstProperty.getConstraints().iterator().next()
-                instanceof JpaToscaConstraintLogicalString);
-        assertEquals("measurementsForVfScaling", ((JpaToscaConstraintLogicalString)(secondDataTypeFirstProperty
-                .getConstraints().iterator().next())).getCompareToString());
+        assertTrue(secondDataTypeFirstProperty.getConstraints().iterator().next() instanceof JpaToscaConstraintLogical);
+        assertEquals("measurementsForVfScaling",
+                ((JpaToscaConstraintLogical) (secondDataTypeFirstProperty.getConstraints().iterator().next()))
+                        .getCompareTo());
 
         JpaToscaProperty secondDataTypeSecondProperty = secondDataTypePropertiesIter.next();
         assertEquals("onap.datatypes.monitoring.tca_policy", secondDataTypeSecondProperty.getKey().getParentKeyName());
@@ -270,26 +269,24 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("Contains eventName and threshold details that need to be applied to given eventName",
                 secondDataTypeSecondProperty.getDescription());
         assertNotNull(secondDataTypeSecondProperty.getEntrySchema());
-        assertEquals("list", secondDataTypeSecondProperty.getEntrySchema().getKey().getParentKeyName());
         assertEquals("onap.datatypes.monitoring.metricsPerEventName",
                 secondDataTypeSecondProperty.getEntrySchema().getType().getName());
-        assertEquals("entry_schema", secondDataTypeSecondProperty.getEntrySchema().getKey().getLocalName());
 
         Entry<PfConceptKey, JpaToscaDataType> thirdDataType = dataTypesIter.next();
         assertEquals("onap.datatypes.monitoring.thresholds", thirdDataType.getKey().getName());
         JpaToscaDataType thirdDataTypeVal = thirdDataType.getValue();
         assertEquals("tosca.datatypes.Root", thirdDataTypeVal.getDerivedFrom().getName());
-        assertEquals("1.0.0", thirdDataTypeVal.getDerivedFrom().getVersion());
+        assertEquals("0.0.0", thirdDataTypeVal.getDerivedFrom().getVersion());
         assertTrue(thirdDataTypeVal.getProperties().size() == 7);
-        Iterator<JpaToscaProperty> thirdDataTypePropertiesIter = thirdDataTypeVal.getProperties().iterator();
+        Iterator<JpaToscaProperty> thirdDataTypePropertiesIter = thirdDataTypeVal.getProperties().values().iterator();
 
         JpaToscaProperty thirdDataTypeFirstProperty = thirdDataTypePropertiesIter.next();
         assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeFirstProperty.getKey().getParentKeyName());
         assertEquals("closedLoopControlName", thirdDataTypeFirstProperty.getKey().getLocalName());
         assertEquals("string", thirdDataTypeFirstProperty.getType().getName());
         assertTrue(thirdDataTypeFirstProperty.isRequired());
-        assertEquals("Closed Loop Control Name associated with the threshold", thirdDataTypeFirstProperty
-                .getDescription());
+        assertEquals("Closed Loop Control Name associated with the threshold",
+                thirdDataTypeFirstProperty.getDescription());
 
         JpaToscaProperty thirdDataTypeSecondProperty = thirdDataTypePropertiesIter.next();
         assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeSecondProperty.getKey().getParentKeyName());
@@ -299,13 +296,11 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("Closed Loop Event Status of the threshold", thirdDataTypeSecondProperty.getDescription());
         assertNotNull(thirdDataTypeSecondProperty.getConstraints());
         assertTrue(thirdDataTypeSecondProperty.getConstraints().size() == 1);
-        assertEquals("string", thirdDataTypeSecondProperty.getConstraints().iterator().next().getKey()
-                .getParentKeyName());
-        assertEquals("valid_values", thirdDataTypeSecondProperty.getConstraints().iterator().next().getKey()
-                .getLocalName());
-        assertTrue(thirdDataTypeSecondProperty.getConstraints().iterator().next()
-                instanceof JpaToscaConstraintValidValues);
-        assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeSecondProperty.getConstraints().iterator().next()))
+        assertEquals("JpaToscaConstraintValidValues(validValues=[ONSET, ABATED])",
+                thirdDataTypeSecondProperty.getConstraints().iterator().next().toString());
+        assertTrue(thirdDataTypeSecondProperty.getConstraints().iterator()
+                .next() instanceof JpaToscaConstraintValidValues);
+        assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeSecondProperty.getConstraints().iterator().next()))
                 .getValidValues().size() == 2);
 
         JpaToscaProperty thirdDataTypeThirdProperty = thirdDataTypePropertiesIter.next();
@@ -316,11 +311,10 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("Direction of the threshold", thirdDataTypeThirdProperty.getDescription());
         assertNotNull(thirdDataTypeThirdProperty.getConstraints());
         assertTrue(thirdDataTypeThirdProperty.getConstraints().size() == 1);
-        assertEquals("string", thirdDataTypeThirdProperty.getConstraints().iterator().next().getKey()
-                .getParentKeyName());
-        assertEquals("valid_values", thirdDataTypeThirdProperty.getConstraints().iterator().next().getKey()
-                .getLocalName());
-        assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeThirdProperty.getConstraints().iterator().next()))
+        assertEquals(
+                "JpaToscaConstraintValidValues(validValues=[LESS, LESS_OR_EQUAL, GREATER, GREATER_OR_EQUAL, EQUAL])",
+                thirdDataTypeThirdProperty.getConstraints().iterator().next().toString());
+        assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeThirdProperty.getConstraints().iterator().next()))
                 .getValidValues().size() == 5);
 
         JpaToscaProperty thirdDataTypeFourthProperty = thirdDataTypePropertiesIter.next();
@@ -332,11 +326,7 @@ public class MonitoringPolicyTypeSerializationTest {
                 thirdDataTypeFourthProperty.getDescription());
         assertNotNull(thirdDataTypeFourthProperty.getConstraints());
         assertTrue(thirdDataTypeFourthProperty.getConstraints().size() == 1);
-        assertEquals("string", thirdDataTypeFourthProperty.getConstraints().iterator().next().getKey()
-                .getParentKeyName());
-        assertEquals("valid_values", thirdDataTypeFourthProperty.getConstraints().iterator().next().getKey()
-                .getLocalName());
-        assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeFourthProperty.getConstraints().iterator().next()))
+        assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFourthProperty.getConstraints().iterator().next()))
                 .getValidValues().size() == 43);
 
         JpaToscaProperty thirdDataTypeFifthProperty = thirdDataTypePropertiesIter.next();
@@ -347,11 +337,9 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("Threshold Event Severity", thirdDataTypeFifthProperty.getDescription());
         assertNotNull(thirdDataTypeFifthProperty.getConstraints());
         assertTrue(thirdDataTypeFifthProperty.getConstraints().size() == 1);
-        assertEquals("string", thirdDataTypeFifthProperty.getConstraints().iterator().next().getKey()
-                .getParentKeyName());
-        assertEquals("valid_values", thirdDataTypeFifthProperty.getConstraints().iterator().next().getKey()
-                .getLocalName());
-        assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeFifthProperty.getConstraints().iterator().next()))
+        assertEquals("JpaToscaConstraintValidValues(validValues=[CRITICAL, MAJOR, MINOR, WARNING, NORMAL])",
+                thirdDataTypeFifthProperty.getConstraints().iterator().next().toString());
+        assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFifthProperty.getConstraints().iterator().next()))
                 .getValidValues().size() == 5);;
 
         JpaToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next();
@@ -359,8 +347,8 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("thresholdValue", thirdDataTypeSixthProperty.getKey().getLocalName());
         assertEquals("integer", thirdDataTypeSixthProperty.getType().getName());
         assertTrue(thirdDataTypeSixthProperty.isRequired());
-        assertEquals("Threshold value for the field Path inside CEF message", thirdDataTypeSixthProperty
-                .getDescription());
+        assertEquals("Threshold value for the field Path inside CEF message",
+                thirdDataTypeSixthProperty.getDescription());
 
         JpaToscaProperty thirdDataTypeSeventhProperty = thirdDataTypePropertiesIter.next();
         assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeSeventhProperty.getKey().getParentKeyName());
@@ -399,7 +387,7 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("policy.nodes.Root", secondPolicyType.getValue().getDerivedFrom().getName());
         assertTrue(secondPolicyType.getValue().getProperties().size() == 2);
 
-        Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().iterator();
+        Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().values().iterator();
 
         JpaToscaProperty firstProperty = propertiesIter.next();
         assertEquals("onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server",
@@ -418,7 +406,8 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("datafile Policy JSON as string", secondProperty.getDescription());
     }
 
-    private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) {
-        return gson.toJson(serviceTemplate);
+    private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) throws CoderException {
+        ToscaServiceTemplate toscaServiceTemplate = serviceTemplate.toAuthorative();
+        return coder.encode(toscaServiceTemplate);
     }
-}
\ No newline at end of file
+}