diff options
author | burdziak <olaf.burdziakowski@nokia.com> | 2019-03-18 15:24:30 +0100 |
---|---|---|
committer | burdziak <olaf.burdziakowski@nokia.com> | 2019-03-19 08:44:03 +0100 |
commit | f6ddf987897744272c57bb28a30ab39a15970677 (patch) | |
tree | 025ad2c8e2120c2dde8c12b32a85f114d35a9e4b /ecomp-sdk | |
parent | 1ded3bb69c5e91cd879d83e13d2b3295710cdb4f (diff) |
Fix sonar issues in RoleController
Change-Id: I95fe737705b9a92e6aeeb0ec917c0199b5e6a0a6
Issue-ID: PORTAL-523
Signed-off-by: burdziak <olaf.burdziakowski@nokia.com>
Diffstat (limited to 'ecomp-sdk')
-rw-r--r-- | ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java | 34 |
1 files changed, 18 insertions, 16 deletions
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<String, Object> model = new HashMap<>(); @@ -133,6 +131,14 @@ public class RoleController extends RestrictedBaseController { } + private void trowIfUserRoleExist(String roleName, String userId) throws IOException, SecurityException + { + List<Role> 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<Role> 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; + } } |