Search in sources :

Example 6 with IdmContractSliceGuaranteeFilter

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();
}
Also used : IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with IdmContractSliceGuaranteeFilter

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);
}
Also used : ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) Serializable(java.io.Serializable) HashMap(java.util.HashMap) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) UUID(java.util.UUID) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)

Example 8 with IdmContractSliceGuaranteeFilter

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());
}
Also used : IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 9 with IdmContractSliceGuaranteeFilter

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());
}
Also used : IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 10 with IdmContractSliceGuaranteeFilter

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());
}
Also used : IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmContractSliceGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter)10 IdmContractSliceDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)8 IdmContractSliceGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 UUID (java.util.UUID)7 Serializable (java.io.Serializable)5 IdmContractGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter)4 IdmContractSliceFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter)4 ContractSliceEvent (eu.bcvsolutions.idm.core.model.event.ContractSliceEvent)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)3 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)3 AutomaticRoleManager (eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager)3 ContractSliceManager (eu.bcvsolutions.idm.core.api.service.ContractSliceManager)3 IdmContractSliceGuaranteeService (eu.bcvsolutions.idm.core.api.service.IdmContractSliceGuaranteeService)3 IdmContractSliceService (eu.bcvsolutions.idm.core.api.service.IdmContractSliceService)3 IdmIdentityContractService (eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService)3 ContractSliceEventType (eu.bcvsolutions.idm.core.model.event.ContractSliceEvent.ContractSliceEventType)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 MessageFormat (java.text.MessageFormat)3