X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FPDPController.java;h=1dce3a6b0a9bd546f39c10fdaa2bdd6a7154d84a;hb=b65e96826d7339ce29ddb73e3ed6775bd4f54753;hp=e5ed3122e21208a69add5ce2503ae100e879ad5d;hpb=38261bb20e49c39f710aef47b5415dcdf14a1729;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java index e5ed3122e..1dce3a6b0 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java @@ -88,8 +88,8 @@ public class PDPController extends RestrictedBaseController { try { PolicyController controller = getPolicyControllerInstance(); Set filteredPolicies = new HashSet<>(); - Set scopes = null; - List roles = null; + Set scopes; + List roles; String userId = isJunit() ? "Test" : UserUtils.getUserSession(request).getOrgUserId(); List userRoles = controller.getRoles(userId); roles = new ArrayList<>(); @@ -118,39 +118,37 @@ public class PDPController extends RestrictedBaseController { this.groups.addAll(this.getGroupsData()); } }else{ - if(!userRoles.isEmpty()){ - if(!scopes.isEmpty()){ - this.groups.addAll(controller.getPapEngine().getOnapPDPGroups()); - List tempGroups = new ArrayList<>(); - if(!groups.isEmpty()){ - Iterator pdpGroup = groups.iterator(); - while(pdpGroup.hasNext()){ - OnapPDPGroup group = pdpGroup.next(); - Set policies = group.getPolicies(); - for(PDPPolicy policy : policies){ - for(String scope : scopes){ - scope = scope.replace(File.separator, "."); - String policyName = policy.getId(); - if(policyName.contains(".Config_")){ - policyName = policyName.substring(0, policyName.lastIndexOf(".Config_")); - }else if(policyName.contains(".Action_")){ - policyName = policyName.substring(0, policyName.lastIndexOf(".Action_")); - }else if(policyName.contains(".Decision_")){ - policyName = policyName.substring(0, policyName.lastIndexOf(".Decision_")); - } - if(policyName.startsWith(scope)){ - filteredPolicies.add(policy); - } + if(!userRoles.isEmpty() && !scopes.isEmpty()){ + this.groups.addAll(controller.getPapEngine().getOnapPDPGroups()); + List tempGroups = new ArrayList<>(); + if(!groups.isEmpty()){ + Iterator pdpGroup = groups.iterator(); + while(pdpGroup.hasNext()){ + OnapPDPGroup group = pdpGroup.next(); + Set policies = group.getPolicies(); + for(PDPPolicy policy : policies){ + for(String scope : scopes){ + scope = scope.replace(File.separator, "."); + String policyName = policy.getId(); + if(policyName.contains(".Config_")){ + policyName = policyName.substring(0, policyName.lastIndexOf(".Config_")); + }else if(policyName.contains(".Action_")){ + policyName = policyName.substring(0, policyName.lastIndexOf(".Action_")); + }else if(policyName.contains(".Decision_")){ + policyName = policyName.substring(0, policyName.lastIndexOf(".Decision_")); + } + if(policyName.startsWith(scope)){ + filteredPolicies.add(policy); } } - pdpGroup.remove(); - StdPDPGroup newGroup = (StdPDPGroup) group; - newGroup.setPolicies(filteredPolicies); - tempGroups.add(newGroup); - } - groups.clear(); - groups = tempGroups; - } + } + pdpGroup.remove(); + StdPDPGroup newGroup = (StdPDPGroup) group; + newGroup.setPolicies(filteredPolicies); + tempGroups.add(newGroup); + } + groups.clear(); + groups = tempGroups; } } } @@ -254,7 +252,7 @@ public class PDPController extends RestrictedBaseController { policyLogger.info("*****************************************************************************************************************************"); StdPDPGroup pdpGroupData = mapper.readValue(root.get("pdpGroupData").toString(), StdPDPGroup.class); - if(pdpGroupData.getName().equals("Default")) { + if("Default".equals(pdpGroupData.getName())) { throw new UnsupportedOperationException("You can't remove the Default Group."); }else{ this.container.removeGroup(pdpGroupData, null);