use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class PermissionConversionUtil method toPermission.
/**
* To permission.
*
* @param permissionEntity the permission entity
* @param roleEntities the role entities
* @return the permission
*/
public static Permission toPermission(final PermissionEntity permissionEntity, final Set<RoleEntity> roleEntities) {
Permission permission = new Permission();
permission.setName(permissionEntity.getName());
permission.setPermissionId(permissionEntity.getPermissionId());
permission.setIsEditable(permissionEntity.getIsEditable());
permission.setIsAdminPermission(permissionEntity.getIsAdminPermission());
permission.setStatus(permissionEntity.getStatusEntity().getStatus());
permission.setDescription(permissionEntity.getDescription());
if (!ValidatorUtil.isNull(roleEntities)) {
List<Role> roles = new ArrayList<>();
for (RoleEntity entity : roleEntities) {
Role role = new Role();
role.setRoleId(entity.getRoleId());
role.setName(entity.getName());
roles.add(role);
}
permission.setRoles(roles);
}
return permission;
}
use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class RoleConversionUtil method toPermissionByRole.
/**
* To permission by role.
*
* @param roleEntityList the role entity list
* @param permissionEntity the permission entity
* @return the permission
*/
public static Permission toPermissionByRole(final Set<RoleEntity> roleEntityList, final PermissionEntity permissionEntity) {
Permission permission = new Permission();
permission.setName(permissionEntity.getName());
permission.setDescription(permissionEntity.getDescription());
permission.setPermissionId(permissionEntity.getPermissionId());
List<Role> role = new ArrayList<>();
for (RoleEntity roleEntity : roleEntityList) {
Role roles = new Role();
roles.setRoleId(roleEntity.getRoleId());
roles.setName(roleEntity.getName());
role.add(roles);
}
permission.setRoles(role);
return permission;
}
use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class RoleService method deleteRoleById.
/**
* Delete role by id.
*
* @param roleId the role id
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void deleteRoleById(final Long roleId) {
RoleEntity roleEntity = roleRepository.findByRoleId(roleId);
if (ValidatorUtil.isNull(roleEntity)) {
LOGGER.warn("Role with role id '" + roleId + "' not found. Error: " + messageUtil.getAttributeInvalid("role_id", roleId + ""));
throw new RequestValidationException(messageUtil.getAttributeInvalid("role_id", roleId + ""));
}
Set<UserEntity> userEntityList = userRepository.findByRoles_roleId(roleId);
if (userEntityList.size() > 0) {
String users = "";
for (UserEntity userEntity : userEntityList) {
users += !"".equals(users) ? "," + userEntity.getName() : userEntity.getName();
}
LOGGER.warn("Role with role id '" + roleId + "' not allowed to delete. Error: " + messageUtil.getAttributeDeletionNotAllowed(roleEntity.getName(), users));
throw new RequestValidationException(messageUtil.getAttributeDeletionNotAllowed(roleEntity.getName(), users));
}
roleRepository.delete(roleEntity);
activityLogger.log(ActivityType.DELETE_ROLE, roleEntity.getName());
LOGGER.info("Role(roleId: " + roleId + ") deleted successfully.");
}
use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class RoleService method getRolesById.
/**
* Gets the roles by id.
*
* @param roleIds the role ids
* @return the roles by id
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Set<RoleEntity> getRolesById(final List<Long> roleIds) {
Set<RoleEntity> roleEntities = new HashSet<>();
List<RoleEntity> roleEntityList = roleRepository.findAll();
for (Long roleId : roleIds) {
RoleEntity roleEntity = roleEntityList.parallelStream().filter((entity) -> entity.getRoleId().equals(roleId)).findFirst().orElse(null);
if (!ValidatorUtil.isNull(roleEntity)) {
roleEntities.add(roleEntity);
} else {
LOGGER.warn("Role with role id '" + roleId + "' not found. Error: " + messageUtil.getAttributeNotFound("roles"));
throw new RequestValidationException(messageUtil.getAttributeNotFound("roles"));
}
}
return roleEntities;
}
use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class RoleService method updateRole.
/**
* Update role.
*
* @param roleId the role id
* @param role the role
* @return the role
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Role updateRole(final Long roleId, final Role role) {
roleValidator.validateUpdateRole(role, roleId);
RoleEntity roleEntity = roleRepository.findByRoleId(roleId);
if (ValidatorUtil.isNull(roleEntity)) {
LOGGER.warn("Role with role id '" + roleId + "' not found. Error: " + messageUtil.getAttributeInvalid("role_id", roleId + ""));
throw new RequestValidationException(messageUtil.getAttributeInvalid("role_id", roleId + ""));
}
if (role.getPermissionId() != null) {
roleEntity.getPermissions().clear();
for (Long permissionId : role.getPermissionId()) {
PermissionEntity permissionEntity = permissionRepository.findByPermissionId(permissionId);
if (permissionEntity != null) {
roleEntity.getPermissions().add(permissionEntity);
}
}
}
roleEntity = RoleConversionUtil.toUpateRoleEntity(role, roleEntity);
roleRepository.save(roleEntity);
activityLogger.log(ActivityType.UPDATE_ROLE, roleEntity.getName());
LOGGER.info("Role updated successfully (roleId: " + roleId + ")");
return RoleConversionUtil.toRole(roleEntity, true, false);
}
Aggregations