use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class IdentityContractDeleteProcessor method process.
@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
IdmIdentityContractDto contract = event.getContent();
//
// delete referenced roles
identityRoleService.findAllByContract(contract.getId()).forEach(identityRole -> {
identityRoleService.delete(identityRole);
});
// Find all concepts and remove relation on role
IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
conceptRequestFilter.setIdentityContractId(contract.getId());
conceptRequestService.find(conceptRequestFilter, null).getContent().forEach(concept -> {
IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
String message = null;
if (concept.getState().isTerminatedState()) {
message = MessageFormat.format("IdentityContract [{0}] (requested in concept [{1}]) was deleted (not from this role request)!", contract.getId(), concept.getId());
} else {
message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested IdentityContract [{1}] was deleted (not from this role request)!", concept.getId(), contract.getId());
concept.setState(RoleRequestState.CANCELED);
}
roleRequestService.addToLog(request, message);
conceptRequestService.addToLog(concept, message);
concept.setIdentityContract(null);
roleRequestService.save(request);
conceptRequestService.save(concept);
});
// delete contract guarantees
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setIdentityContractId(contract.getId());
contractGuaranteeService.find(filter, null).forEach(guarantee -> {
contractGuaranteeService.delete(guarantee);
});
// delete identity contract
service.deleteInternal(contract);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testReferentialIntegrityOnIdentityDelete.
@Test
public void testReferentialIntegrityOnIdentityDelete() {
// prepare data
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identityWithContract = helper.createIdentity();
IdmIdentityContractDto contract = helper.createIdentityContact(identityWithContract);
helper.createContractGuarantee(contract.getId(), identity.getId());
//
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setIdentityContractId(contract.getId());
List<IdmContractGuaranteeDto> 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.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testReferentialIntegrityOnContractDelete.
@Test
public void testReferentialIntegrityOnContractDelete() {
// prepare data
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identityWithContract = helper.createIdentity();
IdmIdentityContractDto contract = helper.createIdentityContact(identityWithContract);
helper.createContractGuarantee(contract.getId(), identity.getId());
//
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setGuaranteeId(identity.getId());
List<IdmContractGuaranteeDto> guarantees = contractGuaranteeService.find(filter, null).getContent();
assertEquals(1, guarantees.size());
//
helper.deleteIdentityContact(contract.getId());
//
guarantees = contractGuaranteeService.find(filter, null).getContent();
assertEquals(0, guarantees.size());
}
Aggregations