use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method findSliceGuarantees.
@Transactional
@Override
public List<IdmContractSliceGuaranteeDto> findSliceGuarantees(UUID sliceId) {
Assert.notNull(sliceId, "Contract slice identifier is required.");
IdmContractSliceGuaranteeFilter guaranteeFilter = new IdmContractSliceGuaranteeFilter();
guaranteeFilter.setContractSliceId(sliceId);
return contractSliceGuaranteeService.find(guaranteeFilter, null).getContent();
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceDeleteProcessor method process.
@Override
public EventResult<IdmContractSliceDto> process(EntityEvent<IdmContractSliceDto> event) {
IdmContractSliceDto slice = event.getContent();
// delete. Deleting is provided by ClearDirtyStateForContractSliceTaskExecutor!
if (this.getBooleanProperty(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, event.getProperties())) {
// If is set slice as using as contract, set this flag to false
if (slice.isUsingAsContract()) {
slice.setUsingAsContract(false);
service.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, slice, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
}
Map<String, Serializable> properties = new HashMap<>(event.getProperties());
// Creates new dirty states, dirty states must be process by executor
createDeleteDirtyState(slice, properties);
LOG.info("Property SET_DIRTY_STATE_CONTRACT_SLICE is true -> Slice [{}] is not deleted but only marked as DIRTY." + " Deleting will be processed in ClearDirtyStateForContractSliceTaskExecutor!", slice.toString());
return new DefaultEventResult<>(event, this);
}
// delete dirty states for contract slice
findAllDirtyStatesForSlices(slice.getId()).forEach(dirtyState -> {
entityStateManager.deleteState(dirtyState);
});
// delete contract slice guarantees
IdmContractSliceGuaranteeFilter filter = new IdmContractSliceGuaranteeFilter();
filter.setContractSliceId(slice.getId());
contractGuaranteeService.find(filter, null).forEach(guarantee -> {
contractGuaranteeService.delete(guarantee);
});
UUID contractId = slice.getParentContract();
if (contractId != null) {
List<IdmContractSliceDto> slices = contractSliceManager.findAllSlices(contractId);
if (slices.size() == 1) {
// Internal delete of slice
service.deleteInternal(slice);
// This slice is last for parent contract. We will also deleted the parent
// contract;
contractService.deleteById(contractId);
return new DefaultEventResult<>(event, this);
}
// Find next slice
IdmContractSliceDto nextSlice = contractSliceManager.findNextSlice(slice, slices);
// Internal delete of slice
service.deleteInternal(slice);
// If exists next slice, then update valid till on previous slice
if (nextSlice != null) {
contractSliceManager.updateValidTillOnPreviousSlice(nextSlice, contractSliceManager.findAllSlices(contractId));
} else {
// If next slice doesn't exists, then we need to find previous slice (last after deleting) and set valid till to infinity.
IdmContractSliceDto previousSlice = contractSliceManager.findPreviousSlice(slice, contractSliceManager.findAllSlices(contractId));
if (previousSlice != null) {
// Previous slice will be valid till infinity
previousSlice.setValidTill(null);
contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, previousSlice, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
}
}
IdmContractSliceDto validSlice = contractSliceManager.findValidSlice(contractId);
if (validSlice != null) {
// Set next slice as is currently using in contract
contractSliceManager.setSliceAsCurrentlyUsing(validSlice, event.getProperties());
}
} else {
service.deleteInternal(slice);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter 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.filter.IdmContractSliceGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method testReferentialIntegrityOnContractDelete.
@Test
public void testReferentialIntegrityOnContractDelete() {
// 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.setGuaranteeId(identity.getId());
List<IdmContractSliceGuaranteeDto> guarantees = contractGuaranteeService.find(filter, null).getContent();
assertEquals(1, guarantees.size());
//
contractSliceService.deleteById(slice.getId());
//
guarantees = contractGuaranteeService.find(filter, null).getContent();
assertEquals(0, guarantees.size());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeSaveAndDeleteProcessorTest method testCreateGuaranteeOfContractWithSlice.
@Test
public void testCreateGuaranteeOfContractWithSlice() {
IdmIdentityDto sliceGuarantee = getHelper().createIdentity();
IdmIdentityDto identity = getHelper().createIdentity();
IdmContractSliceDto slice = getHelper().createContractSlice(identity, null, LocalDate.now().minusDays(1), null, null);
UUID contractId = slice.getParentContract();
// guarantee can't be created directly
try {
getHelper().createContractGuarantee(contractId, sliceGuarantee.getId());
fail("Contract guarantee can't be created directly when slice is applied");
} catch (ResultCodeException ex) {
Assert.assertTrue(CoreResultCode.CONTRACT_IS_CONTROLLED_GUARANTEE_CANNOT_BE_MODIFIED.toString().equals(ex.getError().getErrors().get(0).getStatusEnum()));
}
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contractId);
List<IdmContractGuaranteeDto> contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(0, contractGuarantees.size());
// contract slice guarantee can be created
getHelper().createContractSliceGuarantee(slice.getId(), sliceGuarantee.getId());
IdmContractSliceGuaranteeFilter sliceGuaranteefilter = new IdmContractSliceGuaranteeFilter();
sliceGuaranteefilter.setGuaranteeId(sliceGuarantee.getId());
List<IdmContractSliceGuaranteeDto> sliceGuarantees = contractSliceGuaranteeService.find(sliceGuaranteefilter, null).getContent();
Assert.assertEquals(1, sliceGuarantees.size());
// applying slice with guarantee causes creating of contract guarantee which is correct
contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(1, contractGuarantees.size());
IdmIdentityDto sliceGuaranteeIdent = DtoUtils.getEmbedded(sliceGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
IdmIdentityDto contractGuaranteeIdent = DtoUtils.getEmbedded(contractGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
Assert.assertEquals(sliceGuaranteeIdent.getId(), contractGuaranteeIdent.getId());
}
Aggregations