use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method selectCurrentSliceAsContractLrtTest.
@Test
public void selectCurrentSliceAsContractLrtTest() {
IdmIdentityDto identity = helper.createIdentity();
String contractCode = "contract-one";
IdmContractSliceDto sliceFuture = helper.createContractSlice(identity, null, LocalDate.now().plusDays(10), null, LocalDate.now().plusDays(100));
sliceFuture.setContractCode(contractCode);
contractSliceService.save(sliceFuture);
IdmContractSliceDto sliceCurrent = helper.createContractSlice(identity, null, LocalDate.now(), null, LocalDate.now().plusDays(50));
sliceCurrent.setContractCode(contractCode);
contractSliceService.save(sliceCurrent);
IdmContractSliceDto slicePast = helper.createContractSlice(identity, null, LocalDate.now().minusDays(10), null, LocalDate.now().plusDays(200));
slicePast.setContractCode(contractCode);
contractSliceService.save(slicePast);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setIdentity(identity.getId());
List<IdmContractSliceDto> results = contractSliceService.find(filter, null).getContent();
assertEquals(3, results.size());
UUID parentContract = results.get(0).getParentContract();
List<IdmContractSliceDto> slices = contractSliceManager.findAllSlices(parentContract);
assertEquals(3, slices.size());
IdmContractSliceDto validSlice = contractSliceManager.findValidSlice(parentContract);
// Valid slice should be currentSlice
assertEquals(sliceCurrent, validSlice);
// Check created contract by that slice
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(identity.getId());
List<IdmIdentityContractDto> resultsContract = //
contractService.find(filter, null).getContent().stream().filter(//
c -> contractService.get(c.getId()).getControlledBySlices()).collect(Collectors.toList());
assertEquals(1, resultsContract.size());
// Current slice should be contract
IdmIdentityContractDto contract = resultsContract.get(0);
assertTrue(contract.isValid());
assertEquals(sliceCurrent.getContractValidFrom(), contract.getValidFrom());
// None invalid slices
List<IdmContractSliceDto> unvalidSlices = contractSliceManager.findUnvalidSlices(null).getContent();
assertEquals(0, unvalidSlices.size());
// Set current slice as not currently using
sliceCurrent = contractSliceService.get(sliceCurrent.getId());
sliceCurrent.setUsingAsContract(false);
// Save without recalculation
contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, sliceCurrent, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
// One invalid slice
unvalidSlices = contractSliceManager.findUnvalidSlices(null).getContent();
assertEquals(1, unvalidSlices.size());
SelectCurrentContractSliceTaskExecutor lrt = new SelectCurrentContractSliceTaskExecutor();
AutowireHelper.autowire(lrt);
OperationResult result = lrt.process();
assertEquals(OperationState.EXECUTED, result.getState());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method changeSlicesForTwoContractTest.
@Test
public void changeSlicesForTwoContractTest() {
IdmIdentityDto identity = helper.createIdentity();
String contractCodeOne = "contract-one";
String contractCodeTwo = "contract-two";
IdmContractSliceDto sliceFuture = helper.createContractSlice(identity, null, LocalDate.now().plusDays(10), null, LocalDate.now().plusDays(100));
sliceFuture.setContractCode(contractCodeOne);
contractSliceService.save(sliceFuture);
IdmContractSliceDto sliceCurrentTwo = helper.createContractSlice(identity, null, LocalDate.now(), null, LocalDate.now().plusDays(50));
sliceCurrentTwo.setContractCode(contractCodeTwo);
contractSliceService.save(sliceCurrentTwo);
IdmContractSliceDto slicePastTwo = helper.createContractSlice(identity, null, LocalDate.now().minusDays(10), null, LocalDate.now().plusDays(200));
slicePastTwo.setContractCode(contractCodeTwo);
contractSliceService.save(slicePastTwo);
IdmContractSliceDto slicePast = helper.createContractSlice(identity, null, LocalDate.now().minusDays(10), null, LocalDate.now().plusDays(200));
slicePast.setContractCode(contractCodeOne);
contractSliceService.save(slicePast);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setIdentity(identity.getId());
List<IdmContractSliceDto> results = contractSliceService.find(filter, null).getContent();
assertEquals(4, results.size());
// Get contract for contractCodeOne
UUID parentContractOne = results.stream().filter(s -> s.getContractCode().equals(contractCodeOne)).findFirst().get().getParentContract();
List<IdmContractSliceDto> slices = contractSliceManager.findAllSlices(parentContractOne);
assertEquals(2, slices.size());
IdmContractSliceDto validSlice = contractSliceManager.findValidSlice(parentContractOne);
// Valid slice should be slicePast now
assertEquals(slicePast, validSlice);
IdmContractSliceDto nextSlice = contractSliceManager.findNextSlice(validSlice, slices);
// Next slice should be futureSlice
assertEquals(sliceFuture, nextSlice);
IdmContractSliceDto previousSlice = contractSliceManager.findPreviousSlice(validSlice, slices);
// Previous slice should be null
assertNull(previousSlice);
List<IdmContractSliceDto> unvalidSlices = contractSliceManager.findUnvalidSlices(null).getContent();
assertEquals(0, unvalidSlices.size());
// Get contract for contractCodeTwo
UUID parentContractTwo = results.stream().filter(s -> s.getContractCode().equals(contractCodeTwo)).findFirst().get().getParentContract();
List<IdmContractSliceDto> slicesTwo = contractSliceManager.findAllSlices(parentContractTwo);
assertEquals(2, slicesTwo.size());
IdmContractSliceDto validSliceTwo = contractSliceManager.findValidSlice(parentContractTwo);
// Valid slice should be sliceCurrentTwo now
assertEquals(sliceCurrentTwo, validSliceTwo);
// Check created contract by that slice
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(identity.getId());
List<IdmIdentityContractDto> resultsContract = //
contractService.find(filter, null).getContent().stream().filter(//
c -> contractService.get(c.getId()).getControlledBySlices()).collect(Collectors.toList());
// Two contract controlled by slices must exists now
assertEquals(2, resultsContract.size());
// Past slice should be contract
IdmIdentityContractDto contract = resultsContract.stream().filter(c -> c.getId().equals(parentContractOne)).findFirst().get();
assertTrue(contract.isValid());
assertEquals(slicePast.getContractValidFrom(), contract.getValidFrom());
// Change parent contract from Two to One
sliceCurrentTwo.setContractCode(contractCodeOne);
contractSliceService.save(sliceCurrentTwo);
// Check slice for contractCodeTwo
slicesTwo = contractSliceManager.findAllSlices(parentContractTwo);
assertEquals(1, slicesTwo.size());
validSliceTwo = contractSliceManager.findValidSlice(parentContractTwo);
// Valid slice should be sliceCurrentTwo now
assertEquals(slicePastTwo, validSliceTwo);
assertTrue(validSliceTwo.isUsingAsContract());
// Check slice for contractCodeOne
slices = contractSliceManager.findAllSlices(parentContractOne);
assertEquals(3, slices.size());
validSlice = contractSliceManager.findValidSlice(parentContractOne);
// Valid slice should be currentSliceTwo now
assertEquals(sliceCurrentTwo, validSlice);
nextSlice = contractSliceManager.findNextSlice(validSlice, slices);
// Next slice should be futureSlice
assertEquals(sliceFuture, nextSlice);
previousSlice = contractSliceManager.findPreviousSlice(validSlice, slices);
// Previous slice should be pastSlice
assertEquals(slicePast, previousSlice);
unvalidSlices = contractSliceManager.findUnvalidSlices(null).getContent();
assertEquals(0, unvalidSlices.size());
// Check created contract by that slice
resultsContract = //
contractService.find(filter, null).getContent().stream().filter(//
c -> contractService.get(c.getId()).getControlledBySlices()).collect(Collectors.toList());
assertEquals(2, resultsContract.size());
// Change parent contract from Two to One (slicePastTwo)
slicePastTwo.setContractCode(contractCodeOne);
contractSliceService.save(slicePastTwo);
// Contract TWO was deleted
resultsContract = //
contractService.find(filter, null).getContent().stream().filter(//
c -> contractService.get(c.getId()).getControlledBySlices()).collect(Collectors.toList());
assertEquals(1, resultsContract.size());
// Past slice should be contract
contract = resultsContract.get(0);
assertTrue(contract.isValid());
assertEquals(sliceCurrentTwo.getContractValidFrom(), contract.getValidFrom());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method testModifiedEAVOnSlice.
@Test
public void testModifiedEAVOnSlice() {
IdmIdentityDto identity = helper.createIdentity();
String contractCode = "contract-one";
IdmContractSliceDto slice = helper.createContractSlice(identity, null, null, null, null);
slice.setContractCode(contractCode);
slice = contractSliceService.save(slice);
// Init form definition for identity-contract
IdmFormDefinitionDto definition = this.initIdentityContractFormDefinition();
// Create slice with EAV values
IdmFormInstanceDto formInstanceDto = formService.getFormInstance(slice, definition);
Assert.assertNotNull(formInstanceDto);
Assert.assertNotNull(formInstanceDto.getFormDefinition());
Assert.assertEquals(0, formInstanceDto.getValues().size());
IdmFormAttributeDto attribute = formInstanceDto.getMappedAttributeByCode(NUMBER_OF_FINGERS);
formService.saveValues(slice, attribute, Lists.newArrayList(BigDecimal.TEN));
// We need to save slice for invoke save slice to the contract
slice = contractSliceService.save(slice);
formInstanceDto = formService.getFormInstance(slice, definition);
Assert.assertNotNull(formInstanceDto);
Assert.assertNotNull(formInstanceDto.getFormDefinition());
Assert.assertEquals(1, formInstanceDto.getValues().size());
Assert.assertEquals(BigDecimal.TEN.longValue(), ((BigDecimal) formInstanceDto.getValues().get(0).getValue()).longValue());
formService.saveValues(slice, attribute, Lists.newArrayList(BigDecimal.ONE));
// We need to save slice for invoke save slice to the contract
slice = contractSliceService.save(slice);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setIdentity(identity.getId());
List<IdmContractSliceDto> results = contractSliceService.find(filter, null).getContent();
assertEquals(1, results.size());
IdmContractSliceDto createdSlice = results.get(0);
assertTrue(createdSlice.isValid());
assertEquals(null, createdSlice.getValidTill());
// Check created contract by that slice
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(identity.getId());
List<IdmIdentityContractDto> resultsContract = //
contractService.find(filter, null).getContent().stream().filter(//
c -> contractService.get(c.getId()).getControlledBySlices()).collect(Collectors.toList());
//
assertEquals(1, resultsContract.size());
IdmIdentityContractDto contract = resultsContract.get(0);
assertEquals(slice.getContractValidFrom(), contract.getValidFrom());
assertEquals(slice.getContractValidTill(), contract.getValidTill());
assertTrue(contract.isValidNowOrInFuture());
IdmFormInstanceDto contractFormInstanceDto = formService.getFormInstance(contract);
Assert.assertNotNull(contractFormInstanceDto);
Assert.assertNotNull(contractFormInstanceDto.getFormDefinition());
Assert.assertEquals(1, contractFormInstanceDto.getValues().size());
Assert.assertEquals(BigDecimal.ONE.longValue(), ((BigDecimal) contractFormInstanceDto.getValues().get(0).getValue()).longValue());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method changeContractBySliceTest.
@Test
public void changeContractBySliceTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
IdmIdentityDto owner = helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_LEADER_ONE);
IdmContractSliceFilter contractSliceFilter = new IdmContractSliceFilter();
contractSliceFilter.setProperty(IdmIdentityContract_.position.getName());
contractSliceFilter.setValue("1");
Assert.assertEquals(0, contractSliceService.find(contractSliceFilter, null).getTotalElements());
contractSliceFilter.setValue("2");
Assert.assertEquals(0, contractSliceService.find(contractSliceFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractSliceFilter.setValue("1");
Assert.assertEquals(1, contractSliceService.find(contractSliceFilter, null).getTotalElements());
contractSliceFilter.setValue("2");
List<IdmContractSliceDto> slicesTwo = contractSliceService.find(contractSliceFilter, null).getContent();
Assert.assertEquals(1, slicesTwo.size());
contractSliceFilter.setValue("3");
List<IdmContractSliceDto> contractsThree = contractSliceService.find(contractSliceFilter, null).getContent();
Assert.assertEquals(1, contractsThree.size());
Assert.assertEquals(null, contractsThree.get(0).getState());
contractSliceFilter.setValue("4");
Assert.assertEquals(1, contractSliceService.find(contractSliceFilter, null).getTotalElements());
// Find created contract
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(owner.getId());
List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(3, contracts.size());
// Slice with id "2" should be current using
Assert.assertEquals(1, contracts.stream().filter(c -> c.getPosition().equals("2") && c.isValid()).count());
Assert.assertTrue(slicesTwo.get(0).isUsingAsContract());
// Delete log
syncLogService.delete(log);
// Slice with id "2" reassign from contract ONE to TWO
this.getBean().changeContractData();
helper.startSynchronization(config);
log = checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Find created contract
contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(owner.getId());
contracts = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(3, contracts.size());
// Slice with id "2" should not be current used
Assert.assertEquals(0, contracts.stream().filter(c -> c.getPosition().equals("2") && c.isValid()).count());
// But slice with id "4" should be current used
Assert.assertEquals(1, contracts.stream().filter(c -> c.getPosition().equals("4") && c.isValid()).count());
Assert.assertTrue(slicesTwo.get(0).isUsingAsContract());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter 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);
}
Aggregations