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=236d26eb21cb711c01e61748f4f53bb9fb165d35;hb=bbf59429cf462ae417a16afa631c87f495e261df;hp=186ce0a36f2bda5a96a13ae7454421f8a18c5ec8;hpb=f3819951cf22cf93940679964a8c46bd8dfc89cb;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 186ce0a3..236d26eb 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 @@ -68,7 +68,10 @@ public class LegacyGuardPolicyProvider implements AutoCloseable { public Map fetchGuardPolicy(String policyId, String policyVersion) throws PfModelException { - return modelsProvider.getGuardPolicy(policyId); + if (policyVersion != null) { + validateLegacyGuardPolicyVersion(policyVersion); + } + return modelsProvider.getGuardPolicy(policyId, policyVersion); } /** @@ -78,7 +81,8 @@ public class LegacyGuardPolicyProvider implements AutoCloseable { * * @return the map of LegacyGuardPolicyOutput objectst */ - public Map createGuardPolicy(LegacyGuardPolicyInput body) throws PfModelException { + public Map createGuardPolicy(LegacyGuardPolicyInput body) + throws PfModelException { return modelsProvider.createGuardPolicy(body); } @@ -95,8 +99,9 @@ public class LegacyGuardPolicyProvider implements AutoCloseable { throws PfModelException { validateDeleteEligibility(policyId, policyVersion); + validateLegacyGuardPolicyVersion(policyVersion); - return modelsProvider.deleteGuardPolicy(policyId); + return modelsProvider.deleteGuardPolicy(policyId, policyVersion); } /** @@ -121,6 +126,23 @@ public class LegacyGuardPolicyProvider implements AutoCloseable { } } + /** + * Validates whether the legacy guard policy version is an integer. + * + * @param policyVersion the version of policy + * + * @throws PfModelException the PfModel parsing exception + */ + private void validateLegacyGuardPolicyVersion(String policyVersion) throws PfModelException { + + try { + Integer.valueOf(policyVersion); + } catch (NumberFormatException exc) { + throw new PfModelException(Response.Status.BAD_REQUEST, + "legacy policy version is not an integer", exc); + } + } + /** * Constructs returned message for policy delete rule violation. *