use of org.motechproject.security.exception.RoleHasUserException 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