From 202be3bf6f8b95ed1012b0127f8b859410ce6be5 Mon Sep 17 00:00:00 2001 From: Michael Mokry Date: Thu, 16 May 2019 12:46:03 -0500 Subject: Fix to resolve unpushing(delete) policies issue 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 --- .../org/onap/policy/pdp/rest/api/services/PdpApiService.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'ONAP-PDP-REST/src/main') diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PdpApiService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PdpApiService.java index 8a7a8e0a0..7ecfb2dbe 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PdpApiService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PdpApiService.java @@ -103,8 +103,7 @@ public abstract class PdpApiService { protected boolean validatePolicyNameAndScope(List policyNames, List policyTypes, List 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; -- cgit 1.2.3-korg