From 971903e3b96068094b35ffa4207f025b7b569e51 Mon Sep 17 00:00:00 2001 From: Michael Mokry Date: Thu, 8 Aug 2019 09:59:03 -0500 Subject: Fix issue for policies not loading on GUI push tab - found the problem to be with a line of code to add all the scopes from the role to a Set of scopes. when the scopes attribute in the role object is null it logs an exception and fails to load policies. I added a new method to check the value of the roles.getScopes() for null and only attempt to add the scope to the set if it is not null - I created a separate method to do this in order to avoid an increase in technical debt as it would have added to the complexity if I kept it in the same method. - PATCH 4: Added scopes to the method arguments in order to avoid overwriting scopes that are added in prevous interations of the loop. - PATCH 5: removed redundant scopes assignment per Jorge's review. Change-Id: Ifcc8775d3db8ecc722ee6806310a58ecb4e15856 Issue-ID: POLICY-1981 Signed-off-by: Michael Mokry --- .../java/org/onap/policy/controller/AutoPushController.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'POLICY-SDK-APP/src') diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java index 44a133068..a42d3d8d7 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java @@ -114,6 +114,13 @@ public class AutoPushController extends RestrictedBaseController { return policyController != null ? getPolicyController() : new PolicyController(); } + private Set addAllScopes(Roles userRole, Set scopes) { + if (userRole.getScope() != null) { + scopes.addAll(Stream.of(userRole.getScope().split(",")).collect(Collectors.toSet())); + } + return scopes; + } + @RequestMapping(value = {"/get_AutoPushPoliciesContainerData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) public void getPolicyGroupContainerData(HttpServletRequest request, HttpServletResponse response) { @@ -130,8 +137,9 @@ public class AutoPushController extends RestrictedBaseController { for (Object role : userRoles) { Roles userRole = (Roles) role; roles.add(userRole.getRole()); - scopes.addAll(Stream.of(userRole.getScope().split(",")).collect(Collectors.toSet())); + addAllScopes(userRole, scopes); } + if (roles.contains("super-admin") || roles.contains("super-editor") || roles.contains("super-guest")) { data = commonClassDao.getData(PolicyVersion.class); } else { -- cgit 1.2.3-korg