use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityChangeContractGuaranteeBulkAction method processDto.
@Override
protected OperationResult processDto(IdmIdentityDto identity) {
UUID newGuarantee = getSelectedGuaranteeUuid(PROPERTY_NEW_GUARANTEE);
UUID oldGuarantee = getSelectedGuaranteeUuid(PROPERTY_OLD_GUARANTEE);
if (ObjectUtils.equals(newGuarantee, oldGuarantee)) {
return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Map<UUID, List<IdmContractGuaranteeDto>> currentGuaranteesByContract = getIdentityGuaranteesOrderedByContract(identity.getId());
// iterate over all contract UUIDs ~ keys and contractGuarantees in List ~ values
currentGuaranteesByContract.forEach((contractId, contractGuarantees) -> {
List<IdmContractGuaranteeDto> toUpdate = contractGuarantees.stream().filter(dto -> dto.getGuarantee().equals(oldGuarantee)).collect(Collectors.toList());
if (toUpdate.isEmpty()) {
// there is no guarantee who to replace for this contract, start new iteration
return;
}
for (IdmContractGuaranteeDto guarantee : toUpdate) {
// if same guarantee added multiple-times update all occurrences
try {
guarantee.setGuarantee(newGuarantee);
contractGuaranteeService.save(guarantee, IdmBasePermission.UPDATE);
logItemProcessed(guarantee, new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (ForbiddenEntityException ex) {
LOG.warn("Not authorized to remove the contract guarantee [{}] from contract [{}] .", guarantee, contractId, ex);
logContractGuaranteePermissionError(guarantee, guarantee.getGuarantee(), contractId, IdmBasePermission.UPDATE, ex);
// start the new iteration for another contract, this guarantee wasn't removed here
return;
} catch (ResultCodeException ex) {
logResultCodeException(guarantee, ex);
// start the new iteration for another contract, this guarantee wasn't removed here
return;
}
}
});
return new OperationResult.Builder(OperationState.EXECUTED).build();
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityRemoveContractGuaranteeBulkAction method processDto.
@Override
protected OperationResult processDto(IdmIdentityDto identity) {
Set<UUID> selectedGuarantees = getSelectedGuaranteeUuids(PROPERTY_OLD_GUARANTEE);
Map<UUID, List<IdmContractGuaranteeDto>> currentGuarantees = getIdentityGuaranteesOrderedByContract(identity.getId());
currentGuarantees.forEach((contractId, contractGuarantees) -> {
// create list of guarantee dtos to delete
List<IdmContractGuaranteeDto> toDelete = contractGuarantees.stream().filter(guarantee -> selectedGuarantees.contains(guarantee.getGuarantee())).collect(Collectors.toList());
// delete guarantees
for (IdmContractGuaranteeDto guarantee : toDelete) {
try {
contractGuaranteeService.delete(guarantee, IdmBasePermission.DELETE);
logItemProcessed(guarantee, new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (ForbiddenEntityException ex) {
LOG.warn("Not authorized to remove contract guarantee [{}] of contract [{}].", guarantee.getGuarantee(), contractId, ex);
logContractGuaranteePermissionError(guarantee, guarantee.getGuarantee(), contractId, IdmBasePermission.DELETE, ex);
} catch (ResultCodeException ex) {
logResultCodeException(guarantee, ex);
}
}
});
return new OperationResult.Builder(OperationState.EXECUTED).build();
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityContractAddGuaranteeByProjectionProcessorIntegrationTest method testGuaranteeIsNotCreatedWithoutLogin.
@Test
public void testGuaranteeIsNotCreatedWithoutLogin() {
// create identity with projection
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setFormProjection(createProjection(true).getId());
identity = identityService.save(identity);
//
// create new contract for identity with projection
IdmIdentityContractDto contract = getHelper().createContract(identity);
//
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setIdentityContractId(contract.getId());
//
List<IdmContractGuaranteeDto> guarantees = contractGuaranteeService.find(filter, null).getContent();
Assert.assertTrue(guarantees.isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityContractAddGuaranteeByProjectionProcessorIntegrationTest method testGuaranteeIsCreated.
@Test
public void testGuaranteeIsCreated() {
IdmIdentityDto manager = getHelper().createIdentity();
// create identity with projection
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setFormProjection(createProjection(true).getId());
identity = identityService.save(identity);
//
try {
getHelper().login(manager);
//
// create new contract for identity with projection
IdmIdentityContractDto contract = getHelper().createContract(identity);
//
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setIdentityContractId(contract.getId());
filter.setGuaranteeId(manager.getId());
//
List<IdmContractGuaranteeDto> guarantees = contractGuaranteeService.find(filter, null).getContent();
Assert.assertEquals(1, guarantees.size());
Assert.assertTrue(guarantees.stream().allMatch(g -> g.getGuarantee().equals(manager.getId())));
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method save.
/**
* Save entity
*
* @param entity
* @param skipProvisioning
* @return
*/
@Override
protected IdmIdentityContractDto save(IdmIdentityContractDto entity, boolean skipProvisioning) {
if (entity.getIdentity() == null) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_CANNOT_BE_NULL, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
}
EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(contractService.isNew(entity) ? IdentityContractEventType.CREATE : IdentityContractEventType.UPDATE, entity, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
// We do not want execute HR processes for every contract. We need start
// them for every identity only once.
// For this we skip them now. HR processes must be start after whole
// sync finished (by using dependent scheduled task)!
event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
//
// We don't want recalculate automatic role by attribute recalculation for every contract.
// Recalculation will be started only once.
event.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, Boolean.TRUE);
IdmIdentityContractDto contract = contractService.publish(event).getContent();
if (entity.getEmbedded().containsKey(SYNC_CONTRACT_FIELD)) {
SyncIdentityContractDto syncContract = (SyncIdentityContractDto) entity.getEmbedded().get(SYNC_CONTRACT_FIELD);
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contract.getId());
List<IdmContractGuaranteeDto> currentGuarantees = guaranteeService.find(guaranteeFilter, null).getContent();
// Search guarantees to delete
List<IdmContractGuaranteeDto> guaranteesToDelete = currentGuarantees.stream().filter(sysImplementer -> {
return sysImplementer.getGuarantee() != null && !syncContract.getGuarantees().contains(new IdmIdentityDto(sysImplementer.getGuarantee()));
}).collect(Collectors.toList());
// Search guarantees to add
List<IdmIdentityDto> guaranteesToAdd = syncContract.getGuarantees().stream().filter(identity -> {
return !currentGuarantees.stream().filter(currentGuarrantee -> {
return identity.getId().equals(currentGuarrantee.getGuarantee());
}).findFirst().isPresent();
}).collect(Collectors.toList());
// Delete guarantees
guaranteesToDelete.forEach(guarantee -> {
EntityEvent<IdmContractGuaranteeDto> guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.DELETE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
guaranteeService.publish(guaranteeEvent);
});
// Create new guarantees
guaranteesToAdd.forEach(identity -> {
IdmContractGuaranteeDto guarantee = new IdmContractGuaranteeDto();
guarantee.setIdentityContract(contract.getId());
guarantee.setGuarantee(identity.getId());
//
EntityEvent<IdmContractGuaranteeDto> guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.CREATE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
guaranteeService.publish(guaranteeEvent);
});
}
return contract;
}
Aggregations