Search in sources :

Example 6 with ContractSliceEvent

use of eu.bcvsolutions.idm.core.model.event.ContractSliceEvent in project CzechIdMng by bcvsolutions.

the class ContractSliceManagerTest method setDirtyStateAndReferentialIntegrityTest.

@Test
public void setDirtyStateAndReferentialIntegrityTest() {
    IdmIdentityDto identity = this.getHelper().createIdentity();
    // remove all contracts
    List<IdmIdentityContractDto> allByIdentity = contractService.findAllByIdentity(identity.getId());
    allByIdentity.forEach(contract -> {
        contractService.delete(contract);
    });
    IdmContractSliceDto slice = new IdmContractSliceDto();
    slice.setContractCode("test");
    slice.setIdentity(identity.getId());
    slice.setValidFrom(LocalDate.now().minusDays(5));
    slice.setValidTill(LocalDate.now().plusDays(5));
    slice.setContractValidFrom(LocalDate.now().minusDays(5));
    slice.setMain(true);
    EventContext<IdmContractSliceDto> context = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, slice, ImmutableMap.of(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE)));
    IdmContractSliceDto sliceDto = context.getContent();
    // slice has skip recalculation and dirty state isn't create
    allByIdentity = contractService.findAllByIdentity(identity.getId());
    assertTrue(allByIdentity.isEmpty());
    List<IdmEntityStateDto> dirtyStates = findDirtyStatesForSlice(sliceDto.getId());
    assertFalse(dirtyStates.isEmpty());
    assertEquals(1, dirtyStates.size());
    contractSliceService.delete(sliceDto);
    dirtyStates = findDirtyStatesForSlice(sliceDto.getId());
    assertTrue(dirtyStates.isEmpty());
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 7 with ContractSliceEvent

use of eu.bcvsolutions.idm.core.model.event.ContractSliceEvent 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 ContractSliceEvent

use of eu.bcvsolutions.idm.core.model.event.ContractSliceEvent in project CzechIdMng by bcvsolutions.

the class ContractSliceManagerTest method selectCurrentSliceAsContractLrtTest.

@Test
public void selectCurrentSliceAsContractLrtTest() {
    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());
    // None invalid slices
    List<IdmContractSliceDto> unvalidSlices = contractSliceManager.findUnvalidSlices(null).getContent();
    assertEquals(0, unvalidSlices.size());
    // Set current slice as not currently using
    sliceCurrent = contractSliceService.get(sliceCurrent.getId());
    sliceCurrent.setUsingAsContract(false);
    // Save without recalculation
    contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, sliceCurrent, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
    // One invalid slice
    unvalidSlices = contractSliceManager.findUnvalidSlices(null).getContent();
    assertEquals(1, unvalidSlices.size());
    SelectCurrentContractSliceTaskExecutor lrt = new SelectCurrentContractSliceTaskExecutor();
    AutowireHelper.autowire(lrt);
    OperationResult result = lrt.process();
    assertEquals(OperationState.EXECUTED, result.getState());
}
Also used : IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) ContractSliceEventType(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent.ContractSliceEventType) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ClearDirtyStateForContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) BigDecimal(java.math.BigDecimal) Map(java.util.Map) After(org.junit.After) ContractSliceConfiguration(eu.bcvsolutions.idm.core.api.config.domain.ContractSliceConfiguration) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ImmutableMap(com.google.common.collect.ImmutableMap) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) SelectCurrentContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.SelectCurrentContractSliceTaskExecutor) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmContractSliceService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceService) HashMap(java.util.HashMap) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) Lists(com.google.common.collect.Lists) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmContractSliceGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceGuaranteeService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmLongRunningTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmLongRunningTaskService) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) IdmContractSlice(eu.bcvsolutions.idm.core.model.entity.IdmContractSlice) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Assert.assertNull(org.junit.Assert.assertNull) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) ContractSliceManager(eu.bcvsolutions.idm.core.api.service.ContractSliceManager) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) SelectCurrentContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.SelectCurrentContractSliceTaskExecutor) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 9 with ContractSliceEvent

use of eu.bcvsolutions.idm.core.model.event.ContractSliceEvent in project CzechIdMng by bcvsolutions.

the class ContractSliceManagerTest method setDirtyStateTest.

@Test
public void setDirtyStateTest() {
    IdmIdentityDto identity = this.getHelper().createIdentity();
    // remove all contracts
    List<IdmIdentityContractDto> allByIdentity = contractService.findAllByIdentity(identity.getId());
    allByIdentity.forEach(contract -> {
        contractService.delete(contract);
    });
    IdmContractSliceDto slice = new IdmContractSliceDto();
    slice.setContractCode("test");
    slice.setIdentity(identity.getId());
    slice.setValidFrom(LocalDate.now().minusDays(5));
    slice.setValidTill(LocalDate.now().plusDays(5));
    slice.setContractValidFrom(LocalDate.now().minusDays(5));
    slice.setMain(true);
    EventContext<IdmContractSliceDto> eventContext = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, slice, ImmutableMap.of(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE)));
    // slice has skip recalculation and dirty state isn't create
    allByIdentity = contractService.findAllByIdentity(identity.getId());
    assertTrue(allByIdentity.isEmpty());
    List<IdmEntityStateDto> dirtyStates = findDirtyStatesForSlice(null);
    assertFalse(dirtyStates.isEmpty());
    assertEquals(1, dirtyStates.size());
    // delete the states
    entityStateManager.deleteState(dirtyStates.get(0));
    // Delete unused slice
    contractSliceService.delete(eventContext.getContent());
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 10 with ContractSliceEvent

use of eu.bcvsolutions.idm.core.model.event.ContractSliceEvent in project CzechIdMng by bcvsolutions.

the class DefaultContractSliceManager method recalculateContractSlice.

@Override
public void recalculateContractSlice(IdmContractSliceDto slice, IdmContractSliceDto originalSlice, Map<String, Serializable> eventProperties) {
    boolean forceRecalculateCurrentUsingSlice = false;
    Object forceRecalculateCurrentUsingSliceAsObject = eventProperties.get(IdmContractSliceService.FORCE_RECALCULATE_CURRENT_USING_SLICE);
    if (forceRecalculateCurrentUsingSliceAsObject == null) {
        forceRecalculateCurrentUsingSlice = false;
    } else if (forceRecalculateCurrentUsingSliceAsObject instanceof Boolean) {
        forceRecalculateCurrentUsingSlice = (Boolean) forceRecalculateCurrentUsingSliceAsObject;
    } else {
        forceRecalculateCurrentUsingSlice = false;
    }
    boolean recalculateUsingAsContract = false;
    if (slice.getIdentity() != null) {
        UUID parentContract = slice.getParentContract();
        // null (will be recalculated)
        if (originalSlice != null && !Objects.equal(originalSlice.getContractCode(), slice.getContractCode())) {
            slice.setParentContract(null);
            // When external code changed, link or create new contract is required
            parentContract = null;
        }
        if (originalSlice != null && !Objects.equal(originalSlice.getParentContract(), slice.getParentContract())) {
            slice.setParentContract(null);
            slice.setUsingAsContract(false);
        }
        if (parentContract == null) {
            slice = linkOrCreateContract(slice, eventProperties);
        } else {
            // Update contract by that slice
            if (slice.isUsingAsContract()) {
                // Validity of slice was changed, slice cannot be using for update the contract
                if (originalSlice != null && !Objects.equal(originalSlice.getValidFrom(), slice.getValidFrom())) {
                    recalculateUsingAsContract = true;
                } else {
                    IdmIdentityContractDto contract = contractService.get(parentContract);
                    this.getBean().updateContractBySlice(contract, slice, eventProperties);
                }
            }
        }
    }
    UUID parentContract = slice.getParentContract();
    if (originalSlice == null) {
        // Slice is new, we want to recalculate "Is using as contract" field.
        recalculateUsingAsContract = true;
    }
    // Recalculate on change of 'parentContract' field
    boolean parentContractChanged = false;
    if (originalSlice != null && !Objects.equal(originalSlice.getParentContract(), slice.getParentContract())) {
        UUID originalParentContract = originalSlice.getParentContract();
        // Parent contract was changed ... we need recalculate parent contract for
        // original slice
        parentContractChanged = true;
        if (originalParentContract != null) {
            IdmIdentityContractDto originalContract = contractService.get(originalParentContract);
            // Find other slices for original contract
            IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
            sliceFilter.setParentContract(originalParentContract);
            List<IdmContractSliceDto> originalSlices = contractSliceService.find(sliceFilter, null).getContent();
            if (!originalSlices.isEmpty()) {
                IdmContractSliceDto originalNextSlice = this.getBean().findNextSlice(originalSlice, originalSlices);
                IdmContractSliceDto originalSliceToUpdate = originalNextSlice;
                if (originalNextSlice != null) {
                    // Next slice exists, update valid-till on previous slice by that slice
                    IdmContractSliceDto originalPreviousSlice = this.getBean().findPreviousSlice(originalNextSlice, originalSlices);
                    if (originalPreviousSlice != null) {
                        originalPreviousSlice.setValidTill(originalNextSlice.getValidFrom().minusDays(1));
                        originalSliceToUpdate = originalPreviousSlice;
                    }
                } else {
                    // Next slice does not exists. I means original slice was last. Set valid-till
                    // on previous slice to null.
                    IdmContractSliceDto originalPreviousSlice = this.getBean().findPreviousSlice(originalSlice, originalSlices);
                    if (originalPreviousSlice != null && this.getBean().findNextSlice(originalPreviousSlice, originalSlices) == null) {
                        originalPreviousSlice.setValidTill(null);
                        originalSliceToUpdate = originalPreviousSlice;
                    }
                }
                // Save with force recalculation
                contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, originalSliceToUpdate, ImmutableMap.of(IdmContractSliceService.FORCE_RECALCULATE_CURRENT_USING_SLICE, Boolean.TRUE)));
            } else {
                // Parent contract was changed and old contract does not have next slice, we
                // have to delete him.
                // Delete contract
                contractService.publish(new IdentityContractEvent(IdentityContractEventType.DELETE, originalContract, ImmutableMap.copyOf(eventProperties))).getContent();
            }
        }
        // Parent contract was changed, want to recalculate "Is using as contract"
        // field.
        recalculateUsingAsContract = true;
    }
    // contract
    if (originalSlice == null || parentContractChanged || (originalSlice != null && !Objects.equal(originalSlice.getValidFrom(), slice.getValidFrom()))) {
        // slice
        if (parentContract != null) {
            // Find other slices for parent contract
            List<IdmContractSliceDto> slices = this.getBean().findAllSlices(parentContract);
            if (!slices.isEmpty()) {
                // Update validity till on this slice and on previous slice
                recalculateValidTill(slice, slices);
                // original slice)
                if (originalSlice != null) {
                    IdmContractSliceDto nextSliceForOriginalSlice = this.getBean().findNextSlice(originalSlice, slices);
                    if (nextSliceForOriginalSlice == null) {
                        // Next slice not exists, it means original slice was last
                        IdmContractSliceDto previousSliceForOriginalSlice = this.getBean().findPreviousSlice(originalSlice, slices);
                        if (previousSliceForOriginalSlice != null && this.getBean().findNextSlice(previousSliceForOriginalSlice, slices) == null) {
                            previousSliceForOriginalSlice.setValidTill(null);
                            // Save with skip this processor
                            saveWithoutRecalculate(previousSliceForOriginalSlice);
                        }
                    }
                }
            }
        }
        // Validity from was changed, want to recalculate "Is using as contract" field.
        recalculateUsingAsContract = true;
    }
    if (recalculateUsingAsContract || forceRecalculateCurrentUsingSlice) {
        IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
        sliceFilter.setParentContract(parentContract);
        sliceFilter.setUsingAsContract(Boolean.TRUE);
        IdmContractSliceDto shouldBeSetAsUsing = this.getBean().findValidSlice(parentContract);
        if (shouldBeSetAsUsing != null) {
            Map<String, Serializable> clonedProperties = new HashMap<>(eventProperties);
            if (clonedProperties.containsKey(IdmContractSliceService.FORCE_RECALCULATE_CURRENT_USING_SLICE)) {
                clonedProperties.remove(IdmContractSliceService.FORCE_RECALCULATE_CURRENT_USING_SLICE);
            }
            shouldBeSetAsUsing = this.getBean().setSliceAsCurrentlyUsing(shouldBeSetAsUsing, clonedProperties);
            if (slice.equals(shouldBeSetAsUsing)) {
                // If that slice should be using as contract, then we using returned instance
                // (instead the reload slice from DB)
                slice = shouldBeSetAsUsing;
            }
        }
    }
    // Check if is slice new or contract valid till field was changed.
    if (originalSlice == null || (!Objects.equal(originalSlice.getContractValidTill(), slice.getContractValidTill()))) {
        // If is slice last, then will be to slice valid till copy date of contract
        // valid till
        boolean isSliceLast = this.getBean().findNextSlice(slice, this.getBean().findAllSlices(parentContract)) == null ? true : false;
        if (isSliceLast) {
            slice.setValidTill(null);
            saveWithoutRecalculate(slice);
        }
    }
}
Also used : ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) Serializable(java.io.Serializable) HashMap(java.util.HashMap) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Aggregations

ContractSliceEvent (eu.bcvsolutions.idm.core.model.event.ContractSliceEvent)14 IdmContractSliceDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)13 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)6 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)6 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 Test (org.junit.Test)5 UUID (java.util.UUID)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 IdmContractSliceFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter)3 IdmContractSliceGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter)3 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)3 ContractSliceConfiguration (eu.bcvsolutions.idm.core.api.config.domain.ContractSliceConfiguration)2 Codeable (eu.bcvsolutions.idm.core.api.domain.Codeable)2 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)2 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)2 IdmContractSliceGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto)2 EventContext (eu.bcvsolutions.idm.core.api.event.EventContext)2