Remove legacy operational policy from api config
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / provider / LegacyOperationalPolicyProvider.java
index 8319de4..11a6f2d 100644 (file)
@@ -2,7 +2,8 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy API
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,14 +26,9 @@ package org.onap.policy.api.main.rest.provider;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import javax.ws.rs.core.Response;
-
 import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.pdp.concepts.PdpGroup;
-import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
 
 /**
@@ -42,8 +38,6 @@ import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
  */
 public class LegacyOperationalPolicyProvider extends CommonModelProvider {
 
-    private static final String INVALID_POLICY_VERSION = "legacy policy version is not an integer";
-    private static final String LEGACY_MINOR_PATCH_SUFFIX = ".0.0";
     private static final PfConceptKey LEGACY_OPERATIONAL_TYPE =
             new PfConceptKey("onap.policies.controlloop.Operational", "1.0.0");
 
@@ -65,9 +59,6 @@ public class LegacyOperationalPolicyProvider extends CommonModelProvider {
     public LegacyOperationalPolicy fetchOperationalPolicy(String policyId, String policyVersion)
             throws PfModelException {
 
-        if (policyVersion != null) {
-            validNumber(policyVersion, INVALID_POLICY_VERSION);
-        }
         return modelsProvider.getOperationalPolicy(policyId, policyVersion);
     }
 
@@ -83,8 +74,8 @@ public class LegacyOperationalPolicyProvider extends CommonModelProvider {
     public Map<Pair<String, String>, List<LegacyOperationalPolicy>> fetchDeployedOperationalPolicies(String policyId)
             throws PfModelException {
 
-        return collectDeployedPolicies(
-                policyId, LEGACY_OPERATIONAL_TYPE, modelsProvider::getOperationalPolicy, List::add, new ArrayList<>());
+        return collectDeployedPolicies(policyId, LEGACY_OPERATIONAL_TYPE, modelsProvider::getOperationalPolicy,
+                List::add, new ArrayList<>(5));
     }
 
     /**
@@ -110,31 +101,6 @@ public class LegacyOperationalPolicyProvider extends CommonModelProvider {
     public LegacyOperationalPolicy deleteOperationalPolicy(String policyId, String policyVersion)
             throws PfModelException {
 
-        validNumber(policyVersion, INVALID_POLICY_VERSION);
-        validateDeleteEligibility(policyId, policyVersion);
-
         return modelsProvider.deleteOperationalPolicy(policyId, policyVersion);
     }
-
-    /**
-     * Validates whether specified policy can be deleted based on the rule that deployed policy cannot be deleted.
-     *
-     * @param policyId the ID of policy
-     * @param policyVersion the version of policy
-     *
-     * @throws PfModelException the PfModel parsing exception
-     */
-    private void validateDeleteEligibility(String policyId, String policyVersion) throws PfModelException {
-
-        List<ToscaPolicyIdentifier> policies = new ArrayList<>();
-        policies.add(new ToscaPolicyIdentifier(policyId, policyVersion + LEGACY_MINOR_PATCH_SUFFIX));
-        PdpGroupFilter pdpGroupFilter = PdpGroupFilter.builder().policyList(policies).build();
-
-        List<PdpGroup> pdpGroups = modelsProvider.getFilteredPdpGroups(pdpGroupFilter);
-
-        if (!pdpGroups.isEmpty()) {
-            throw new PfModelException(Response.Status.CONFLICT,
-                    constructDeletePolicyViolationMessage(policyId, policyVersion, pdpGroups));
-        }
-    }
 }
\ No newline at end of file