Search in sources :

Example 1 with SelectCurrentContractSliceTaskExecutor

use of eu.bcvsolutions.idm.core.scheduler.task.impl.SelectCurrentContractSliceTaskExecutor 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)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 ContractSliceConfiguration (eu.bcvsolutions.idm.core.api.config.domain.ContractSliceConfiguration)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)1 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)1 IdmContractSliceDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)1 IdmContractSliceGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto)1 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)1 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)1 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)1 IdmContractSliceFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter)1 IdmContractSliceGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter)1 IdmEntityStateFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter)1 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)1 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)1 EventContext (eu.bcvsolutions.idm.core.api.event.EventContext)1 ConfigurationService (eu.bcvsolutions.idm.core.api.service.ConfigurationService)1