diff options
author | Michael Mokry <mm117s@att.com> | 2018-02-05 09:48:59 -0600 |
---|---|---|
committer | Michael Mokry <mm117s@att.com> | 2018-02-08 07:45:06 -0600 |
commit | c5d97e8a9a6bea71f3be329a2e44bdbe5fe50882 (patch) | |
tree | 8db57c1406d2479e7624a2778dd5d518e874f59c /ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java | |
parent | c9039d15e8a84a9304fba40283a332a2a65ef854 (diff) |
MS Model Input Validation
- Provides validation for MS policy input content body that matches the GUI validations when create/update MS policy from API
- Added changes to satisfy review comments and updated copywright
headers for modified and new files
Change-Id: I02bfa639bffb48520badd0e4fa34eb36418547ae
Issue-ID: POLICY-377
Signed-off-by: Michael Mokry <mm117s@att.com>
Diffstat (limited to 'ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java')
-rw-r--r-- | ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java index 01670a5fd..144d3a48d 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PDP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,13 +75,15 @@ public class DeletePolicyService { return; } if (deleteResult.contains("BAD REQUEST")||deleteResult.contains("PE300")||deleteResult.contains("PE200")||deleteResult.contains("not exist")||deleteResult.contains("Invalid policyName")) { - status = HttpStatus.BAD_REQUEST; + if(deleteResult.contains("groupId")) { + status = HttpStatus.NOT_FOUND; + } else { + status = HttpStatus.BAD_REQUEST; + } } else if (deleteResult.contains("locked down")){ status = HttpStatus.ACCEPTED; } else if (deleteResult.contains("not Authorized")) { status = HttpStatus.FORBIDDEN; - } else if (deleteResult.contains("groupId")) { - status = HttpStatus.NOT_FOUND; } else if (deleteResult.contains("JPAUtils")||deleteResult.contains("database")||deleteResult.contains("policy file")|| deleteResult.contains("unknown")||deleteResult.contains("configuration")) { status = HttpStatus.INTERNAL_SERVER_ERROR; @@ -148,7 +150,7 @@ public class DeletePolicyService { if ("PAP".equalsIgnoreCase(deletePolicyParameters.getPolicyComponent())) { if (deletePolicyParameters.getDeleteCondition()==null||deletePolicyParameters.getDeleteCondition().toString().trim().isEmpty()){ - String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Delete Condition given."; + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Delete Condition given."; LOGGER.error(message); return message; } @@ -158,14 +160,14 @@ public class DeletePolicyService { response = (String) papServices.callPAP(deletePapPolicy, new String[] {"groupId="+pdpGroup, "apiflag=deletePapApi", "operation=delete" }, deletePolicyParameters.getRequestID(), clientScope); } else if ("PDP".equalsIgnoreCase(deletePolicyParameters.getPolicyComponent())) { if (deletePolicyParameters.getPdpGroup()==null||deletePolicyParameters.getPdpGroup().trim().isEmpty()){ - String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No PDP Group given."; + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No PDP Group given."; LOGGER.error(message); return message; } //send JSON object to PAP response = (String) papServices.callPAP(null, new String[] {"policyName="+fullPolicyName, "groupId="+pdpGroup, "apiflag=deletePdpApi", "operation=delete" }, deletePolicyParameters.getRequestID(), clientScope); } else { - String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy Component does not exist. Please enter either PAP or PDP to delete the policy from a specified Policy Component."; + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy Component does not exist. Please enter either PAP or PDP to delete the policy from a specified Policy Component."; LOGGER.error(message); response = message; } @@ -181,9 +183,9 @@ public class DeletePolicyService { if (!deletePolicyParameters.getPolicyName().contains("xml")) { if (deletePolicyParameters.getPolicyName() != null && deletePolicyParameters.getPolicyName().contains(".")) { - policyName = deletePolicyParameters.getPolicyName().substring(deletePolicyParameters.getPolicyName().lastIndexOf(".") + 1, + policyName = deletePolicyParameters.getPolicyName().substring(deletePolicyParameters.getPolicyName().lastIndexOf('.') + 1, deletePolicyParameters.getPolicyName().length()); - policyScope = deletePolicyParameters.getPolicyName().substring(0,deletePolicyParameters.getPolicyName().lastIndexOf(".")); + policyScope = deletePolicyParameters.getPolicyName().substring(0,deletePolicyParameters.getPolicyName().lastIndexOf('.')); LOGGER.info("Name is " + policyName + " scope is " + policyScope); } else { message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; |