Fix to resolve unpushing(delete) policies issue 11/87911/2
authorMichael Mokry <michael.mokry@att.com>
Thu, 16 May 2019 17:46:03 +0000 (12:46 -0500)
committerMichael Mokry <michael.mokry@att.com>
Mon, 20 May 2019 16:04:09 +0000 (11:04 -0500)
Added code the ONAP-PDP-REST to fix an issue causing the policyName to be null
and fail validation

Updated Changes per Review:
1. re-added the else for "No Policy Scope given"
2. localized the policyName and policyScope declarations to reset to null
each time through the loop
3. Changed to polName check to endsWith per Jim's review

Change-Id: I912511ef362cc79e89adc1c9da93d387e273c32a
Issue-ID: POLICY-1754
Signed-off-by: Michael Mokry <michael.mokry@att.com>
ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PdpApiService.java

index 8a7a8e0..7ecfb2d 100644 (file)
@@ -103,8 +103,7 @@ public abstract class PdpApiService {
 
     protected boolean validatePolicyNameAndScope(List<String> policyNames, List<String> policyTypes,
             List<PolicyNameType> policyList) {
-        String policyName = null;
-        String policyScope = null;
+
         String polType = null;
 
         if (policyTypes.size() == 1) {
@@ -117,13 +116,20 @@ public abstract class PdpApiService {
                 if (policyTypes.size() > 1) {
                     polType = policyTypes.get(i).trim();
                 }
-                if (polName.contains(".")) {
+
+                String policyName = null;
+                String policyScope = null;
+                if (polName.endsWith("xml")) {
+                    policyName = polName;
+                    policyScope = policyName.substring(0, StringUtils.lastOrdinalIndexOf(policyName, ".", 3));
+                } else if (polName.contains(".")) {
                     policyName = polName.substring(polName.lastIndexOf('.') + 1);
                     policyScope = polName.substring(0, polName.lastIndexOf('.'));
                 } else {
                     message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given.";
                     return false;
                 }
+
                 if (StringUtils.isBlank(policyName) || StringUtils.isBlank(policyScope)) {
                     message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Policy Name.";
                     return false;