Add changes for safe delete in policy-models
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / provider / PolicyTypeProvider.java
index d325f2c..6c8e73e 100644 (file)
 \r
 package org.onap.policy.api.main.rest.provider;\r
 \r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Map.Entry;\r
-\r
 import javax.ws.rs.core.Response;\r
 \r
 import org.onap.policy.models.base.PfModelException;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;\r
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;\r
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;\r
 \r
@@ -107,7 +100,7 @@ public class PolicyTypeProvider extends CommonModelProvider {
             throw new PfModelException(Response.Status.BAD_REQUEST,\r
                     "no policy types specified in the service template");\r
         }\r
-        validatePolicyTypeVersionExist(body);\r
+\r
         return modelsProvider.createPolicyTypes(body);\r
     }\r
 \r
@@ -124,8 +117,6 @@ public class PolicyTypeProvider extends CommonModelProvider {
     public ToscaServiceTemplate deletePolicyType(String policyTypeId, String policyTypeVersion)\r
             throws PfModelException {\r
 \r
-        validateDeleteEligibility(policyTypeId, policyTypeVersion);\r
-\r
         ToscaServiceTemplate serviceTemplate = modelsProvider.deletePolicyType(policyTypeId, policyTypeVersion);\r
 \r
         if (!hasPolicyType(serviceTemplate)) {\r
@@ -136,50 +127,6 @@ public class PolicyTypeProvider extends CommonModelProvider {
         return serviceTemplate;\r
     }\r
 \r
-    /**\r
-     * Validates whether specified policy type can be deleted based on the rule that policy type parameterized by at\r
-     * least one policies cannot be deleted.\r
-     *\r
-     * @param policyTypeId the ID of policy type\r
-     * @param policyTypeVersion the version of policy type\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    private void validateDeleteEligibility(String policyTypeId, String policyTypeVersion) throws PfModelException {\r
-\r
-        ToscaPolicyFilter policyFilter =\r
-                ToscaPolicyFilter.builder().type(policyTypeId).typeVersion(policyTypeVersion).build();\r
-        List<ToscaPolicy> policies = modelsProvider.getFilteredPolicyList(policyFilter);\r
-        if (!policies.isEmpty()) {\r
-            throw new PfModelException(Response.Status.CONFLICT,\r
-                    constructDeletePolicyTypeViolationMessage(policyTypeId, policyTypeVersion, policies));\r
-        }\r
-    }\r
-\r
-    /**\r
-     * Validates that each policy type has a version specified in the payload.\r
-     *\r
-     * @param body the TOSCA service template payload to check against\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    private void validatePolicyTypeVersionExist(ToscaServiceTemplate body) throws PfModelException {\r
-\r
-        List<String> invalidPolicyTypeNames = new ArrayList<>();\r
-        for (Entry<String, ToscaPolicyType> policyType : body.getPolicyTypes().entrySet()) {\r
-            if (!"tosca.policies.Root".equals(policyType.getValue().getDerivedFrom())\r
-                    && policyType.getValue().getVersion() == null) {\r
-                invalidPolicyTypeNames.add(policyType.getKey());\r
-            }\r
-        }\r
-\r
-        if (!invalidPolicyTypeNames.isEmpty()) {\r
-            String errorMsg = "mandatory 'version' field is missing in policy types: "\r
-                    + String.join(", ", invalidPolicyTypeNames);\r
-            throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMsg);\r
-        }\r
-    }\r
-\r
     /**\r
      * Retrieves the specified version of the policy type.\r
      *\r