use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractSliceGuaranteeSaveProcessor method process.
@Override
public EventResult<IdmContractSliceGuaranteeDto> process(EntityEvent<IdmContractSliceGuaranteeDto> event) {
IdmContractSliceGuaranteeDto dto = event.getContent();
//
dto = contractSliceGuaranteeService.saveInternal(dto);
//
event.setContent(dto);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeSaveAndDeleteProcessorTest method testDeleteGuaranteeOfContractWithSlice.
@Test
public void testDeleteGuaranteeOfContractWithSlice() {
IdmIdentityDto sliceGuarantee = getHelper().createIdentity();
IdmIdentityDto identity = getHelper().createIdentity();
IdmContractSliceDto slice = getHelper().createContractSlice(identity, null, LocalDate.now().minusDays(1), null, null);
UUID contractId = slice.getParentContract();
getHelper().createContractSliceGuarantee(slice.getId(), sliceGuarantee.getId());
IdmContractSliceGuaranteeFilter sliceGuaranteefilter = new IdmContractSliceGuaranteeFilter();
sliceGuaranteefilter.setGuaranteeId(sliceGuarantee.getId());
List<IdmContractSliceGuaranteeDto> sliceGuarantees = contractSliceGuaranteeService.find(sliceGuaranteefilter, null).getContent();
Assert.assertEquals(1, sliceGuarantees.size());
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contractId);
List<IdmContractGuaranteeDto> contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(1, contractGuarantees.size());
IdmIdentityDto sliceGuaranteeIdent = DtoUtils.getEmbedded(sliceGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
IdmIdentityDto contractGuaranteeIdent = DtoUtils.getEmbedded(contractGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
Assert.assertEquals(sliceGuaranteeIdent.getId(), contractGuaranteeIdent.getId());
try {
contractGuaranteeService.delete(contractGuarantees.get(0));
fail("Contract guarantee can't be deleted directly when slice is applied");
} catch (ResultCodeException ex) {
Assert.assertTrue(CoreResultCode.CONTRACT_IS_CONTROLLED_GUARANTEE_CANNOT_BE_DELETED.toString().equals(ex.getError().getErrors().get(0).getStatusEnum()));
}
// guarantee can be still deleted via contract slice operation
contractSliceGuaranteeService.delete(sliceGuarantees.get(0));
sliceGuarantees = contractSliceGuaranteeService.find(sliceGuaranteefilter, null).getContent();
Assert.assertEquals(0, sliceGuarantees.size());
contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(0, contractGuarantees.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSynchronizationExecutor method save.
/**
* Save entity
*
* @param entity
* @param skipProvisioning
* @return
*/
@Override
protected IdmContractSliceDto save(IdmContractSliceDto entity, boolean skipProvisioning, SynchronizationContext context) {
if (entity.getIdentity() == null) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_CANNOT_BE_NULL, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
}
EntityEvent<IdmContractSliceDto> event = new ContractSliceEvent(sliceService.isNew(entity) ? ContractSliceEventType.CREATE : ContractSliceEventType.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(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
//
// Set dirty state during recalculation, the process of recalculation will be solved in ClearDirtyStateForContractSliceTaskExecutor
// ClearDirtyStateForContractSliceTaskExecutor will be started with HR processes.
event.getProperties().put(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE);
IdmContractSliceDto slice = sliceService.publish(event).getContent();
if (entity.getEmbedded().containsKey(SYNC_CONTRACT_FIELD)) {
SyncIdentityContractDto syncContract = (SyncIdentityContractDto) entity.getEmbedded().get(SYNC_CONTRACT_FIELD);
IdmContractSliceGuaranteeFilter guaranteeFilter = new IdmContractSliceGuaranteeFilter();
guaranteeFilter.setContractSliceId(slice.getId());
List<IdmContractSliceGuaranteeDto> currentGuarantees = guaranteeService.find(guaranteeFilter, null).getContent();
// Search guarantees to delete
List<IdmContractSliceGuaranteeDto> 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<IdmContractSliceGuaranteeDto> guaranteeEvent = new ContractSliceGuaranteeEvent(ContractSliceGuaranteeEventType.DELETE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
guaranteeService.publish(guaranteeEvent);
});
// Create new guarantees
guaranteesToAdd.forEach(identity -> {
IdmContractSliceGuaranteeDto guarantee = new IdmContractSliceGuaranteeDto();
guarantee.setContractSlice(slice.getId());
guarantee.setGuarantee(identity.getId());
//
EntityEvent<IdmContractSliceGuaranteeDto> guaranteeEvent = new ContractSliceGuaranteeEvent(ContractSliceGuaranteeEventType.CREATE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
guaranteeService.publish(guaranteeEvent);
});
}
return slice;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSynchronizationExecutor method isGuaranteesSame.
/**
* Check if current contract's slices guarantees are same as in account values
*
* @param dto
* @param newGuarantees
* @return
*/
private boolean isGuaranteesSame(IdmContractSliceDto dto, List<IdmIdentityDto> newGuarantees) {
// Guarantees
IdmContractSliceGuaranteeFilter guaranteeFilter = new IdmContractSliceGuaranteeFilter();
guaranteeFilter.setContractSliceId(dto.getId());
List<IdmContractSliceGuaranteeDto> currentGuarantees = guaranteeService.find(guaranteeFilter, null).getContent();
List<UUID> currentGuranteeIds = currentGuarantees.stream().map(gurrantee -> {
return gurrantee.getGuarantee();
}).collect(Collectors.toList());
List<UUID> newGuranteeIds = newGuarantees.stream().map(gurrantee -> {
return gurrantee.getId();
}).collect(Collectors.toList());
return CollectionUtils.isEqualCollection(currentGuranteeIds, newGuranteeIds);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method copyGuarantees.
@Transactional
@Override
public void copyGuarantees(IdmContractSliceDto slice, IdmIdentityContractDto contract) {
Assert.notNull(slice, "Contract slice is required.");
Assert.notNull(slice.getId(), "Contract slice identifier is required.");
Assert.notNull(contract, "Contract is required.");
Assert.notNull(contract.getId(), "Contract identifier is required.");
IdmContractSliceGuaranteeFilter guaranteeFilter = new IdmContractSliceGuaranteeFilter();
guaranteeFilter.setContractSliceId(slice.getId());
List<IdmContractSliceGuaranteeDto> guarantees = contractSliceGuaranteeService.find(guaranteeFilter, null).getContent();
List<IdmContractGuaranteeDto> resultGuarantees = new ArrayList<>();
guarantees.forEach(guarantee -> {
IdmContractGuaranteeDto result = this.cloneGuarante(guarantee);
result.setIdentityContract(contract.getId());
resultGuarantees.add(result);
});
IdmContractGuaranteeFilter contractGuaranteeFilter = new IdmContractGuaranteeFilter();
contractGuaranteeFilter.setIdentityContractId(contract.getId());
List<IdmContractGuaranteeDto> currentGuarantees = contractGuaranteeService.find(contractGuaranteeFilter, null).getContent();
// Find and create new guarantees
resultGuarantees.stream().filter(guarantee -> {
//
return !//
currentGuarantees.stream().filter(//
cg -> guarantee.getGuarantee().equals(cg.getGuarantee())).findFirst().isPresent();
}).forEach(guaranteeToAdd -> {
ContractGuaranteeEvent event = new ContractGuaranteeEvent(contractGuaranteeService.isNew(guaranteeToAdd) ? ContractGuaranteeEventType.CREATE : ContractGuaranteeEventType.UPDATE, guaranteeToAdd, ImmutableMap.of(ContractSliceManager.SKIP_CHECK_FOR_SLICES, Boolean.TRUE));
contractGuaranteeService.publish(event);
});
// Find and remove guarantees which missing in the current result set
currentGuarantees.stream().filter(guarantee -> {
//
return !//
resultGuarantees.stream().filter(//
cg -> guarantee.getGuarantee().equals(cg.getGuarantee())).findFirst().isPresent();
}).forEach(guaranteeToRemove -> {
ContractGuaranteeEvent event = new ContractGuaranteeEvent(ContractGuaranteeEventType.DELETE, guaranteeToRemove, ImmutableMap.of(ContractSliceManager.SKIP_CHECK_FOR_SLICES, Boolean.TRUE));
contractGuaranteeService.publish(event);
});
}
Aggregations