From f6ddf987897744272c57bb28a30ab39a15970677 Mon Sep 17 00:00:00 2001 From: burdziak Date: Mon, 18 Mar 2019 15:24:30 +0100 Subject: Fix sonar issues in RoleController Change-Id: I95fe737705b9a92e6aeeb0ec917c0199b5e6a0a6 Issue-ID: PORTAL-523 Signed-off-by: burdziak --- .../portalapp/controller/core/RoleController.java | 34 ++++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'ecomp-sdk') diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java index 52dedd46..d555ba46 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java @@ -84,8 +84,6 @@ public class RoleController extends RestrictedBaseController { @Autowired private RoleService roleService; - private String viewName; - @RequestMapping(value = { "/role" }, method = RequestMethod.GET) public ModelAndView role(HttpServletRequest request) throws IOException { Map model = new HashMap<>(); @@ -133,6 +131,14 @@ public class RoleController extends RestrictedBaseController { } + private void trowIfUserRoleExist(String roleName, String userId) throws IOException, SecurityException + { + List roles = roleService.getAvailableRoles(userId); + for (Role existRole : roles) + if (existRole.getName().equalsIgnoreCase(roleName)) + throw new SecurityException("role already exists: " + existRole.getName()); + } + /** * Creates a new role or updates an existing role. * @@ -167,11 +173,8 @@ public class RoleController extends RestrictedBaseController { domainRole.setPriority(role.getPriority()); } else { doAuditLog("saveRole: creating new role", role.getName()); - // check for existing role of same name - List roles = roleService.getAvailableRoles(user.getOrgUserId()); - for (Role existRole : roles) - if (existRole.getName().equalsIgnoreCase(role.getName())) - throw new Exception("role already exists: " + existRole.getName()); + + trowIfUserRoleExist(role.getName(),user.getOrgUserId()); domainRole = new Role(); domainRole.setName(role.getName()); @@ -371,13 +374,12 @@ public class RoleController extends RestrictedBaseController { } @Override - public String getViewName() { - return viewName; - } - - @Override - public void setViewName(String viewName) { - this.viewName = viewName; - } - + public String getViewName() { + return viewName; + } + + @Override + public void setViewName(String viewName) { + this.viewName = viewName; + } } -- cgit 1.2.3-korg