JPA concepts for TOSCA
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / utils / ToscaServiceTemplateUtils.java
index 343e023..7bf4d29 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  * Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020 AT&T
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,11 +23,8 @@ package org.onap.policy.models.tosca.utils;
 
 import java.util.Map;
 import java.util.Map.Entry;
-
 import javax.ws.rs.core.Response;
-
 import lombok.NonNull;
-
 import org.onap.policy.models.base.PfConceptContainer;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelRuntimeException;
@@ -37,15 +35,11 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType;
 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;
 
 /**
  * This utility class provides methods to manage service templates.
  */
 public class ToscaServiceTemplateUtils {
-    private static final Logger LOGGER = LoggerFactory.getLogger(ToscaServiceTemplateUtils.class);
-
     /**
      * Private constructor to prevent subclassing.
      */
@@ -59,7 +53,7 @@ public class ToscaServiceTemplateUtils {
      *
      * @param originalTemplate the original service template
      * @param fragmentTemplate the fragment being added to the original service template
-     * @return
+     * @return JpaToscaServiceTemplate
      */
     public static JpaToscaServiceTemplate addFragment(@NonNull final JpaToscaServiceTemplate originalTemplate,
             @NonNull final JpaToscaServiceTemplate fragmentTemplate) {
@@ -78,7 +72,7 @@ public class ToscaServiceTemplateUtils {
         compositeTemplate.setPolicyTypes(
                 addFragmentEntitites(compositeTemplate.getPolicyTypes(), fragmentTemplate.getPolicyTypes(), result));
 
-        if (originalTemplate.getTopologyTemplate() != null) {
+        if (originalTemplate.getTopologyTemplate() != null && fragmentTemplate.getTopologyTemplate() != null) {
             if (originalTemplate.getTopologyTemplate()
                     .compareToWithoutEntities(fragmentTemplate.getTopologyTemplate()) == 0) {
                 compositeTemplate.getTopologyTemplate()
@@ -99,7 +93,7 @@ public class ToscaServiceTemplateUtils {
 
         if (!result.isValid()) {
             String message = result.toString();
-            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, message);
+            throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, message);
         }
 
         return compositeTemplate;
@@ -131,9 +125,9 @@ public class ToscaServiceTemplateUtils {
 
         for (Entry<PfConceptKey, ? extends JpaToscaEntityType<? extends ToscaEntity>> fragmentEntry : fragmentContainer
                 .getConceptMap().entrySet()) {
-            JpaToscaEntityType<? extends ToscaEntity> containerEntry =
+            JpaToscaEntityType<? extends ToscaEntity> containerEntity =
                     compositeContainer.getConceptMap().get(fragmentEntry.getKey());
-            if (containerEntry != null && !containerEntry.equals(fragmentEntry.getValue())) {
+            if (containerEntity != null && containerEntity.compareTo(fragmentEntry.getValue()) != 0) {
                 result.addValidationMessage(new PfValidationMessage(fragmentEntry.getKey(),
                         ToscaServiceTemplateUtils.class,
                         ValidationResult.INVALID, "entity in incoming fragment does not equal existing entity"));