X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=main%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fapi%2Fmain%2Frest%2Fprovider%2FLegacyGuardPolicyProvider.java;h=80c57d360bd0f106b9198f185296e64ab44fd47e;hb=19286bf7b66750aba7192af363349db2a4d5323d;hp=978a8c0ab1ac78231a8dba333012a364a7b3abb1;hpb=f2ab4c7c1943528146e4cac83cea0f777dfc5e94;p=policy%2Fapi.git diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyGuardPolicyProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyGuardPolicyProvider.java index 978a8c0a..80c57d36 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyGuardPolicyProvider.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyGuardPolicyProvider.java @@ -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. @@ -22,20 +23,16 @@ package org.onap.policy.api.main.rest.provider; -import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import java.util.Map.Entry; + 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.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; @@ -46,15 +43,12 @@ import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; */ public class LegacyGuardPolicyProvider 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 Map GUARD_POLICY_TYPE_MAP = new LinkedHashMap<>(); static { GUARD_POLICY_TYPE_MAP.put("guard.frequency.", new PfConceptKey("onap.policies.controlloop.guard.FrequencyLimiter:1.0.0")); - GUARD_POLICY_TYPE_MAP.put("guard.minmax.", - new PfConceptKey("onap.policies.controlloop.guard.MinMax:1.0.0")); + GUARD_POLICY_TYPE_MAP.put("guard.minmax.", new PfConceptKey("onap.policies.controlloop.guard.MinMax:1.0.0")); GUARD_POLICY_TYPE_MAP.put("guard.blacklist.", new PfConceptKey("onap.policies.controlloop.guard.Blacklist:1.0.0")); } @@ -77,9 +71,6 @@ public class LegacyGuardPolicyProvider extends CommonModelProvider { public Map fetchGuardPolicy(String policyId, String policyVersion) throws PfModelException { - if (policyVersion != null) { - validNumber(policyVersion, INVALID_POLICY_VERSION); - } return modelsProvider.getGuardPolicy(policyId, policyVersion); } @@ -95,8 +86,8 @@ public class LegacyGuardPolicyProvider extends CommonModelProvider { public Map, Map> fetchDeployedGuardPolicies(String policyId) throws PfModelException { - return collectDeployedPolicies( - policyId, getGuardPolicyType(policyId), modelsProvider::getGuardPolicy, Map::putAll, new HashMap<>()); + return collectDeployedPolicies(policyId, getGuardPolicyType(policyId), modelsProvider::getGuardPolicy, + Map::putAll, new HashMap<>()); } /** @@ -106,8 +97,7 @@ public class LegacyGuardPolicyProvider extends CommonModelProvider { * * @return the map of LegacyGuardPolicyOutput objectst */ - public Map createGuardPolicy(LegacyGuardPolicyInput body) - throws PfModelException { + public Map createGuardPolicy(LegacyGuardPolicyInput body) throws PfModelException { return modelsProvider.createGuardPolicy(body); } @@ -123,34 +113,9 @@ public class LegacyGuardPolicyProvider extends CommonModelProvider { public Map deleteGuardPolicy(String policyId, String policyVersion) throws PfModelException { - validNumber(policyVersion, INVALID_POLICY_VERSION); - validateDeleteEligibility(policyId, policyVersion); - return modelsProvider.deleteGuardPolicy(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 policies = new ArrayList<>(); - policies.add(new ToscaPolicyIdentifier(policyId, policyVersion + LEGACY_MINOR_PATCH_SUFFIX)); - PdpGroupFilter pdpGroupFilter = PdpGroupFilter.builder().policyList(policies).build(); - - List pdpGroups = modelsProvider.getFilteredPdpGroups(pdpGroupFilter); - - if (!pdpGroups.isEmpty()) { - throw new PfModelException(Response.Status.CONFLICT, - constructDeletePolicyViolationMessage(policyId, policyVersion, pdpGroups)); - } - } - /** * Retrieves guard policy type given guard policy ID. *