use of eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest_ in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestIdentityRoleService method save.
@Override
@Transactional
public IdmRequestIdentityRoleDto save(IdmRequestIdentityRoleDto dto, BasePermission... permission) {
LOG.debug(MessageFormat.format("Save idm-request-identity-role [{0}] ", dto));
Assert.notNull(dto, "DTO is required.");
// We don`t know if is given DTO identity-role or role-concept.
if (dto.getId() != null && dto.getId().equals(dto.getIdentityRole())) {
// Given DTO is identity-role -> create UPDATE concept
IdmIdentityRoleDto identityRole = identityRoleService.get(dto.getId());
Assert.notNull(identityRole, "Identity role is required.");
IdmIdentityContractDto identityContractDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.identityContract.getName(), IdmIdentityContractDto.class);
UUID requestId = dto.getRoleRequest();
IdmRoleRequestDto request = null;
if (requestId == null) {
request = this.createRequest(identityContractDto.getIdentity());
requestId = request.getId();
}
IdmConceptRoleRequestDto conceptRoleRequest = createConcept(identityRole, identityContractDto, requestId, identityRole.getRole(), identityContractDto.getValidFrom(), identityContractDto.getValidTill(), ConceptRoleRequestOperation.UPDATE);
conceptRoleRequest.setValidFrom(dto.getValidFrom());
conceptRoleRequest.setValidTill(dto.getValidTill());
conceptRoleRequest.setRoleSystem(dto.getRoleSystem());
conceptRoleRequest.setEavs(dto.getEavs());
// Create concept with EAVs
conceptRoleRequest = conceptRoleService.save(conceptRoleRequest, permission);
if (request != null) {
// Add request to concept. Will be used on the FE (prevent loading of request).
conceptRoleRequest.getEmbedded().put(IdmConceptRoleRequest_.roleRequest.getName(), request);
}
return this.conceptToRequestIdentityRole(conceptRoleRequest, null);
} else if (dto.getId() == null && dto.getIdentityRole() == null) {
// Given DTO does not have ID neither identity-role ID -> create ADD concept
Assert.notNull(dto.getIdentityContract(), "Contract is required.");
Set<UUID> roles = Sets.newHashSet();
if (dto.getRole() != null) {
roles.add(dto.getRole());
}
if (dto.getRoles() != null) {
roles.addAll(dto.getRoles());
}
Assert.notEmpty(roles, "Roles cannot be empty!");
IdmIdentityContractDto identityContractDto = identityContractService.get(dto.getIdentityContract());
UUID requestId = dto.getRoleRequest();
IdmRoleRequestDto request = null;
if (requestId == null) {
request = this.createRequest(identityContractDto.getIdentity());
requestId = request.getId();
}
List<IdmConceptRoleRequestDto> concepts = Lists.newArrayList();
UUID finalRequestId = requestId;
IdmRoleRequestDto finalRequest = request;
roles.forEach(role -> {
IdmConceptRoleRequestDto conceptRoleRequest = createConcept(null, identityContractDto, finalRequestId, role, dto.getValidFrom(), dto.getValidTill(), ConceptRoleRequestOperation.ADD);
conceptRoleRequest.setEavs(dto.getEavs());
conceptRoleRequest.setRoleSystem(dto.getRoleSystem());
// Create concept with EAVs
conceptRoleRequest = conceptRoleService.save(conceptRoleRequest);
if (finalRequest != null) {
// Add request to concept. Will be used on the FE (prevent loading of request).
conceptRoleRequest.getEmbedded().put(IdmConceptRoleRequest_.roleRequest.getName(), finalRequest);
}
concepts.add(conceptRoleRequest);
});
// Beware more then one concepts could be created, but only first will be returned!
return this.conceptToRequestIdentityRole(concepts.get(0), null);
} else {
// Try to find role-concept
IdmConceptRoleRequestDto roleConceptDto = conceptRoleService.get(dto.getId());
if (roleConceptDto != null) {
dto.setState(roleConceptDto.getState());
if (ConceptRoleRequestOperation.UPDATE == roleConceptDto.getOperation()) {
// Given DTO is concept -> update exists UPDATE concept
return this.conceptToRequestIdentityRole(conceptRoleService.save(dto, permission), null);
}
if (ConceptRoleRequestOperation.ADD == roleConceptDto.getOperation()) {
// Given DTO is concept -> update exists ADD concept
return this.conceptToRequestIdentityRole(conceptRoleService.save(dto, permission), null);
}
}
}
return null;
}
use of eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest_ in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestService method convertConceptRoleToIdentityRole.
private IdmIdentityRoleDto convertConceptRoleToIdentityRole(List<IdmConceptRoleRequestDto> allConcepts, IdmConceptRoleRequestDto conceptRole, IdmIdentityRoleDto identityRole) {
if (conceptRole == null || identityRole == null) {
return null;
}
IdmRoleDto roleDto = DtoUtils.getEmbedded(conceptRole, IdmConceptRoleRequest_.role, IdmRoleDto.class);
if (roleDto != null && roleDto.getIdentityRoleAttributeDefinition() != null) {
IdmFormDefinitionDto formDefinitionDto = roleService.getFormAttributeSubdefinition(roleDto);
formService.mergeValues(formDefinitionDto, conceptRole, identityRole);
}
identityRole.setRole(conceptRole.getRole());
identityRole.setIdentityContract(conceptRole.getIdentityContract());
identityRole.setContractPosition(conceptRole.getContractPosition());
identityRole.setValidFrom(conceptRole.getValidFrom());
identityRole.setValidTill(conceptRole.getValidTill());
identityRole.setOriginalCreator(conceptRole.getOriginalCreator());
identityRole.setOriginalCreatorId(conceptRole.getOriginalCreatorId());
identityRole.setOriginalModifier(conceptRole.getOriginalModifier());
identityRole.setOriginalModifierId(conceptRole.getOriginalModifierId());
identityRole.setAutomaticRole(conceptRole.getAutomaticRole());
// fill directly assigned role by superior concept
UUID directRole = conceptRole.getDirectRole();
UUID directConcept = conceptRole.getDirectConcept();
if (directRole != null) {
// update / delete / new role composition
identityRole.setDirectRole(directRole);
} else if (directConcept != null) {
// new identity role by superior concept
directRole = allConcepts.stream().filter(c -> c.getId().equals(directConcept)).findFirst().get().getIdentityRole();
identityRole.setDirectRole(directRole);
}
identityRole.setRoleComposition(conceptRole.getRoleComposition());
identityRole.setRoleSystem(conceptRole.getRoleSystem());
return identityRole;
}
use of eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest_ in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestService method getIncompatibleRoles.
@Override
public Set<ResolvedIncompatibleRoleDto> getIncompatibleRoles(IdmRoleRequestDto request, IdmBasePermission... permissions) {
// Currently assigned roles
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(request.getApplicant());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, null, permissions).getContent();
// Roles from concepts
IdmConceptRoleRequestFilter conceptFilter = new IdmConceptRoleRequestFilter();
conceptFilter.setRoleRequestId(request.getId());
List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.find(conceptFilter, null, permissions).getContent();
Set<UUID> removedIdentityRoleIds = new HashSet<>();
// We don't want calculate incompatible roles for ended or disapproved concepts
List<IdmConceptRoleRequestDto> conceptsForCheck = //
concepts.stream().filter(concept -> {
// role can be deleted in the mean time
return concept.getRole() != null;
}).filter(//
concept -> //
RoleRequestState.CONCEPT == concept.getState() || RoleRequestState.IN_PROGRESS == concept.getState() || RoleRequestState.APPROVED == concept.getState() || //
RoleRequestState.EXECUTED == concept.getState()).collect(Collectors.toList());
Set<IdmRoleDto> roles = new HashSet<>();
conceptsForCheck.stream().filter(concept -> {
boolean isDelete = concept.getOperation() == ConceptRoleRequestOperation.REMOVE;
if (isDelete) {
// removed role fixes the incompatibility
removedIdentityRoleIds.add(concept.getIdentityRole());
}
return !isDelete;
}).forEach(concept -> roles.add(DtoUtils.getEmbedded(concept, IdmConceptRoleRequest_.role)));
identityRoles.stream().filter(identityRole -> !removedIdentityRoleIds.contains(identityRole.getId())).forEach(identityRole -> roles.add(DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.role)));
// We want to returns only incompatibilities caused by new added roles
Set<ResolvedIncompatibleRoleDto> incompatibleRoles = incompatibleRoleService.resolveIncompatibleRoles(Lists.newArrayList(roles));
return //
incompatibleRoles.stream().filter(incompatibleRole -> {
return //
conceptsForCheck.stream().anyMatch(concept -> concept.getOperation() == ConceptRoleRequestOperation.ADD && (concept.getRole().equals(incompatibleRole.getDirectRole().getId()) || concept.getRole().equals(incompatibleRole.getIncompatibleRole().getSuperior()) || concept.getRole().equals(incompatibleRole.getIncompatibleRole().getSub())));
//
}).collect(Collectors.toSet());
}
Aggregations