use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method findValidSlice.
@Override
@Transactional
public IdmContractSliceDto findValidSlice(UUID contractId) {
Assert.notNull(contractId, "Contract is mandatory!");
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setShouldBeUsingAsContract(Boolean.TRUE);
sliceFilter.setParentContract(contractId);
// First try found valid slice
List<IdmContractSliceDto> validSlices = contractSliceService.find(sliceFilter, null).getContent();
if (!validSlices.isEmpty()) {
return validSlices.get(0);
}
// None valid slice exists, now we found all slices
sliceFilter.setShouldBeUsingAsContract(null);
List<IdmContractSliceDto> slices = contractSliceService.find(sliceFilter, null).getContent();
// We does not have any slices for this contract
if (slices.isEmpty()) {
return null;
}
LocalDate now = LocalDate.now();
// Try to find the nearest slice in future
IdmContractSliceDto resultSlice = slices.stream().filter(slice -> now.isBefore(slice.getValidFrom())).min(Comparator.comparing(IdmContractSliceDto::getValidFrom)).orElse(null);
if (resultSlice != null) {
return resultSlice;
}
return null;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method updateValidTillOnPreviousSlice.
@Override
@Transactional
public void updateValidTillOnPreviousSlice(IdmContractSliceDto slice, List<IdmContractSliceDto> slices) {
Assert.notNull(slice, "Contract slice cannot be null!");
Assert.notNull(slices, "Contract slices are required.");
if (slice.getValidFrom() == null) {
return;
}
IdmContractSliceDto previousSlice = this.findPreviousSlice(slice, slices);
if (previousSlice == null) {
return;
}
// Previous slice will be valid till starts of validity next slice
previousSlice.setValidTill(slice.getValidFrom().minusDays(1));
contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, previousSlice, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method setSliceAsCurrentlyUsing.
@Override
@Transactional
public IdmContractSliceDto setSliceAsCurrentlyUsing(IdmContractSliceDto slice, Map<String, Serializable> eventProperties) {
// contract)
if (slice.getParentContract() != null) {
// Find other slices with this contract and marked "is using as contract"
// (usually should be returned only one)
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setParentContract(slice.getParentContract());
sliceFilter.setUsingAsContract(Boolean.TRUE);
List<IdmContractSliceDto> otherSlices = contractSliceService.find(sliceFilter, null).getContent();
// To all this slices (exclude itself) set "using as contract" on false
//
otherSlices.stream().filter(//
s -> !s.equals(slice)).forEach(s -> {
//
s.setUsingAsContract(false);
// We want only save data, not update contract by slice
contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, s, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
});
}
slice.setUsingAsContract(true);
// attribute 'Is using as contract' to true.
if (eventProperties == null) {
return contractSliceService.save(slice);
}
return contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, slice, ImmutableMap.copyOf(eventProperties))).getContent();
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method recalculateValidTill.
/**
* Recalculate valid till on given slice and on previous slice
*
* @param slice
* @param slices
*/
private void recalculateValidTill(IdmContractSliceDto slice, List<IdmContractSliceDto> slices) {
this.getBean().updateValidTillOnPreviousSlice(slice, slices);
IdmContractSliceDto nextSlice = this.getBean().findNextSlice(slice, slices);
if (nextSlice != null) {
LocalDate validTill = nextSlice.getValidFrom().minusDays(1);
slice.setValidTill(validTill);
} else {
slice.setValidTill(null);
}
// Save with skip this processor
saveWithoutRecalculate(slice);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSynchronizationExecutor method doDeleteEntity.
/**
* Delete entity linked with given account
*
* @param account
* @param entityType
* @param log
* @param logItem
* @param actionLogs
*/
protected void doDeleteEntity(AccAccountDto account, SystemEntityType entityType, SysSyncLogDto log, SysSyncItemLogDto logItem, List<SysSyncActionLogDto> actionLogs) {
IdmContractSliceDto dto = this.getDtoByAccount(null, account);
if (dto == null) {
addToItemLog(logItem, MessageFormat.format("Warning! - Entity for account [{0}] was not found!", account.getUid()));
initSyncActionLog(SynchronizationActionType.DELETE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
return;
}
String entityIdentification = dto.getId().toString();
if (dto instanceof Codeable) {
entityIdentification = ((Codeable) dto).getCode();
}
logItem.setDisplayName(entityIdentification);
// Delete entity
// Set dirty state during recalculation, the process of recalculation will be
// solved in ClearDirtyStateForContractSliceTaskExecutor
// ClearDirtyStateForContractSliceTaskExecutor will be started with HR
// processes.
EntityEvent<IdmContractSliceDto> event = new ContractSliceEvent(ContractSliceEventType.DELETE, dto, ImmutableMap.of(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE));
// 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);
getService().publish(event);
}
Aggregations