use of eu.bcvsolutions.idm.core.api.exception.RoleRequestException in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestService method executeRequestInternal.
private IdmRoleRequestDto executeRequestInternal(UUID requestId) {
Assert.notNull(requestId, "Role request ID is required!");
IdmRoleRequestDto request = this.get(requestId);
Assert.notNull(request, "Role request is required!");
List<IdmConceptRoleRequestDto> concepts = request.getConceptRoles();
IdmIdentityDto identity = identityService.get(request.getApplicant());
boolean identityNotSame = concepts.stream().anyMatch(concept -> {
// get contract dto from embedded map
IdmIdentityContractDto contract = (IdmIdentityContractDto) concept.getEmbedded().get(IdmConceptRoleRequestService.IDENTITY_CONTRACT_FIELD);
return !identity.getId().equals(contract.getIdentity());
});
if (identityNotSame) {
throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_APPLICANTS_NOT_SAME, ImmutableMap.of("request", request, "applicant", identity.getUsername()));
}
// Create new identity role
concepts.stream().filter(concept -> {
return ConceptRoleRequestOperation.ADD == concept.getOperation();
}).filter(concept -> {
// approval event disabled)
return RoleRequestState.APPROVED == concept.getState() || RoleRequestState.CONCEPT == concept.getState();
}).forEach(concept -> {
IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
identityRole = identityRoleService.save(convertConceptRoleToIdentityRole(conceptRoleRequestService.get(concept.getId()), identityRole));
// Save created identity role id
concept.setIdentityRole(identityRole.getId());
concept.setState(RoleRequestState.EXECUTED);
IdmRoleDto roleDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.role, IdmRoleDto.class);
String message = MessageFormat.format("Role [{0}] was added to applicant. Requested in concept [{1}].", roleDto.getCode(), concept.getId());
conceptRoleRequestService.addToLog(concept, message);
conceptRoleRequestService.addToLog(request, message);
conceptRoleRequestService.save(concept);
});
// Update identity role
concepts.stream().filter(concept -> {
return ConceptRoleRequestOperation.UPDATE == concept.getOperation();
}).filter(concept -> {
// approval event disabled)
return RoleRequestState.APPROVED == concept.getState() || RoleRequestState.CONCEPT == concept.getState();
}).forEach(concept -> {
IdmIdentityRoleDto identityRole = identityRoleService.get(concept.getIdentityRole());
identityRole = identityRoleService.save(convertConceptRoleToIdentityRole(conceptRoleRequestService.get(concept.getId()), identityRole));
// Save created identity role id
concept.setIdentityRole(identityRole.getId());
concept.setState(RoleRequestState.EXECUTED);
IdmRoleDto roleDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.role, IdmRoleDto.class);
String message = MessageFormat.format("Role [{0}] was changed. Requested in concept [{1}].", roleDto.getCode(), concept.getId());
conceptRoleRequestService.addToLog(concept, message);
conceptRoleRequestService.addToLog(request, message);
conceptRoleRequestService.save(concept);
});
// Delete identity role
concepts.stream().filter(concept -> {
return ConceptRoleRequestOperation.REMOVE == concept.getOperation();
}).filter(concept -> {
// approval event disabled)
return RoleRequestState.APPROVED == concept.getState() || RoleRequestState.CONCEPT == concept.getState();
}).filter(concept -> {
return concept.getIdentityRole() != null;
}).forEach(concept -> {
IdmIdentityRoleDto identityRole = identityRoleService.get(concept.getIdentityRole());
if (identityRole != null) {
concept.setState(RoleRequestState.EXECUTED);
// we have to remove relation on
concept.setIdentityRole(null);
// deleted identityRole
String message = MessageFormat.format("IdentityRole [{0}] (reqested in concept [{1}]) was deleted (from this role request).", identityRole.getId(), concept.getId());
conceptRoleRequestService.addToLog(concept, message);
conceptRoleRequestService.addToLog(request, message);
conceptRoleRequestService.save(concept);
identityRoleService.delete(identityRole);
}
});
request.setState(RoleRequestState.EXECUTED);
return this.save(request);
}
use of eu.bcvsolutions.idm.core.api.exception.RoleRequestException in project CzechIdMng by bcvsolutions.
the class IdmAutomaticRoleRequestController method delete.
@Override
@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.DELETE)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_DELETE + "')")
@ApiOperation(value = "Delete role request", nickname = "deleteRoleRequest", tags = { IdmAutomaticRoleRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_DELETE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_DELETE, description = "") }) })
public ResponseEntity<?> delete(@ApiParam(value = "Role request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
IdmAutomaticRoleRequestService service = ((IdmAutomaticRoleRequestService) this.getService());
IdmAutomaticRoleRequestDto dto = service.get(backendId);
//
checkAccess(dto, IdmBasePermission.DELETE);
// Request in Executed state can not be delete or change
if (RequestState.EXECUTED == dto.getState()) {
throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_EXECUTED_CANNOT_DELETE, ImmutableMap.of("request", dto));
}
// Only request in Concept state, can be deleted. In others states, will be request set to Canceled state and save.
if (RequestState.CONCEPT == dto.getState()) {
service.delete(dto);
} else {
service.cancel(dto);
}
return new ResponseEntity<Object>(HttpStatus.NO_CONTENT);
}
Aggregations