Search in sources :

Example 6 with SysSyncContractConfigDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto in project CzechIdMng by bcvsolutions.

the class IdentityContractSyncTest method deleteContractAccountTest.

@Test
public void deleteContractAccountTest() {
    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);
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setProperty(IdmIdentityContract_.position.getName());
    contractFilter.setValue("1");
    Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
    contractFilter.setValue("2");
    Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    contractFilter.setValue("1");
    List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contracts.size());
    // Find the account for this contract
    IdmIdentityContractDto contract = contracts.get(0);
    AccContractAccountFilter contractAccountFilter = new AccContractAccountFilter();
    contractAccountFilter.setContractId(contract.getId());
    contractAccountFilter.setSystemId(system.getId());
    List<AccContractAccountDto> contractAccounts = contractAccountService.find(contractAccountFilter, null).getContent();
    Assert.assertEquals(1, contractAccounts.size());
    AccContractAccountDto contractAccount = contractAccounts.get(0);
    AccAccountDto account = accountService.get(contractAccount.getAccount());
    Assert.assertNotNull(account);
    // Delete this account directly test
    accountService.delete(account);
    account = accountService.get(contractAccount.getAccount());
    Assert.assertNull(account);
    // 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) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AccContractAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter) AccContractAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractAccountDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 7 with SysSyncContractConfigDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto in project CzechIdMng by bcvsolutions.

the class IdentityContractSyncTest method checkContractInvalidWithStartHrProcessesTest.

@Test
public /**
 * HR process are not executed during sync, but after sync end.
 */
void checkContractInvalidWithStartHrProcessesTest() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
    Assert.assertTrue(config instanceof SysSyncContractConfigDto);
    ((SysSyncContractConfigDto) config).setStartOfHrProcesses(true);
    syncConfigService.save(config);
    Task task = findTask(HrEnableContractProcess.class);
    IdmScheduledTaskDto scheduledTask = null;
    if (scheduledService.findByQuartzTaskName(task.getId()) == null) {
        scheduledTask = new IdmScheduledTaskDto();
        scheduledTask.setQuartzTaskName(task.getId());
        scheduledService.save(scheduledTask);
    }
    task = findTask(HrEndContractProcess.class);
    if (scheduledService.findByQuartzTaskName(task.getId()) == null) {
        scheduledTask = new IdmScheduledTaskDto();
        scheduledTask.setQuartzTaskName(task.getId());
        scheduledService.save(scheduledTask);
    }
    task = findTask(HrContractExclusionProcess.class);
    if (scheduledService.findByQuartzTaskName(task.getId()) == null) {
        scheduledTask = new IdmScheduledTaskDto();
        scheduledTask.setQuartzTaskName(task.getId());
        scheduledService.save(scheduledTask);
    }
    IdmIdentityDto ownerOne = helper.createIdentity(CONTRACT_OWNER_ONE);
    IdmIdentityDto ownerTwo = helper.createIdentity(CONTRACT_OWNER_TWO);
    helper.createIdentity(CONTRACT_LEADER_ONE);
    contractService.findAllByIdentity(ownerOne.getId()).forEach(contract -> {
        IdentityContractEvent event = new IdentityContractEvent(IdentityContractEventType.DELETE, contract);
        event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
        contractService.publish(event);
    });
    contractService.findAllByIdentity(ownerTwo.getId()).forEach(contract -> {
        IdentityContractEvent event = new IdentityContractEvent(IdentityContractEventType.DELETE, contract);
        event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
        contractService.publish(event);
    });
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setProperty(IdmIdentityContract_.position.getName());
    contractFilter.setValue("1");
    Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
    contractFilter.setValue("2");
    Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
    // Change resources (set to invalid) .. must be call in transaction
    this.getBean().initContractCheckInvalidTest();
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    contractFilter.setValue("1");
    List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsOne.size());
    Assert.assertFalse(contractsOne.get(0).isValid());
    contractFilter.setValue("3");
    List<IdmIdentityContractDto> contractsThree = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsThree.size());
    Assert.assertTrue(contractsThree.get(0).isValid());
    // HR processes was started, identity have to be in "correct" state
    ownerOne = identityService.getByUsername(CONTRACT_OWNER_ONE);
    Assert.assertTrue(ownerOne.isDisabled());
    ownerTwo = identityService.getByUsername(CONTRACT_OWNER_TWO);
    Assert.assertFalse(ownerTwo.isDisabled());
    // Delete log
    syncLogService.delete(log);
}
Also used : Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) HrEndContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEndContractProcess) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) HrContractExclusionProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrContractExclusionProcess) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) 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)

Example 8 with SysSyncContractConfigDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto in project CzechIdMng by bcvsolutions.

the class IdentityContractSyncTest method defaultWorkPositionTest.

@Test
public void defaultWorkPositionTest() {
    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);
    helper.createIdentity(CONTRACT_LEADER_TWO);
    // Set default tree type to sync configuration
    IdmTreeTypeDto treeType = treeTypeService.getByCode(InitApplicationData.DEFAULT_TREE_TYPE);
    Assert.assertNotNull(treeType);
    SysSyncContractConfigDto configContract = (SysSyncContractConfigDto) config;
    configContract.setDefaultTreeType(treeType.getId());
    // Set default tree node to sync configuration
    IdmTreeNodeFilter nodeFilter = new IdmTreeNodeFilter();
    nodeFilter.setCode("one");
    nodeFilter.setTreeTypeId(treeType.getId());
    List<IdmTreeNodeDto> nodes = treeNodeService.find(nodeFilter, null).getContent();
    Assert.assertEquals(1, nodes.size());
    IdmTreeNodeDto defaultNode = nodes.get(0);
    configContract.setDefaultTreeNode(defaultNode.getId());
    config = syncConfigService.save(configContract);
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setProperty(IdmIdentityContract_.position.getName());
    // Start sync
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    // Default work positions must be set
    contractFilter.setValue("1");
    List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsOne.size());
    Assert.assertEquals(defaultNode.getId(), contractsOne.get(0).getWorkPosition());
    contractFilter.setValue("2");
    List<IdmIdentityContractDto> contractsTwo = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsTwo.size());
    Assert.assertEquals(defaultNode.getId(), contractsTwo.get(0).getWorkPosition());
    contractFilter.setValue("3");
    List<IdmIdentityContractDto> contractsThree = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsThree.size());
    Assert.assertEquals(defaultNode.getId(), contractsThree.get(0).getWorkPosition());
    // 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) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 9 with SysSyncContractConfigDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto in project CzechIdMng by bcvsolutions.

the class ContractSynchronizationExecutor method transformGuarantees.

private Object transformGuarantees(SynchronizationContext context, Object transformedValue) {
    if (transformedValue != null) {
        SyncIdentityContractDto syncContract = new SyncIdentityContractDto();
        if (transformedValue instanceof List) {
            ((List<?>) transformedValue).stream().forEach(guarantee -> {
                // Beware this DTO contains only identity ID, not
                // contract ... must be save separately.
                context.getLogItem().addToLog(MessageFormat.format("Finding guarantee [{0}].", guarantee));
                IdmIdentityDto guarranteeDto = this.findIdentity(guarantee, context);
                if (guarranteeDto != null) {
                    context.getLogItem().addToLog(MessageFormat.format("Guarantee [{0}] was found.", guarranteeDto.getCode()));
                    syncContract.getGuarantees().add(guarranteeDto);
                }
            });
        } else {
            // Beware this DTO contains only identity ID, not
            // contract ... must be save separately.
            context.getLogItem().addToLog(MessageFormat.format("Finding guarantee [{0}].", transformedValue));
            IdmIdentityDto guarranteeDto = this.findIdentity(transformedValue, context);
            if (guarranteeDto != null) {
                context.getLogItem().addToLog(MessageFormat.format("Guarantee [{0}] was found.", guarranteeDto.getCode()));
                syncContract.getGuarantees().add(guarranteeDto);
            }
        }
        transformedValue = syncContract;
    } else {
        if (getConfig(context).getDefaultLeader() != null) {
            UUID defaultLeader = ((SysSyncContractConfigDto) context.getConfig()).getDefaultLeader();
            IdmIdentityDto identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, defaultLeader);
            if (identity != null) {
                SyncIdentityContractDto syncContract = new SyncIdentityContractDto();
                syncContract.getGuarantees().add(identity);
                transformedValue = syncContract;
                context.getLogItem().addToLog(MessageFormat.format("Warning! - None leader was found for this realtion, we use default leader [{0}]!", identity.getCode()));
            }
        }
    }
    return transformedValue;
}
Also used : SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) List(java.util.List) SyncIdentityContractDto(eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID)

Example 10 with SysSyncContractConfigDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto in project CzechIdMng by bcvsolutions.

the class IdentityContractSyncTest method checkContractInvalidTest.

@Test
public /**
 * HR process are not executed during sync. If contract is invalid, then HR
 * process disable the Identity. But in the sync we need skip this
 * functionality.
 */
void checkContractInvalidTest() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
    Assert.assertTrue(config instanceof SysSyncContractConfigDto);
    ((SysSyncContractConfigDto) config).setStartOfHrProcesses(false);
    syncConfigService.save(config);
    IdmIdentityDto ownerOne = helper.createIdentity(CONTRACT_OWNER_ONE);
    IdmIdentityDto ownerTwo = helper.createIdentity(CONTRACT_OWNER_TWO);
    helper.createIdentity(CONTRACT_LEADER_ONE);
    contractService.findAllByIdentity(ownerOne.getId()).forEach(contract -> {
        IdentityContractEvent event = new IdentityContractEvent(IdentityContractEventType.DELETE, contract);
        event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
        contractService.publish(event);
    });
    contractService.findAllByIdentity(ownerTwo.getId()).forEach(contract -> {
        IdentityContractEvent event = new IdentityContractEvent(IdentityContractEventType.DELETE, contract);
        event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
        contractService.publish(event);
    });
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setProperty(IdmIdentityContract_.position.getName());
    contractFilter.setValue("1");
    Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
    contractFilter.setValue("2");
    Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
    // Change resources (set to invalid) .. must be call in transaction
    this.getBean().initContractCheckInvalidTest();
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    contractFilter.setValue("1");
    List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsOne.size());
    Assert.assertFalse(contractsOne.get(0).isValid());
    contractFilter.setValue("3");
    List<IdmIdentityContractDto> contractsThree = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsThree.size());
    Assert.assertTrue(contractsThree.get(0).isValid());
    // HR processes was not started, identity have to be in "incorrect" state
    ownerOne = identityService.getByUsername(CONTRACT_OWNER_ONE);
    Assert.assertFalse(ownerOne.isDisabled());
    ownerTwo = identityService.getByUsername(CONTRACT_OWNER_TWO);
    Assert.assertFalse(ownerTwo.isDisabled());
    // 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) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) 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) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)13 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)10 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)9 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)9 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)9 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)9 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Test (org.junit.Test)9 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)4 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)3 IdmTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter)2 IdentityContractEvent (eu.bcvsolutions.idm.core.model.event.IdentityContractEvent)2 UUID (java.util.UUID)2 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)1 AccContractAccountDto (eu.bcvsolutions.idm.acc.dto.AccContractAccountDto)1 SyncIdentityContractDto (eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto)1 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)1 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)1 AccContractAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter)1