Add safe entity delete, fix multiple entity get
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / utils / ToscaUtils.java
index b75273e..77633bd 100644 (file)
@@ -211,7 +211,7 @@ public final class ToscaUtils {
     }
 
     /**
-     * Find all the ancestors of an entity type.
+     * getLatestPolicyTypeVersion Find all the ancestors of an entity type.
      *
      * @param entityTypes the set of entity types that exist
      * @param entityType the entity type for which to get the parents
@@ -227,6 +227,12 @@ public final class ToscaUtils {
             return CollectionUtils.emptyCollection();
         }
 
+        if (entityType.getKey().equals(parentEntityTypeKey)) {
+            result.addValidationMessage(new PfValidationMessage(entityType.getKey(), ToscaUtils.class,
+                    ValidationResult.INVALID, "entity cannot be an ancestor of itself"));
+            throw new PfModelRuntimeException(Response.Status.CONFLICT, result.toString());
+        }
+
         @SuppressWarnings("unchecked")
         Set<JpaToscaEntityType<ToscaEntity>> ancestorEntitySet = (Set<JpaToscaEntityType<ToscaEntity>>) entityTypes
                 .getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion());