use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class RoleActions method updateWithoutChecks.
@Override
protected ActionResponse<RolePermissionModel> updateWithoutChecks(Long id, RolePermissionModel resource) {
try {
String roleName = resource.getRoleName();
Optional<UserRoleModel> existingRole = roleAccessor.getRoles(List.of(id)).stream().findFirst();
if (existingRole.isPresent()) {
logger.debug(actionMessageCreator.updateStartMessage("role", existingRole.get().getName()));
if (!existingRole.get().getName().equals(roleName)) {
authorizationManager.updateRoleName(id, roleName);
}
Set<PermissionModel> permissions = resource.getPermissions();
PermissionMatrixModel permissionMatrixModel = PermissionModelUtil.convertToPermissionMatrixModel(permissions);
authorizationManager.updatePermissionsForRole(roleName, permissionMatrixModel);
logger.debug(actionMessageCreator.updateSuccessMessage("Role", roleName));
return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
logger.warn(actionMessageCreator.updateNotFoundMessage("Role", id));
return new ActionResponse<>(HttpStatus.NOT_FOUND, "Role not found.");
} catch (AlertException ex) {
logger.error(actionMessageCreator.updateErrorMessage("role", resource.getRoleName()));
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
Aggregations