Search in sources :

Example 11 with SysSyncContractConfigDto

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

the class IdentityContractSyncTest method defaultTreeTest.

@Test
public void defaultTreeTest() {
    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());
    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());
    // None work positions can be found
    contractFilter.setValue("1");
    List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsOne.size());
    Assert.assertEquals(null, contractsOne.get(0).getWorkPosition());
    contractFilter.setValue("2");
    List<IdmIdentityContractDto> contractsTwo = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsTwo.size());
    Assert.assertEquals(null, contractsTwo.get(0).getWorkPosition());
    contractFilter.setValue("3");
    List<IdmIdentityContractDto> contractsThree = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsThree.size());
    Assert.assertEquals(null, contractsThree.get(0).getWorkPosition());
    // Delete log
    syncLogService.delete(log);
    // Set work positions to resources
    this.getBean().initContractDefaultTreeTest();
    // Start sync again (we want to see some work positions)
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    log = checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 3);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    // For contract One must be found workposition (one)
    contractFilter.setValue("1");
    contractsOne = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsOne.size());
    IdmTreeNodeDto workposition = DtoUtils.getEmbedded(contractsOne.get(0), IdmIdentityContract_.workPosition, IdmTreeNodeDto.class);
    Assert.assertEquals("one", workposition.getCode());
    // For contract Two must not be found workposition (WRONG node is not in
    // default
    // tree)
    contractFilter.setValue("2");
    contractsTwo = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsTwo.size());
    Assert.assertEquals(null, contractsTwo.get(0).getWorkPosition());
    contractFilter.setValue("3");
    contractsThree = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsThree.size());
    Assert.assertEquals(null, 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) 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 12 with SysSyncContractConfigDto

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

the class ContractSynchronizationExecutor method getValueByMappedAttribute.

@Override
protected Object getValueByMappedAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
    Object transformedValue = super.getValueByMappedAttribute(attribute, icAttributes, context);
    // Transform contract state enumeration from string
    if (CONTRACT_STATE_FIELD.equals(attribute.getIdmPropertyName()) && transformedValue instanceof String && attribute.isEntityAttribute()) {
        return ContractState.valueOf((String) transformedValue);
    }
    // Transform contract guarantees
    if (CONTRACT_GUARANTEES_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
        return transformGuarantees(context, transformedValue);
    }
    // Transform work position (tree node)
    if (CONTRACT_WORK_POSITION_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
        if (transformedValue != null) {
            IdmTreeNodeDto workposition = this.findTreeNode(transformedValue, context);
            if (workposition != null) {
                return workposition.getId();
            }
            return null;
        } else {
            if (getConfig(context).getDefaultTreeNode() != null) {
                UUID defaultNode = ((SysSyncContractConfigDto) context.getConfig()).getDefaultTreeNode();
                IdmTreeNodeDto node = (IdmTreeNodeDto) lookupService.lookupDto(IdmTreeNodeDto.class, defaultNode);
                if (node != null) {
                    context.getLogItem().addToLog(MessageFormat.format("Warning! - None workposition was defined for this realtion, we use default workposition [{0}]!", node.getCode()));
                    return node.getId();
                }
            }
        }
    }
    // Transform contract owner
    if (transformedValue != null && CONTRACT_IDENTITY_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
        context.getLogItem().addToLog(MessageFormat.format("Finding contract owner [{0}].", transformedValue));
        IdmIdentityDto identity = this.findIdentity(transformedValue, context);
        if (identity == null) {
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_CANNOT_BE_NULL, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
        }
        return identity.getId();
    }
    return transformedValue;
}
Also used : SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 13 with SysSyncContractConfigDto

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

the class ContractSynchronizationExecutor method findTreeNode.

private IdmTreeNodeDto findTreeNode(Object value, SynchronizationContext context) {
    if (value instanceof Serializable) {
        // Find by UUID
        context.getLogItem().addToLog(MessageFormat.format("Work position - try find directly by transformed value [{0}]!", value));
        IdmTreeNodeDto node = (IdmTreeNodeDto) lookupService.lookupDto(IdmTreeNodeDto.class, (Serializable) value);
        if (node != null) {
            IdmTreeTypeDto treeTypeDto = DtoUtils.getEmbedded(node, IdmTreeNode_.treeType, IdmTreeTypeDto.class);
            context.getLogItem().addToLog(MessageFormat.format("Work position - One node [{1}] (in tree type [{2}]) was found directly by transformed value [{0}]!", value, node.getCode(), treeTypeDto.getCode()));
            return node;
        }
        context.getLogItem().addToLog(MessageFormat.format("Work position - was not not found directly from transformed value [{0}]!", value));
        if (value instanceof String) {
            // Find by code in default tree type
            SysSyncContractConfigDto config = this.getConfig(context);
            if (config.getDefaultTreeType() == null) {
                context.getLogItem().addToLog(MessageFormat.format("Warning - Work position - we cannot finding node by code [{0}], because default tree node is not set (in sync configuration)!", value));
                this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
                return null;
            }
            IdmTreeNodeFilter treeNodeFilter = new IdmTreeNodeFilter();
            IdmTreeTypeDto defaultTreeType = DtoUtils.getEmbedded(config, SysSyncContractConfig_.defaultTreeType, IdmTreeTypeDto.class);
            treeNodeFilter.setTreeTypeId(config.getDefaultTreeType());
            treeNodeFilter.setCode((String) value);
            context.getLogItem().addToLog(MessageFormat.format("Work position - try find in default tree type [{1}] with code [{0}]!", value, defaultTreeType.getCode()));
            List<IdmTreeNodeDto> nodes = treeNodeService.find(treeNodeFilter, null).getContent();
            if (nodes.isEmpty()) {
                context.getLogItem().addToLog(MessageFormat.format("Warning - Work position - none node found for code [{0}]!", value));
                this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
                return null;
            } else if (nodes.size() > 1) {
                context.getLogItem().addToLog(MessageFormat.format("Warning - Work position - more then one [{0}] node found for code [{1}]!", value, nodes.size()));
                this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
                return null;
            } else {
                context.getLogItem().addToLog(MessageFormat.format("Work position - One node [{1}] was found for code [{0}]!", value, nodes.get(0).getId()));
                return nodes.get(0);
            }
        }
    } else {
        context.getLogItem().addToLog(MessageFormat.format("Warning! - Work position cannot be found, because transformed value [{0}] is not Serializable!", value));
        this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
    }
    return null;
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) Serializable(java.io.Serializable) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)

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