use of org.motechproject.security.domain.MotechRole in project motech by motech.
the class MotechRoleServiceImpl method createRole.
@Override
@Transactional
public void createRole(RoleDto role) {
if (findByRoleName(role.getRoleName()) == null) {
LOGGER.info("Creating role: {}", role.getRoleName());
MotechRole motechRole = new MotechRole(role.getRoleName(), role.getPermissionNames(), role.isDeletable());
motechRolesDataService.create(motechRole);
userContextsService.refreshAllUsersContextIfActive();
LOGGER.info("Created role: {}", role.getRoleName());
} else {
LOGGER.info("A role with name {} alredy exists. The role has not been added.", role.getRoleName());
}
}
use of org.motechproject.security.domain.MotechRole in project motech by motech.
the class MotechRoleServiceImpl method updateRole.
@Override
@Transactional
public void updateRole(RoleDto role) {
LOGGER.info("Updating role: {}", role.getRoleName());
MotechRole motechRole = findByRoleName(role.getOriginalRoleName());
motechRole.setRoleName(role.getRoleName());
motechRole.setPermissionNames(role.getPermissionNames());
List<MotechUser> users = motechUsersDao.findByRole(role.getOriginalRoleName());
if (StringUtils.equals(role.getRoleName(), role.getOriginalRoleName())) {
for (MotechUser user : users) {
List<String> roleList = user.getRoles();
roleList.remove(role.getOriginalRoleName());
roleList.add(role.getRoleName());
motechUsersDao.update(user);
}
}
motechRolesDataService.update(motechRole);
userContextsService.refreshAllUsersContextIfActive();
LOGGER.info("Updated role: {}", role.getRoleName());
}
use of org.motechproject.security.domain.MotechRole in project motech by motech.
the class MotechRoleServiceImpl method deleteRole.
@Override
@Transactional
public void deleteRole(RoleDto role) {
LOGGER.info("Deleting role: {}", role.getRoleName());
MotechRole motechRole = findByRoleName(role.getRoleName());
if (motechRole.isDeletable()) {
List<MotechUser> users = motechUsersDao.findByRole(role.getRoleName());
if (!users.isEmpty()) {
throw new RoleHasUserException("Role cannot be deleted because a user has the role.");
}
motechRolesDataService.delete(motechRole);
userContextsService.refreshAllUsersContextIfActive();
LOGGER.info("Deleted role: {}", role);
} else {
LOGGER.warn("The role {} cant be deleted", role.getRoleName());
}
}
Aggregations