use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceGuaranteeRecountProcessor method process.
@Override
public EventResult<IdmContractSliceGuaranteeDto> process(EntityEvent<IdmContractSliceGuaranteeDto> event) {
IdmContractSliceGuaranteeDto dto = event.getContent();
Assert.notNull(dto.getContractSlice(), "Contract slice is required.");
IdmContractSliceDto slice = contractSliceService.get(dto.getContractSlice());
UUID parentContract = slice.getParentContract();
if (parentContract != null) {
IdmIdentityContractDto contract = contractService.get(parentContract);
// Copy guarantees to contract
if (slice.isUsingAsContract()) {
contractSliceManager.copyGuarantees(slice, contract);
}
}
//
event.setContent(dto);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method deleteSliceTest.
@Test
public void deleteSliceTest() {
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());
// Delete the current slice
contractSliceService.delete(contractSliceService.get(sliceCurrent.getId()));
slices = contractSliceManager.findAllSlices(parentContract);
assertEquals(2, slices.size());
validSlice = contractSliceManager.findValidSlice(parentContract);
// Valid slice should be slicePast now
assertEquals(slicePast, validSlice);
List<IdmContractSliceDto> unvalidSlices = contractSliceManager.findUnvalidSlices(null).getContent();
assertEquals(0, unvalidSlices.size());
// Reload the contract
contract = contractService.get(contract.getId());
assertTrue(contract.isValid());
assertEquals(slicePast.getContractValidFrom(), contract.getValidFrom());
assertEquals(slicePast.getContractValidTill(), contract.getValidTill());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method testReferentialIntegrityOnIdentityDelete.
@Test
public void testReferentialIntegrityOnIdentityDelete() {
// prepare data
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identityWithContract = helper.createIdentity();
IdmContractSliceDto slice = helper.createContractSlice(identityWithContract);
helper.createContractSliceGuarantee(slice.getId(), identity.getId());
//
IdmContractSliceGuaranteeFilter filter = new IdmContractSliceGuaranteeFilter();
filter.setContractSliceId(slice.getId());
List<IdmContractSliceGuaranteeDto> guarantees = contractGuaranteeService.find(filter, null).getContent();
assertEquals(1, guarantees.size());
//
helper.deleteIdentity(identity.getId());
//
guarantees = contractGuaranteeService.find(filter, null).getContent();
assertEquals(0, guarantees.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method contractValidityProtectionModeEnabledWithoutGapTest.
@Test
public void contractValidityProtectionModeEnabledWithoutGapTest() {
// Enable protection mode (4 days, gap is 0 days)
configurationService.setValue(ContractSliceConfiguration.PROPERTY_PROTECTION_INTERVAL, "4");
IdmIdentityDto identity = helper.createIdentity();
IdmContractSliceDto sliceOne = helper.createContractSlice(identity, "11", null, LocalDate.now().minusDays(100), LocalDate.now().minusDays(100), LocalDate.now().plusDays(5));
IdmContractSliceDto sliceTwo = helper.createContractSlice(identity, "11", null, LocalDate.now().plusDays(10), LocalDate.now().minusDays(100), LocalDate.now().plusDays(5));
assertNotNull(sliceOne.getParentContract());
assertNotNull(sliceTwo.getParentContract());
assertEquals(sliceOne.getParentContract(), sliceTwo.getParentContract());
assertTrue(sliceOne.isUsingAsContract());
assertFalse(sliceTwo.isUsingAsContract());
IdmIdentityContractDto contract = contractService.get(sliceOne.getParentContract());
// Protection mode is enabled, but gap was too small
assertEquals(sliceOne.getContractValidFrom(), contract.getValidFrom());
assertEquals(sliceOne.getContractValidTill(), contract.getValidTill());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method testDeleteEAVOnSlice.
@Test
public void testDeleteEAVOnSlice() {
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());
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.TEN.longValue(), ((BigDecimal) contractFormInstanceDto.getValues().get(0).getValue()).longValue());
formService.saveValues(slice, attribute, null);
// We need to save slice for invoke save slice to the contract
slice = contractSliceService.save(slice);
contractFormInstanceDto = formService.getFormInstance(contract);
Assert.assertNotNull(contractFormInstanceDto);
Assert.assertNotNull(contractFormInstanceDto.getFormDefinition());
Assert.assertEquals(0, contractFormInstanceDto.getValues().size());
}
Aggregations