use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method deleteSliceTest.
@Test
public void deleteSliceTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
IdmContractSliceFilter contractFilter = new IdmContractSliceFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmContractSliceDto> contractSlices = contractSliceService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractSlices.size());
// Find the account for this contract slice
IdmContractSliceDto slice = contractSlices.get(0);
AccContractSliceAccountFilter contractAccountFilter = new AccContractSliceAccountFilter();
contractAccountFilter.setSliceId(slice.getId());
contractAccountFilter.setSystemId(system.getId());
List<AccContractSliceAccountDto> contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(1, contractAccounts.size());
AccContractSliceAccountDto contractAccount = contractAccounts.get(0);
AccAccountDto account = accountService.get(contractAccount.getAccount());
Assert.assertNotNull(account);
// Delete this slice
contractSliceService.delete(slice);
contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
// Contract - account must be deleted
Assert.assertEquals(0, contractAccounts.size());
account = accountService.get(contractAccount.getAccount());
// Account must be deleted
Assert.assertNull(account);
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method addTwoNewAndDeleteFirstContractSliceTurnOffRecalc.
@Test
public void addTwoNewAndDeleteFirstContractSliceTurnOffRecalc() {
// init system
SysSystemDto system = initData();
this.getBean().deleteAllResourceData();
IdmIdentityDto identity = helper.createIdentity();
List<IdmIdentityContractDto> contracts = contractService.findAllByIdentity(identity.getId());
assertEquals(1, contracts.size());
contractService.delete(contracts.get(0));
// first valid slice
this.getBean().createSlice("1", identity.getUsername(), null, null, null, null, null, LocalDate.now().minusDays(20), null, LocalDate.now().minusDays(20), "ONE");
SysSyncContractConfigDto config = (SysSyncContractConfigDto) doCreateSyncConfig(system);
config.setStartOfHrProcesses(true);
config.setMissingAccountAction(ReconciliationMissingAccountActionType.DELETE_ENTITY);
config = (SysSyncContractConfigDto) syncConfigService.save(config);
// start sync (recalculation on)
helper.startSynchronization(config);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setIdentity(identity.getId());
List<IdmContractSliceDto> slices = contractSliceService.find(filter, null).getContent();
assertEquals(1, slices.size());
IdmContractSliceDto sliceDto = slices.get(0);
assertEquals(LocalDate.now().minusDays(20), sliceDto.getValidFrom());
assertEquals(null, sliceDto.getValidTill());
// create invalid slice
this.getBean().createSlice("2", identity.getUsername(), null, null, null, null, null, LocalDate.now().minusDays(20), LocalDate.now().minusDays(10), LocalDate.now().minusDays(10), "ONE");
// create valid slice
this.getBean().createSlice("3", identity.getUsername(), null, null, null, null, null, LocalDate.now().minusDays(10), null, LocalDate.now().minusDays(9), "ONE");
// delete first
this.getBean().deleteSlice("1");
// start sync (recalculation off)
config.setStartOfHrProcesses(false);
config = (SysSyncContractConfigDto) syncConfigService.save(config);
helper.startSynchronization(config);
slices = contractSliceService.find(filter, null).getContent();
assertEquals(3, slices.size());
for (IdmContractSliceDto slice : slices) {
if ("2".equals(slice.getDescription())) {
assertEquals(LocalDate.now().minusDays(10), slice.getValidFrom());
assertEquals(null, slice.getValidTill());
assertFalse(slice.isUsingAsContract());
assertNull(slice.getParentContract());
} else if ("3".equals(slice.getDescription())) {
assertEquals(LocalDate.now().minusDays(9), slice.getValidFrom());
assertEquals(null, slice.getValidTill());
assertFalse(slice.isUsingAsContract());
assertNull(slice.getParentContract());
} else if ("1".equals(slice.getDescription())) {
// Is not deleted yet
} else {
fail("Slice with bad id!");
}
}
contracts = contractService.findAllByIdentity(identity.getId());
assertEquals(1, contracts.size());
IdmIdentityContractDto contract = contracts.get(0);
assertEquals(LocalDate.now().minusDays(20), contract.getValidFrom());
assertEquals(null, contract.getValidTill());
// some tests expect data as contract slice with id 1. Just for sure we clear test slices
slices = contractSliceService.find(filter, null).getContent();
slices.forEach(slice -> {
contractSliceService.delete(slice);
});
identityService.delete(identity);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method deleteSliceAccountTest.
@Test
public void deleteSliceAccountTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
IdmContractSliceFilter contractFilter = new IdmContractSliceFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmContractSliceDto> contractSlices = contractSliceService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractSlices.size());
// Find the account for this contract slice
IdmContractSliceDto slice = contractSlices.get(0);
AccContractSliceAccountFilter contractAccountFilter = new AccContractSliceAccountFilter();
contractAccountFilter.setSliceId(slice.getId());
contractAccountFilter.setSystemId(system.getId());
List<AccContractSliceAccountDto> contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(1, contractAccounts.size());
AccContractSliceAccountDto contractAccount = contractAccounts.get(0);
AccAccountDto account = accountService.get(contractAccount.getAccount());
Assert.assertNotNull(account);
// Delete this account directly test
accountService.delete(account);
account = accountService.get(contractAccount.getAccount());
Assert.assertNull(account);
AccContractSliceAccountFilter contractSliceAccountFilter = new AccContractSliceAccountFilter();
contractSliceAccountFilter.setAccountId(contractAccount.getAccount());
Assert.assertEquals(0, contractSliceAccountService.find(contractSliceAccountFilter, null).getTotalElements());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method recalculateContractSlice.
@Override
public void recalculateContractSlice(IdmContractSliceDto slice, IdmContractSliceDto originalSlice, Map<String, Serializable> eventProperties) {
boolean forceRecalculateCurrentUsingSlice = false;
Object forceRecalculateCurrentUsingSliceAsObject = eventProperties.get(IdmContractSliceService.FORCE_RECALCULATE_CURRENT_USING_SLICE);
if (forceRecalculateCurrentUsingSliceAsObject == null) {
forceRecalculateCurrentUsingSlice = false;
} else if (forceRecalculateCurrentUsingSliceAsObject instanceof Boolean) {
forceRecalculateCurrentUsingSlice = (Boolean) forceRecalculateCurrentUsingSliceAsObject;
} else {
forceRecalculateCurrentUsingSlice = false;
}
boolean recalculateUsingAsContract = false;
if (slice.getIdentity() != null) {
UUID parentContract = slice.getParentContract();
// null (will be recalculated)
if (originalSlice != null && !Objects.equal(originalSlice.getContractCode(), slice.getContractCode())) {
slice.setParentContract(null);
// When external code changed, link or create new contract is required
parentContract = null;
}
if (originalSlice != null && !Objects.equal(originalSlice.getParentContract(), slice.getParentContract())) {
slice.setParentContract(null);
slice.setUsingAsContract(false);
}
if (parentContract == null) {
slice = linkOrCreateContract(slice, eventProperties);
} else {
// Update contract by that slice
if (slice.isUsingAsContract()) {
// Validity of slice was changed, slice cannot be using for update the contract
if (originalSlice != null && !Objects.equal(originalSlice.getValidFrom(), slice.getValidFrom())) {
recalculateUsingAsContract = true;
} else {
IdmIdentityContractDto contract = contractService.get(parentContract);
this.getBean().updateContractBySlice(contract, slice, eventProperties);
}
}
}
}
UUID parentContract = slice.getParentContract();
if (originalSlice == null) {
// Slice is new, we want to recalculate "Is using as contract" field.
recalculateUsingAsContract = true;
}
// Recalculate on change of 'parentContract' field
boolean parentContractChanged = false;
if (originalSlice != null && !Objects.equal(originalSlice.getParentContract(), slice.getParentContract())) {
UUID originalParentContract = originalSlice.getParentContract();
// Parent contract was changed ... we need recalculate parent contract for
// original slice
parentContractChanged = true;
if (originalParentContract != null) {
IdmIdentityContractDto originalContract = contractService.get(originalParentContract);
// Find other slices for original contract
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setParentContract(originalParentContract);
List<IdmContractSliceDto> originalSlices = contractSliceService.find(sliceFilter, null).getContent();
if (!originalSlices.isEmpty()) {
IdmContractSliceDto originalNextSlice = this.getBean().findNextSlice(originalSlice, originalSlices);
IdmContractSliceDto originalSliceToUpdate = originalNextSlice;
if (originalNextSlice != null) {
// Next slice exists, update valid-till on previous slice by that slice
IdmContractSliceDto originalPreviousSlice = this.getBean().findPreviousSlice(originalNextSlice, originalSlices);
if (originalPreviousSlice != null) {
originalPreviousSlice.setValidTill(originalNextSlice.getValidFrom().minusDays(1));
originalSliceToUpdate = originalPreviousSlice;
}
} else {
// Next slice does not exists. I means original slice was last. Set valid-till
// on previous slice to null.
IdmContractSliceDto originalPreviousSlice = this.getBean().findPreviousSlice(originalSlice, originalSlices);
if (originalPreviousSlice != null && this.getBean().findNextSlice(originalPreviousSlice, originalSlices) == null) {
originalPreviousSlice.setValidTill(null);
originalSliceToUpdate = originalPreviousSlice;
}
}
// Save with force recalculation
contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, originalSliceToUpdate, ImmutableMap.of(IdmContractSliceService.FORCE_RECALCULATE_CURRENT_USING_SLICE, Boolean.TRUE)));
} else {
// Parent contract was changed and old contract does not have next slice, we
// have to delete him.
// Delete contract
contractService.publish(new IdentityContractEvent(IdentityContractEventType.DELETE, originalContract, ImmutableMap.copyOf(eventProperties))).getContent();
}
}
// Parent contract was changed, want to recalculate "Is using as contract"
// field.
recalculateUsingAsContract = true;
}
// contract
if (originalSlice == null || parentContractChanged || (originalSlice != null && !Objects.equal(originalSlice.getValidFrom(), slice.getValidFrom()))) {
// slice
if (parentContract != null) {
// Find other slices for parent contract
List<IdmContractSliceDto> slices = this.getBean().findAllSlices(parentContract);
if (!slices.isEmpty()) {
// Update validity till on this slice and on previous slice
recalculateValidTill(slice, slices);
// original slice)
if (originalSlice != null) {
IdmContractSliceDto nextSliceForOriginalSlice = this.getBean().findNextSlice(originalSlice, slices);
if (nextSliceForOriginalSlice == null) {
// Next slice not exists, it means original slice was last
IdmContractSliceDto previousSliceForOriginalSlice = this.getBean().findPreviousSlice(originalSlice, slices);
if (previousSliceForOriginalSlice != null && this.getBean().findNextSlice(previousSliceForOriginalSlice, slices) == null) {
previousSliceForOriginalSlice.setValidTill(null);
// Save with skip this processor
saveWithoutRecalculate(previousSliceForOriginalSlice);
}
}
}
}
}
// Validity from was changed, want to recalculate "Is using as contract" field.
recalculateUsingAsContract = true;
}
if (recalculateUsingAsContract || forceRecalculateCurrentUsingSlice) {
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setParentContract(parentContract);
sliceFilter.setUsingAsContract(Boolean.TRUE);
IdmContractSliceDto shouldBeSetAsUsing = this.getBean().findValidSlice(parentContract);
if (shouldBeSetAsUsing != null) {
Map<String, Serializable> clonedProperties = new HashMap<>(eventProperties);
if (clonedProperties.containsKey(IdmContractSliceService.FORCE_RECALCULATE_CURRENT_USING_SLICE)) {
clonedProperties.remove(IdmContractSliceService.FORCE_RECALCULATE_CURRENT_USING_SLICE);
}
shouldBeSetAsUsing = this.getBean().setSliceAsCurrentlyUsing(shouldBeSetAsUsing, clonedProperties);
if (slice.equals(shouldBeSetAsUsing)) {
// If that slice should be using as contract, then we using returned instance
// (instead the reload slice from DB)
slice = shouldBeSetAsUsing;
}
}
}
// Check if is slice new or contract valid till field was changed.
if (originalSlice == null || (!Objects.equal(originalSlice.getContractValidTill(), slice.getContractValidTill()))) {
// If is slice last, then will be to slice valid till copy date of contract
// valid till
boolean isSliceLast = this.getBean().findNextSlice(slice, this.getBean().findAllSlices(parentContract)) == null ? true : false;
if (isSliceLast) {
slice.setValidTill(null);
saveWithoutRecalculate(slice);
}
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method findAllSlices.
@Override
@Transactional
public List<IdmContractSliceDto> findAllSlices(UUID parentContract) {
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setParentContract(parentContract);
List<IdmContractSliceDto> slices = contractSliceService.find(sliceFilter, null).getContent();
return slices;
}
Aggregations