Add merge utility for service templates
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaServiceTemplate.java
index 31c7df0..f6139ab 100644 (file)
@@ -277,26 +277,13 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
 
     @Override
     public int compareTo(final PfConcept otherConcept) {
-        if (otherConcept == null) {
-            return -1;
-        }
-        if (this == otherConcept) {
-            return 0;
-        }
-        if (getClass() != otherConcept.getClass()) {
-            return getClass().getName().compareTo(otherConcept.getClass().getName());
-        }
-
-        final JpaToscaServiceTemplate other = (JpaToscaServiceTemplate) otherConcept;
-        if (!super.equals(other)) {
-            return super.compareTo(other);
-        }
-
-        int result = ObjectUtils.compare(toscaDefinitionsVersion, other.toscaDefinitionsVersion);
+        int result = compareToWithoutEntities(otherConcept);
         if (result != 0) {
             return result;
         }
 
+        final JpaToscaServiceTemplate other = (JpaToscaServiceTemplate) otherConcept;
+
         result = ObjectUtils.compare(dataTypes, other.dataTypes);
         if (result != 0) {
             return result;
@@ -309,4 +296,29 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
 
         return ObjectUtils.compare(topologyTemplate, other.topologyTemplate);
     }
+
+    /**
+     * Compare this service template to another service template, ignoring contained entitites.
+     *
+     * @param otherConcept the other topology template
+     * @return the result of the comparison
+     */
+    public int compareToWithoutEntities(final PfConcept otherConcept) {
+        if (otherConcept == null) {
+            return -1;
+        }
+        if (this == otherConcept) {
+            return 0;
+        }
+        if (getClass() != otherConcept.getClass()) {
+            return getClass().getName().compareTo(otherConcept.getClass().getName());
+        }
+
+        final JpaToscaServiceTemplate other = (JpaToscaServiceTemplate) otherConcept;
+        if (!super.equals(other)) {
+            return super.compareTo(other);
+        }
+
+        return ObjectUtils.compare(toscaDefinitionsVersion, other.toscaDefinitionsVersion);
+    }
 }