Search in sources :

Example 11 with IdmContractSliceDto

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

the class ContractSliceManagerTest method clearStateExecutorTest.

@Test
public void clearStateExecutorTest() {
    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(1));
    slice.setValidTill(LocalDate.now().plusDays(5));
    slice.setContractValidFrom(LocalDate.now().minusDays(50));
    slice.setMain(true);
    IdmContractSliceDto sliceTwo = new IdmContractSliceDto();
    sliceTwo.setContractCode("test");
    sliceTwo.setIdentity(identity.getId());
    sliceTwo.setValidFrom(LocalDate.now().minusDays(10));
    sliceTwo.setValidTill(LocalDate.now().minusDays(2));
    sliceTwo.setContractValidFrom(LocalDate.now().minusDays(50));
    sliceTwo.setMain(true);
    EventContext<IdmContractSliceDto> eventContextOne = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, slice, ImmutableMap.of(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE)));
    EventContext<IdmContractSliceDto> eventContextTwo = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, sliceTwo, 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(2, dirtyStates.size());
    ClearDirtyStateForContractSliceTaskExecutor executor = new ClearDirtyStateForContractSliceTaskExecutor();
    OperationResult result = longRunningTaskManager.executeSync(executor);
    assertEquals(OperationState.EXECUTED, result.getState());
    dirtyStates = findDirtyStatesForSlice(null);
    assertTrue(dirtyStates.isEmpty());
    assertEquals(0, dirtyStates.size());
    allByIdentity = contractService.findAllByIdentity(identity.getId());
    assertEquals(1, allByIdentity.size());
    IdmIdentityContractDto contractDto = allByIdentity.get(0);
    assertTrue(contractDto.getControlledBySlices());
    assertEquals(LocalDate.now().minusDays(50), contractDto.getValidFrom());
    // Delete unused slices
    contractSliceService.delete(eventContextOne.getContent());
    contractSliceService.delete(eventContextTwo.getContent());
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) 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) 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 12 with IdmContractSliceDto

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

the class ContractSliceManagerTest method contractValidityProtectionModeEnabledExpiredTest.

@Test
public void contractValidityProtectionModeEnabledExpiredTest() {
    // Enable protection mode (4 days, gap is 5 days)
    configurationService.setValue(ContractSliceConfiguration.PROPERTY_PROTECTION_INTERVAL, "4");
    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), LocalDate.now().plusDays(10), 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 enabled, but gap was too long
    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 13 with IdmContractSliceDto

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

the class ContractSliceManagerTest method skipRecalculationTest.

@Test
public void skipRecalculationTest() {
    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.SKIP_RECALCULATE_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);
    assertTrue(dirtyStates.isEmpty());
    // 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 14 with IdmContractSliceDto

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

the class ContractSliceSyncTest method createContractSlicesTest.

@Test
public void createContractSlicesTest() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
    Assert.assertTrue(config instanceof SysSyncContractConfigDto);
    helper.createIdentity(CONTRACT_OWNER_ONE);
    helper.createIdentity(CONTRACT_OWNER_TWO);
    helper.createIdentity(CONTRACT_LEADER_ONE);
    IdmTreeTypeDto treeType = helper.createTreeType();
    IdmTreeNodeDto defaultNode = helper.createTreeNode(treeType, null);
    ((SysSyncContractConfigDto) config).setDefaultTreeType(treeType.getId());
    ((SysSyncContractConfigDto) config).setDefaultTreeNode(defaultNode.getId());
    config = syncConfigService.save(config);
    IdmContractSliceFilter contractFilter = new IdmContractSliceFilter();
    contractFilter.setProperty(IdmIdentityContract_.position.getName());
    contractFilter.setValue("1");
    Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
    contractFilter.setValue("2");
    Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
    helper.startSynchronization(config);
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    contractFilter.setValue("1");
    Assert.assertEquals(1, contractSliceService.find(contractFilter, null).getTotalElements());
    // Find slice guarantees
    Assert.assertEquals(1, contractSliceManager.findSliceGuarantees(contractSliceService.find(contractFilter, null).getContent().get(0).getId()).size());
    contractFilter.setValue("2");
    Assert.assertEquals(1, contractSliceService.find(contractFilter, null).getTotalElements());
    contractFilter.setValue("3");
    List<IdmContractSliceDto> contractsThree = contractSliceService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsThree.size());
    Assert.assertEquals(null, contractsThree.get(0).getState());
    // Find slice guarantees
    Assert.assertEquals(0, contractSliceManager.findSliceGuarantees(contractsThree.get(0).getId()).size());
    contractFilter.setValue("4");
    Assert.assertEquals(1, contractSliceService.find(contractFilter, null).getTotalElements());
    // Delete log
    syncLogService.delete(log);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) 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)

Example 15 with IdmContractSliceDto

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

the class ContractSliceSyncTest method testIdentityProvisioningOnChangeContractBySlice.

@Test
public void testIdentityProvisioningOnChangeContractBySlice() {
    SysSystemDto identitySystem = helper.createSystem(TestResource.TABLE_NAME);
    helper.createMapping(identitySystem);
    IdmRoleDto roleWithIdentitySystem = helper.createRole();
    helper.createRoleSystem(roleWithIdentitySystem, identitySystem);
    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);
    // Assign identity system to the owner.
    helper.assignRoles(helper.getPrimeContract(owner), roleWithIdentitySystem);
    SysProvisioningOperationFilter provisioningOperationFilter = new SysProvisioningOperationFilter();
    provisioningOperationFilter.setEntityIdentifier(owner.getId());
    provisioningOperationFilter.setSystemId(identitySystem.getId());
    List<SysProvisioningArchiveDto> provisioningArchiveDtos = provisioningArchiveService.find(provisioningOperationFilter, null).getContent();
    Assert.assertEquals(1, provisioningArchiveDtos.size());
    IdmContractSliceFilter contractSliceFilter = new IdmContractSliceFilter();
    contractSliceFilter.setIdentity(owner.getId());
    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());
    provisioningArchiveDtos = provisioningArchiveService.find(provisioningOperationFilter, null).getContent();
    Assert.assertEquals(9, provisioningArchiveDtos.size());
    // 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());
    provisioningArchiveDtos = provisioningArchiveService.find(provisioningOperationFilter, null).getContent();
    Assert.assertEquals(15, provisioningArchiveDtos.size());
    // Delete log
    syncLogService.delete(log);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) 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