use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_ 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);
}
Aggregations