Search in sources :

Example 51 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class ContractSliceManagerTest method contractValidityProtectionModeDisableInfinityTest.

@Test
public void contractValidityProtectionModeDisableInfinityTest() {
    // Disable protection mode (0 days)
    configurationService.setValue(ContractSliceConfiguration.PROPERTY_PROTECTION_INTERVAL, "0");
    IdmIdentityDto identity = helper.createIdentity();
    IdmContractSliceDto sliceOne = helper.createContractSlice(identity, "11", null, LocalDate.now().minusDays(100), LocalDate.now().minusDays(100), LocalDate.now().plusDays(5));
    IdmContractSliceDto sliceTwo = helper.createContractSlice(identity, "11", null, LocalDate.now().plusDays(10), null, LocalDate.now().plusDays(100));
    assertNotNull(sliceOne.getParentContract());
    assertNotNull(sliceTwo.getParentContract());
    assertEquals(sliceOne.getParentContract(), sliceTwo.getParentContract());
    assertTrue(sliceOne.isUsingAsContract());
    assertFalse(sliceTwo.isUsingAsContract());
    IdmIdentityContractDto contract = contractService.get(sliceOne.getParentContract());
    // Protection mode is disabled, next slice has contract valid from sets to null
    assertEquals(sliceOne.getContractValidFrom(), contract.getValidFrom());
    assertEquals(sliceOne.getContractValidTill(), contract.getValidTill());
}
Also used : 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 52 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class ContractSliceManagerTest method clearStateExecutorPageTest.

@Test
public void clearStateExecutorPageTest() {
    IdmIdentityDto identity = this.getHelper().createIdentity();
    List<IdmEntityStateDto> dirtyStates = findAllDirtyStatesForSlices();
    assertEquals(0, dirtyStates.size());
    for (int index = 0; index < 21; index++) {
        IdmContractSliceDto createContractSlice = this.getHelper().createContractSlice(identity);
        createDirtyState(createContractSlice);
    }
    dirtyStates = findAllDirtyStatesForSlices();
    assertEquals(21, dirtyStates.size());
    ClearDirtyStateForContractSliceTaskExecutor executor = new ClearDirtyStateForContractSliceTaskExecutor();
    OperationResult result = longRunningTaskManager.executeSync(executor);
    assertEquals(OperationState.EXECUTED, result.getState());
    dirtyStates = findAllDirtyStatesForSlices();
    assertEquals(0, dirtyStates.size());
    IdmLongRunningTaskDto taskDto = longRunningTaskService.get(executor.getLongRunningTaskId());
    assertNotNull(taskDto.getCount());
    assertNotNull(taskDto.getCounter());
    assertEquals(21, taskDto.getCount().longValue());
    assertEquals(21, taskDto.getCounter().longValue());
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) ClearDirtyStateForContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) 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 53 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto 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 54 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto 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)

Example 55 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class ContractSliceSyncTest method changeContractBySliceTest.

@Test
public void changeContractBySliceTest() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
    Assert.assertTrue(config instanceof SysSyncContractConfigDto);
    IdmIdentityDto owner = helper.createIdentity(CONTRACT_OWNER_ONE);
    helper.createIdentity(CONTRACT_LEADER_ONE);
    IdmContractSliceFilter contractSliceFilter = new IdmContractSliceFilter();
    contractSliceFilter.setProperty(IdmIdentityContract_.position.getName());
    contractSliceFilter.setValue("1");
    Assert.assertEquals(0, contractSliceService.find(contractSliceFilter, null).getTotalElements());
    contractSliceFilter.setValue("2");
    Assert.assertEquals(0, contractSliceService.find(contractSliceFilter, null).getTotalElements());
    helper.startSynchronization(config);
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    contractSliceFilter.setValue("1");
    Assert.assertEquals(1, contractSliceService.find(contractSliceFilter, null).getTotalElements());
    contractSliceFilter.setValue("2");
    List<IdmContractSliceDto> slicesTwo = contractSliceService.find(contractSliceFilter, null).getContent();
    Assert.assertEquals(1, slicesTwo.size());
    contractSliceFilter.setValue("3");
    List<IdmContractSliceDto> contractsThree = contractSliceService.find(contractSliceFilter, null).getContent();
    Assert.assertEquals(1, contractsThree.size());
    Assert.assertEquals(null, contractsThree.get(0).getState());
    contractSliceFilter.setValue("4");
    Assert.assertEquals(1, contractSliceService.find(contractSliceFilter, null).getTotalElements());
    // Find created contract
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setIdentity(owner.getId());
    List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(3, contracts.size());
    // Slice with id "2" should be current using
    Assert.assertEquals(1, contracts.stream().filter(c -> c.getPosition().equals("2") && c.isValid()).count());
    Assert.assertTrue(slicesTwo.get(0).isUsingAsContract());
    // Delete log
    syncLogService.delete(log);
    // Slice with id "2" reassign from contract ONE to TWO
    this.getBean().changeContractData();
    helper.startSynchronization(config);
    log = checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 4);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    // Find created contract
    contractFilter = new IdmIdentityContractFilter();
    contractFilter.setIdentity(owner.getId());
    contracts = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(3, contracts.size());
    // Slice with id "2" should not be current used
    Assert.assertEquals(0, contracts.stream().filter(c -> c.getPosition().equals("2") && c.isValid()).count());
    // But slice with id "4" should be current used
    Assert.assertEquals(1, contracts.stream().filter(c -> c.getPosition().equals("4") && c.isValid()).count());
    Assert.assertTrue(slicesTwo.get(0).isUsingAsContract());
    // Delete log
    syncLogService.delete(log);
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmContractSliceDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)72 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)44 Test (org.junit.Test)44 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)42 IdmContractSliceFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter)36 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)35 ContractSliceEvent (eu.bcvsolutions.idm.core.model.event.ContractSliceEvent)26 UUID (java.util.UUID)22 IdmContractSliceGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto)21 IdmContractSliceGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter)21 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)20 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)19 HashMap (java.util.HashMap)19 ImmutableMap (com.google.common.collect.ImmutableMap)17 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)17 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)17 ContractSliceManager (eu.bcvsolutions.idm.core.api.service.ContractSliceManager)17 List (java.util.List)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)16