JPA concepts for TOSCA
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaPolicyType.java
index 43d7ad6..7a5493c 100644 (file)
@@ -30,18 +30,15 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-
 import javax.persistence.ElementCollection;
 import javax.persistence.Entity;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 import javax.persistence.Lob;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
 import org.apache.commons.collections4.CollectionUtils;
 import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConcept;
@@ -124,15 +121,7 @@ public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> impl
         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);
-        }
+        toscaPolicyType.setProperties(PfUtils.mapMap(properties, JpaToscaProperty::toAuthorative));
 
         return toscaPolicyType;
     }
@@ -202,6 +191,11 @@ public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> impl
     public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
         PfValidationResult result = super.validate(resultIn);
 
+        if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) {
+            result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+                    "key version is a null version"));
+        }
+
         if (properties != null) {
             result = validateProperties(result);
         }
@@ -290,21 +284,22 @@ public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> impl
         }
 
         final JpaToscaPolicyType other = (JpaToscaPolicyType) otherConcept;
-        if (!super.equals(other)) {
-            return super.compareTo(other);
+        int result = super.compareTo(other);
+        if (result != 0) {
+            return result;
         }
 
-        int retVal = PfUtils.compareObjects(properties, other.properties);
-        if (retVal != 0) {
-            return retVal;
+        result = PfUtils.compareMaps(properties, other.properties);
+        if (result != 0) {
+            return result;
         }
 
-        retVal = PfUtils.compareObjects(targets, other.targets);
-        if (retVal != 0) {
-            return retVal;
+        result = PfUtils.compareCollections(targets, other.targets);
+        if (result != 0) {
+            return result;
         }
 
-        return PfUtils.compareObjects(triggers, other.triggers);
+        return PfUtils.compareCollections(triggers, other.triggers);
     }
 
     /**