use of org.usermanagement.dao.entity.PermissionEntity in project open-kilda by telstra.
the class RoleService method assignRoleByPermissionId.
/**
* Assign role by permission id.
*
* @param permissionId the permission id
* @param request the request
* @return the permission
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Permission assignRoleByPermissionId(final Long permissionId, final Permission request) {
PermissionEntity permissionEntity = permissionRepository.findByPermissionId(permissionId);
if (ValidatorUtil.isNull(permissionEntity)) {
LOGGER.warn("Permission with permissionId '" + permissionId + "' not found. Error: " + messageUtil.getAttributeInvalid("permissionId", permissionId + ""));
throw new RequestValidationException(messageUtil.getAttributeInvalid("permissionId", permissionId + ""));
}
permissionEntity.getRoles().clear();
if (request.getRoles() != null) {
for (Role role : request.getRoles()) {
RoleEntity roleEntity = roleRepository.findByRoleId(role.getRoleId());
permissionEntity.getRoles().add(roleEntity);
}
}
permissionRepository.save(permissionEntity);
activityLogger.log(ActivityType.ASSIGN_ROLES_TO_PERMISSION, permissionEntity.getName());
LOGGER.info("Roles assigned with permission successfully (permissionId: " + permissionId + ")");
return RoleConversionUtil.toPermissionByRole(permissionEntity.getRoles(), permissionEntity);
}
use of org.usermanagement.dao.entity.PermissionEntity in project open-kilda by telstra.
the class PermissionService method createPermission.
/**
* Creates the permission.
*
* @param permission the permission
* @return the permission
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Permission createPermission(final Permission permission) {
permissionValidator.validatePermission(permission);
PermissionEntity permissionEntity = PermissionConversionUtil.toPermissionEntity(permission);
permissionRepository.save(permissionEntity);
activityLogger.log(ActivityType.CREATE_PERMISSION, permission.getName());
LOGGER.info("Permission with name '" + permission.getName() + "' created successfully.");
return PermissionConversionUtil.toPermission(permissionEntity, null);
}
use of org.usermanagement.dao.entity.PermissionEntity in project open-kilda by telstra.
the class PermissionService method getPermissionById.
/**
* Gets the permission by id.
*
* @param permissionId the permission id
* @return the permission by id
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Permission getPermissionById(final Long permissionId) {
PermissionEntity permissionEntity = permissionRepository.findByPermissionId(permissionId);
if (ValidatorUtil.isNull(permissionEntity)) {
LOGGER.warn("Permission with permissionId '" + permissionId + "' not found. Error: " + messageUtil.getAttributeInvalid("permission_id", permissionId + ""));
throw new RequestValidationException(messageUtil.getAttributeInvalid("permission_id", permissionId + ""));
}
Set<RoleEntity> roleEntityList = roleRepository.findByPermissions_permissionId(permissionId);
return PermissionConversionUtil.toPermission(permissionEntity, roleEntityList);
}
use of org.usermanagement.dao.entity.PermissionEntity in project open-kilda by telstra.
the class PermissionService method deletePermissionById.
/**
* Delete permission by id.
*
* @param permissionId the permission id
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void deletePermissionById(final Long permissionId) {
PermissionEntity permissionEntity = permissionRepository.findByPermissionId(permissionId);
if (ValidatorUtil.isNull(permissionEntity)) {
throw new RequestValidationException(messageUtil.getAttributeInvalid("permission_id", permissionId + ""));
}
Set<RoleEntity> roleEntityList = roleRepository.findByPermissions_permissionId(permissionId);
if (roleEntityList.size() > 0) {
String roles = "";
for (RoleEntity roleEntity : roleEntityList) {
roles += !"".equals(roles) ? "," + roleEntity.getName() : roleEntity.getName();
}
LOGGER.warn("Permission with permissionId '" + permissionId + "' not allowed to delete. Error: " + messageUtil.getAttributeDeletionNotAllowed(permissionEntity.getName(), roles));
throw new RequestValidationException(messageUtil.getAttributeDeletionNotAllowed(permissionEntity.getName(), roles));
}
permissionRepository.delete(permissionEntity);
LOGGER.info("Permission(permissionId: " + permissionId + ") deleted successfully.");
activityLogger.log(ActivityType.DELETE_PERMISSION, permissionEntity.getName());
}
use of org.usermanagement.dao.entity.PermissionEntity 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