aboutsummaryrefslogtreecommitdiffstats
path: root/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2018-01-29 11:59:40 -0500
committerPamela Dragosh <pdragosh@research.att.com>2018-01-29 13:30:49 -0500
commitb65e96826d7339ce29ddb73e3ed6775bd4f54753 (patch)
treede19c06846e0b1acb5095647a16848431f92a349 /POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java
parent38261bb20e49c39f710aef47b5415dcdf14a1729 (diff)
Reduce technical debt
Focusing on easy try-with-resources changes. Plus some other minor items. I did not get all of them yet, as some have some heavy refactoring. These try-with-resources seem to be fairly harmless. * Utilize try-with-resources * Remove unnecessary parenthesis * Merging simple if statements * Remove useless assignment * Moving string literals to left hand side Issue-ID: POLICY-482 Change-Id: If519ec8ea96f6b90bf82ac2676ffea9cd0cd2daf Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java')
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java66
1 files changed, 32 insertions, 34 deletions
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<PDPPolicy> filteredPolicies = new HashSet<>();
- Set<String> scopes = null;
- List<String> roles = null;
+ Set<String> scopes;
+ List<String> roles;
String userId = isJunit() ? "Test" : UserUtils.getUserSession(request).getOrgUserId();
List<Object> 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<OnapPDPGroup> tempGroups = new ArrayList<>();
- if(!groups.isEmpty()){
- Iterator<OnapPDPGroup> pdpGroup = groups.iterator();
- while(pdpGroup.hasNext()){
- OnapPDPGroup group = pdpGroup.next();
- Set<PDPPolicy> 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<OnapPDPGroup> tempGroups = new ArrayList<>();
+ if(!groups.isEmpty()){
+ Iterator<OnapPDPGroup> pdpGroup = groups.iterator();
+ while(pdpGroup.hasNext()){
+ OnapPDPGroup group = pdpGroup.next();
+ Set<PDPPolicy> 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);