@Override public void updateRole(RoleDto role) { MotechRole motechRole = allMotechRoles.findByRoleName(role.getOriginalRoleName()); motechRole.setRoleName(role.getRoleName()); motechRole.setPermissionNames(role.getPermissionNames()); List<MotechUser> users = (List<MotechUser>) allMotechUsers.findByRole(role.getOriginalRoleName()); for (MotechUser user : users) { List<String> roleList = user.getRoles(); roleList.remove(role.getOriginalRoleName()); roleList.add(role.getRoleName()); allMotechUsers.update(user); } allMotechRoles.update(motechRole); }
@Override public List<RoleDto> getRoles() { List<RoleDto> roles = new ArrayList<>(); for (MotechRole role : allMotechRoles.getRoles()) { roles.add(new RoleDto(role)); } return roles; }
@Override public void createRole(RoleDto role) { MotechRole motechRole = new MotechRoleCouchdbImpl(role.getRoleName(), role.getPermissionNames()); allMotechRoles.add(motechRole); }
@Override public void deleteRole(RoleDto role) { MotechRole motechRole = allMotechRoles.findByRoleName(role.getRoleName()); allMotechRoles.remove(motechRole); }
@Override public RoleDto getRole(String roleName) { MotechRole motechRole = allMotechRoles.findByRoleName(roleName); return motechRole != null ? new RoleDto(motechRole) : null; }