use of eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto in project CzechIdMng by bcvsolutions.
the class RoleRequestApprovalProcessor method process.
@Override
public EventResult<IdmRoleRequestDto> process(EntityEvent<IdmRoleRequestDto> event) {
IdmRoleRequestDto dto = event.getContent();
boolean checkRight = (boolean) event.getProperties().get(CHECK_RIGHT_PROPERTY);
//
String wfDefinition = getConfigurationValue(PROPERTY_WF);
if (Strings.isNullOrEmpty(wfDefinition)) {
wfDefinition = DEFAULT_WF_PROCESS_NAME;
}
boolean approved = service.startApprovalProcess(dto, checkRight, event, wfDefinition);
DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
result.setSuspended(!approved);
return result;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto in project CzechIdMng by bcvsolutions.
the class RoleRequestRealizationProcessor method process.
@Override
public EventResult<IdmRoleRequestDto> process(EntityEvent<IdmRoleRequestDto> event) {
IdmRoleRequestDto dto = event.getContent();
event.setContent(service.executeRequest(dto.getId()));
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestService method startRequestInternal.
@Override
@Transactional
public IdmRoleRequestDto startRequestInternal(UUID requestId, boolean checkRight) {
LOG.debug("Start role request [{}]", requestId);
Assert.notNull(requestId, "Role request ID is required!");
// Load request ... check right for read
IdmRoleRequestDto request = get(requestId);
Assert.notNull(request, "Role request DTO is required!");
Assert.isTrue(RoleRequestState.CONCEPT == request.getState() || RoleRequestState.DUPLICATED == request.getState() || RoleRequestState.EXCEPTION == request.getState(), "Only role request with CONCEPT or EXCEPTION or DUPLICATED state can be started!");
IdmRoleRequestDto duplicant = validateOnDuplicity(request);
if (duplicant != null) {
request.setState(RoleRequestState.DUPLICATED);
request.setDuplicatedToRequest(duplicant.getId());
this.addToLog(request, MessageFormat.format("This request [{0}] is duplicated to another change permissions request [{1}]", request.getId(), duplicant.getId()));
return this.save(request);
}
// Duplicant is fill, but request is not duplicated (maybe in past)
if (request.getDuplicatedToRequest() != null) {
request.setDuplicatedToRequest(null);
}
// Check on same applicants in all role concepts
boolean identityNotSame = this.get(request.getId()).getConceptRoles().stream().anyMatch(concept -> {
// get contract dto from embedded map
IdmIdentityContractDto contract = (IdmIdentityContractDto) concept.getEmbedded().get(IdmConceptRoleRequestService.IDENTITY_CONTRACT_FIELD);
if (contract == null) {
// If is contract from concept null, then contract via identity role must works
contract = (IdmIdentityContractDto) identityRoleService.get(concept.getIdentityRole()).getEmbedded().get(IdmConceptRoleRequestService.IDENTITY_CONTRACT_FIELD);
}
return !request.getApplicant().equals(contract.getIdentity());
});
if (identityNotSame) {
throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_APPLICANTS_NOT_SAME, ImmutableMap.of("request", request, "applicant", request.getApplicant()));
}
// Convert whole request to JSON and persist (without logs and embedded data)
try {
IdmRoleRequestDto requestOriginal = get(requestId);
trimRequest(requestOriginal);
request.setOriginalRequest(objectMapper.writeValueAsString(requestOriginal));
} catch (JsonProcessingException e) {
throw new RoleRequestException(CoreResultCode.BAD_REQUEST, e);
}
// Request will be set on in progress state
request.setState(RoleRequestState.IN_PROGRESS);
IdmRoleRequestDto savedRequest = this.save(request);
// Throw event
Map<String, Serializable> variables = new HashMap<>();
variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, checkRight);
return entityEventManager.process(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, savedRequest, variables)).getContent();
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto 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.dto.IdmRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestService method toDto.
@Override
public IdmRoleRequestDto toDto(IdmRoleRequest entity, IdmRoleRequestDto dto) {
IdmRoleRequestDto requestDto = super.toDto(entity, dto);
// Set concepts to request DTO
if (requestDto != null) {
requestDto.setConceptRoles(conceptRoleRequestService.findAllByRoleRequest(requestDto.getId()));
}
if (requestDto != null && requestDto.getWfProcessId() != null) {
WorkflowProcessInstanceDto processDto = workflowProcessInstanceService.get(requestDto.getWfProcessId(), false);
// TODO: create trimmed variant in workflow process instance service
if (processDto != null) {
processDto.setProcessVariables(null);
}
requestDto.getEmbedded().put(IdmRoleRequestDto.WF_PROCESS_FIELD, processDto);
}
return requestDto;
}
Aggregations