diff options
author | Manoop Talasila <talasila@research.att.com> | 2019-04-11 13:49:19 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-11 13:49:19 +0000 |
commit | 898f19716c4ef430743b530f586fac97f493df85 (patch) | |
tree | cf06b9de35ce4a9c7af9fe359875afe9af429565 /ecomp-sdk/epsdk-app-common/src/main/java | |
parent | 9021afe073998a216924bbafe63dcead16596e02 (diff) | |
parent | f6ddf987897744272c57bb28a30ab39a15970677 (diff) |
Merge "Fix sonar issues in RoleController"
Diffstat (limited to 'ecomp-sdk/epsdk-app-common/src/main/java')
-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; + } } |