use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method linkOrCreateContract.
/**
* Create or link contract from the slice or create relation on the exists
* contract
*
* @param slice
* @return
*/
private IdmContractSliceDto linkOrCreateContract(IdmContractSliceDto slice, Map<String, Serializable> eventProperties) {
String contractCode = slice.getContractCode();
if (Strings.isNullOrEmpty(contractCode)) {
// Create new parent contract
// When new contract is created, then this slice have to be sets as "Is using as
// contract"
slice.setUsingAsContract(true);
IdmIdentityContractDto contract = this.getBean().updateContractBySlice(new IdmIdentityContractDto(), slice, eventProperties);
slice.setParentContract(contract.getId());
return contractSliceService.saveInternal(slice);
} else {
// Find other slices
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setContractCode(contractCode);
sliceFilter.setIdentity(slice.getIdentity());
List<IdmContractSliceDto> slices = contractSliceService.find(sliceFilter, null).getContent();
// Find contract sets on others slices
UUID parentContractId = slices.stream().filter(//
s -> s.getParentContract() != null && !s.getId().equals(slice.getId())).findFirst().map(//
IdmContractSliceDto::getParentContract).orElse(//
null);
if (parentContractId == null) {
// Other slices does not have sets contract
// Create new parent contract
// When new contract is created, then this slice have to be sets as "Is using as
// contract"
slice.setUsingAsContract(true);
IdmIdentityContractDto contract = this.getBean().updateContractBySlice(new IdmIdentityContractDto(), slice, eventProperties);
slice.setParentContract(contract.getId());
return contractSliceService.saveInternal(slice);
} else {
// We found and link on existed contract. We have to do update this contract by
// slice.
slice.setParentContract(parentContractId);
IdmContractSliceDto sliceSaved = contractSliceService.saveInternal(slice);
// Update contract by that slice
if (sliceSaved.isUsingAsContract()) {
IdmIdentityContractDto contract = contractService.get(sliceSaved.getParentContract());
this.getBean().updateContractBySlice(contract, sliceSaved, eventProperties);
}
return sliceSaved;
}
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method findUnvalidSlices.
@Override
@Transactional
public Page<IdmContractSliceDto> findUnvalidSlices(Pageable page) {
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setShouldBeUsingAsContract(Boolean.TRUE);
sliceFilter.setUsingAsContract(Boolean.FALSE);
return contractSliceService.find(sliceFilter, page);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractService method toDto.
@Override
protected IdmIdentityContractDto toDto(IdmIdentityContract entity, IdmIdentityContractDto dto, IdmIdentityContractFilter context) {
IdmIdentityContractDto resultDto = super.toDto(entity, dto, context);
// Set attribute if that contract was created by slices
if (resultDto != null && resultDto.getId() != null && !resultDto.isTrimmed()) {
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setParentContract(resultDto.getId());
resultDto.setControlledBySlices(contractSliceService.count(sliceFilter) > 0);
}
return resultDto;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method identityFilterTest.
@Test
public void identityFilterTest() {
IdmIdentityDto identity = helper.createIdentity();
IdmTreeNodeDto node = helper.createTreeNode();
IdmTreeNodeDto node2 = helper.createTreeNode();
IdmContractSliceDto slice = helper.createContractSlice(identity, node, null, null, null);
IdmContractSliceDto slice2 = helper.createContractSlice(identity, node2, null, null, null);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setIdentity(identity.getId());
Page<IdmContractSliceDto> result = contractSliceService.find(filter, null);
assertEquals("Wrong Identity", 2, result.getTotalElements());
assertTrue(result.getContent().contains(slice));
assertTrue(result.getContent().contains(slice2));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method testCreateSliceWithEAVs.
@Test
public void testCreateSliceWithEAVs() {
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());
}
Aggregations