use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method externeFilterTest.
@Test
public void externeFilterTest() {
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identity2 = helper.createIdentity();
IdmTreeNodeDto node = helper.createTreeNode();
IdmTreeNodeDto node2 = helper.createTreeNode();
IdmContractSliceDto slice = helper.createContractSlice(identity, node, null, null, null);
IdmContractSliceDto slice2 = helper.createContractSlice(identity2, node2, null, null, null);
slice.setExterne(true);
contractSliceService.save(slice);
slice2.setExterne(false);
contractSliceService.save(slice2);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setExterne(true);
Page<IdmContractSliceDto> result = contractSliceService.find(filter, null);
assertTrue(result.getContent().contains(slice));
assertFalse(result.getContent().contains(slice2));
filter.setExterne(false);
result = contractSliceService.find(filter, null);
assertTrue(result.getContent().contains(slice2));
assertFalse(result.getContent().contains(slice));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method createSliceValidFromSameDateAsSomeExisting.
@Test
public void createSliceValidFromSameDateAsSomeExisting() {
IdmIdentityDto identity = helper.createIdentity();
String contractCode = "contract-three";
LocalDate now = LocalDate.now();
IdmContractSliceDto sliceCurrent = helper.createContractSlice(identity, contractCode, null, now, now, now.plusDays(200));
IdmContractSliceDto sliceCurrentNew = helper.createContractSlice(identity, contractCode, null, now, now, now.plusDays(50));
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setIdentity(identity.getId());
List<IdmContractSliceDto> results = contractSliceService.find(filter, null).getContent();
assertEquals(2, results.size());
UUID parentContract = results.get(0).getParentContract();
List<IdmContractSliceDto> slices = contractSliceManager.findAllSlices(parentContract);
assertEquals(2, slices.size());
IdmContractSliceDto validSlice = contractSliceManager.findValidSlice(parentContract);
// Valid slice should be currentSliceNew
assertEquals(sliceCurrentNew, validSlice);
IdmContractSliceDto previousSlice = contractSliceManager.findPreviousSlice(validSlice, slices);
// Previous slice should be sliceCurrent with longer validity
assertEquals(sliceCurrent, previousSlice);
assertNotNull(previousSlice.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());
// Current slice should be contract
IdmIdentityContractDto contract = resultsContract.get(0);
assertTrue(contract.isValid());
assertEquals(sliceCurrentNew.getContractValidFrom(), contract.getValidFrom());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method createSliceValidInPastTest.
@Test
public void createSliceValidInPastTest() {
IdmIdentityDto identity = helper.createIdentity();
String contractCode = "contract-one";
IdmContractSliceDto slice = helper.createContractSlice(identity, null, LocalDate.now().minusDays(10), null, LocalDate.now().minusDays(5));
slice.setContractCode(contractCode);
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());
assertFalse(contract.isValidNowOrInFuture());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method mainFilterTest.
@Test
public void mainFilterTest() {
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identity2 = helper.createIdentity();
IdmTreeNodeDto node = helper.createTreeNode();
IdmTreeNodeDto node2 = helper.createTreeNode();
IdmContractSliceDto slice = helper.createContractSlice(identity, node, null, null, null);
IdmContractSliceDto slice2 = helper.createContractSlice(identity2, node2, null, null, null);
slice.setMain(true);
contractSliceService.save(slice);
slice2.setMain(false);
contractSliceService.save(slice2);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setMain(true);
Page<IdmContractSliceDto> result = contractSliceService.find(filter, null);
assertTrue(result.getContent().contains(slice));
assertFalse(result.getContent().contains(slice2));
filter.setMain(false);
result = contractSliceService.find(filter, null);
assertTrue(result.getContent().contains(slice2));
assertFalse(result.getContent().contains(slice));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method createSlicesForOneContractTest.
@Test
public void createSlicesForOneContractTest() {
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);
IdmContractSliceDto nextSlice = contractSliceManager.findNextSlice(validSlice, slices);
// Next slice should be futureSlice
assertEquals(sliceFuture, nextSlice);
IdmContractSliceDto previousSlice = contractSliceManager.findPreviousSlice(validSlice, slices);
// Previous slice should be pasSlice
assertEquals(slicePast, previousSlice);
List<IdmContractSliceDto> unvalidSlices = contractSliceManager.findUnvalidSlices(null).getContent();
assertEquals(0, unvalidSlices.size());
// 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());
}
Aggregations