Search in sources :

Example 46 with IdmTreeNodeDto

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

the class DefaultTreeSynchronizationServiceTest method provisioningA_CreateAccount_withOutMapping.

@Test
@Transactional
public void provisioningA_CreateAccount_withOutMapping() {
    // Delete all resource data
    this.deleteAllResourceData();
    IdmTreeTypeDto treeType = treeTypeService.find(null).getContent().stream().filter(tree -> {
        return tree.getName().equals(TREE_TYPE_TEST);
    }).findFirst().get();
    // Create root node in IDM tree
    IdmTreeNodeDto nodeRoot = new IdmTreeNodeDto();
    nodeRoot.setCode("P1");
    nodeRoot.setName(nodeRoot.getCode());
    nodeRoot.setParent(null);
    nodeRoot.setTreeType(treeType.getId());
    nodeRoot = treeNodeService.save(nodeRoot);
    // Create node in IDM tree
    IdmTreeNodeDto nodeOne = new IdmTreeNodeDto();
    nodeOne.setCode("P12");
    nodeOne.setName(nodeOne.getCode());
    nodeOne.setParent(nodeRoot.getId());
    nodeOne.setTreeType(treeType.getId());
    nodeOne = treeNodeService.save(nodeOne);
    // Check state before provisioning
    TestTreeResource one = entityManager.find(TestTreeResource.class, "P12");
    Assert.assertNull(one);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) TestTreeResource(eu.bcvsolutions.idm.acc.entity.TestTreeResource) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with IdmTreeNodeDto

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

the class IdentityContractSyncTest method testLinkAndUpdateContract.

@Test
public void testLinkAndUpdateContract() {
    String position1 = "test-link-update-1-" + System.currentTimeMillis();
    String position2 = "test-link-update-2-" + System.currentTimeMillis();
    String position3 = "test-link-update-3-" + System.currentTimeMillis();
    IdmIdentityDto leader = helper.createIdentity();
    IdmTreeNodeDto workPosition = helper.createTreeNode();
    SysSystemDto system = initData();
    AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
    this.getBean().deleteAllResourceData();
    config.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK_AND_UPDATE_ENTITY);
    config = (SysSyncContractConfigDto) syncConfigService.save(config);
    IdmIdentityDto identity1 = helper.createIdentity();
    IdmIdentityDto identity2 = helper.createIdentity();
    IdmIdentityDto identity3 = helper.createIdentity();
    IdmIdentityContractDto contrac1 = helper.getPrimeContract(identity1.getId());
    IdmIdentityContractDto contrac2 = helper.getPrimeContract(identity2.getId());
    IdmIdentityContractDto contrac3 = helper.getPrimeContract(identity3.getId());
    contrac1.setPosition(position1);
    contrac1.setDescription(position1);
    contrac2.setPosition(position2);
    contrac2.setDescription(position2);
    contrac3.setPosition(position3);
    contrac3.setDescription(position3);
    contrac1 = contractService.save(contrac1);
    contrac2 = contractService.save(contrac2);
    contrac3 = contractService.save(contrac3);
    // check empty guarantee
    IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
    guaranteeFilter.setIdentityContractId(contrac1.getId());
    List<IdmContractGuaranteeDto> gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
    assertTrue(gurantees.isEmpty());
    guaranteeFilter.setIdentityContractId(contrac2.getId());
    gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
    assertTrue(gurantees.isEmpty());
    guaranteeFilter.setIdentityContractId(contrac3.getId());
    gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
    assertTrue(gurantees.isEmpty());
    assertNull(contrac1.getState());
    assertNull(contrac2.getState());
    assertNull(contrac3.getState());
    this.getBean().createContractData(position1, identity1.getUsername(), leader.getUsername(), Boolean.TRUE.toString(), workPosition.getId().toString(), "10", Boolean.FALSE.toString());
    this.getBean().createContractData(position2, identity2.getUsername(), leader.getUsername(), Boolean.TRUE.toString(), workPosition.getId().toString(), "10", Boolean.FALSE.toString());
    this.getBean().createContractData(position3, identity3.getUsername(), leader.getUsername(), Boolean.TRUE.toString(), workPosition.getId().toString(), "10", Boolean.FALSE.toString());
    // Start sync
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    contractService.findAllByIdentity(identity1.getId());
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK_AND_UPDATE_ENTITY, 3);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    IdmIdentityContractDto updatedContract1 = helper.getPrimeContract(identity1.getId());
    IdmIdentityContractDto updatedContract2 = helper.getPrimeContract(identity2.getId());
    IdmIdentityContractDto updatedContract3 = helper.getPrimeContract(identity3.getId());
    assertNotEquals(updatedContract1.getModified(), contrac1.getModified());
    assertNotEquals(updatedContract2.getModified(), contrac2.getModified());
    assertNotEquals(updatedContract3.getModified(), contrac3.getModified());
    assertNotEquals(updatedContract1.getState(), contrac1.getState());
    assertNotEquals(updatedContract2.getState(), contrac2.getState());
    assertNotEquals(updatedContract3.getState(), contrac3.getState());
    assertEquals(ContractState.EXCLUDED, updatedContract1.getState());
    assertEquals(ContractState.EXCLUDED, updatedContract2.getState());
    assertEquals(ContractState.EXCLUDED, updatedContract3.getState());
    assertEquals(contrac1.getId(), updatedContract1.getId());
    assertEquals(contrac2.getId(), updatedContract2.getId());
    assertEquals(contrac3.getId(), updatedContract3.getId());
    guaranteeFilter.setIdentityContractId(contrac1.getId());
    gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
    assertFalse(gurantees.isEmpty());
    assertEquals(leader.getId(), gurantees.get(0).getGuarantee());
    guaranteeFilter.setIdentityContractId(contrac2.getId());
    gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
    assertFalse(gurantees.isEmpty());
    assertEquals(leader.getId(), gurantees.get(0).getGuarantee());
    guaranteeFilter.setIdentityContractId(contrac3.getId());
    gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
    assertFalse(gurantees.isEmpty());
    assertEquals(leader.getId(), gurantees.get(0).getGuarantee());
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) 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 48 with IdmTreeNodeDto

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

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

the class TreeNodeDeleteProcessor method process.

@Override
public EventResult<IdmTreeNodeDto> process(EntityEvent<IdmTreeNodeDto> event) {
    IdmTreeNodeDto node = event.getContent();
    Assert.notNull(node);
    AccTreeAccountFilter filter = new AccTreeAccountFilter();
    filter.setTreeNodeId(node.getId());
    treeAccountService.find(filter, null).forEach(treeAccount -> {
        treeAccountService.delete(treeAccount);
    });
    // Delete link to sync contract configuration
    if (node != null && node.getId() != null) {
        syncConfigRepository.clearDefaultTreeNode(node.getId());
    }
    return new DefaultEventResult<>(event, this);
}
Also used : AccTreeAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccTreeAccountFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)

Example 50 with IdmTreeNodeDto

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

Aggregations

IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)79 Test (org.junit.Test)48 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)44 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)35 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)31 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)26 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)21 UUID (java.util.UUID)13 IdmTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter)12 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)12 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)9 LocalDate (org.joda.time.LocalDate)9 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)7 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)6 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)6 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 ApiOperation (io.swagger.annotations.ApiOperation)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)5