Search in sources :

Example 21 with IdmTreeNodeFilter

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

the class IdmTreeNodeServiceIntegrationTest method testFilters.

@Test
public void testFilters() {
    // ****** PREPARE DATA ******
    IdmTreeTypeDto t1 = treeTypeService.save(helper.createTreeType("TYPE1"));
    IdmTreeTypeDto t2 = treeTypeService.save(helper.createTreeType("TYPE2"));
    UUID t1Id = t1.getId();
    UUID t2Id = t2.getId();
    /*
		        o r1
		       / \
		   n1 o   o n3
		  / \
	      n2 o   o n4
		      \
		       o n5
		*/
    IdmTreeNodeDto r1 = helper.createTreeNode(t1, "ROOT1", null);
    IdmTreeNodeDto n1 = helper.createTreeNode(t1, "NODE1", r1);
    helper.createTreeNode(t1, "NODE2", n1);
    helper.createTreeNode(t1, "NODE3", r1);
    IdmTreeNodeDto n4 = helper.createTreeNode(t1, "NODE4", n1);
    IdmTreeNodeDto n5 = helper.createTreeNode(t1, "NODE5", n4);
    /*
		         o r2
		        /
		 n12 o-o n11
		 */
    IdmTreeNodeDto r2 = helper.createTreeNode(t2, "ROOT2", null);
    IdmTreeNodeDto n11 = helper.createTreeNode(t2, "NODE11", r2);
    IdmTreeNodeDto n12 = helper.createTreeNode(t2, "NODE12", n11);
    // 
    final UUID r1Uuid = r1.getId();
    final UUID n1Uuid = n1.getId();
    final UUID n5Uuid = n5.getId();
    final UUID r2Uuid = r2.getId();
    final UUID n12Uuid = n12.getId();
    // 
    // ******* TEST *******
    // 
    final IdmTreeNodeFilter t1Flter = new IdmTreeNodeFilter();
    t1Flter.setTreeTypeId(t1Id);
    Page<IdmTreeNodeDto> res1 = treeNodeService.find(t1Flter, null);
    Assert.assertEquals(6, res1.getTotalElements());
    // 
    final IdmTreeNodeFilter t2Flter = new IdmTreeNodeFilter();
    t2Flter.setTreeTypeId(t2Id);
    Page<IdmTreeNodeDto> res2 = treeNodeService.find(t2Flter, null);
    Assert.assertEquals(3, res2.getTotalElements());
    // 
    // Subtrees
    // 
    final IdmTreeNodeFilter subTreeFilter1 = new IdmTreeNodeFilter();
    subTreeFilter1.setTreeNode(n1Uuid);
    subTreeFilter1.setTreeTypeId(t1Id);
    subTreeFilter1.setRecursively(true);
    Page<IdmTreeNodeDto> res3 = treeNodeService.find(subTreeFilter1, null);
    Assert.assertEquals(3, res3.getTotalElements());
    // 
    final IdmTreeNodeFilter subTreeFilter2 = new IdmTreeNodeFilter();
    subTreeFilter2.setTreeNode(n1Uuid);
    subTreeFilter2.setRecursively(false);
    Page<IdmTreeNodeDto> res4 = treeNodeService.find(subTreeFilter2, null);
    Assert.assertEquals(2, res4.getTotalElements());
    // 
    final IdmTreeNodeFilter subTreeFilter3 = new IdmTreeNodeFilter();
    subTreeFilter3.setTreeNode(r2Uuid);
    subTreeFilter3.setRecursively(false);
    Page<IdmTreeNodeDto> res5 = treeNodeService.find(subTreeFilter3, null);
    Assert.assertEquals(1, res5.getTotalElements());
    // 
    final IdmTreeNodeFilter subTreeFilter4 = new IdmTreeNodeFilter();
    subTreeFilter4.setTreeNode(r2Uuid);
    subTreeFilter4.setTreeTypeId(t2Id);
    subTreeFilter4.setRecursively(true);
    Page<IdmTreeNodeDto> res6 = treeNodeService.find(subTreeFilter4, null);
    Assert.assertEquals(2, res6.getTotalElements());
    // 
    final IdmTreeNodeFilter subTreeFilter5 = new IdmTreeNodeFilter();
    subTreeFilter5.setTreeNode(n12Uuid);
    subTreeFilter5.setTreeTypeId(t2Id);
    subTreeFilter5.setRecursively(true);
    Page<IdmTreeNodeDto> res7 = treeNodeService.find(subTreeFilter5, null);
    Assert.assertEquals(0, res7.getTotalElements());
    // 
    final IdmTreeNodeFilter subTreeFilter6 = new IdmTreeNodeFilter();
    subTreeFilter6.setTreeNode(n12Uuid);
    subTreeFilter6.setTreeTypeId(t2Id);
    subTreeFilter6.setRecursively(false);
    Page<IdmTreeNodeDto> res8 = treeNodeService.find(subTreeFilter6, null);
    Assert.assertEquals(0, res8.getTotalElements());
    // 
    // Fulltext
    // 
    final IdmTreeNodeFilter fullTextFilter1 = new IdmTreeNodeFilter();
    fullTextFilter1.setText("NODE5");
    Page<IdmTreeNodeDto> res9 = treeNodeService.find(fullTextFilter1, null);
    Assert.assertEquals(1, res9.getTotalElements());
    Assert.assertEquals(n5Uuid, res9.getContent().get(0).getId());
    // 
    final IdmTreeNodeFilter fullTextFilter2 = new IdmTreeNodeFilter();
    fullTextFilter2.setText("NODE");
    fullTextFilter2.setTreeTypeId(t1Id);
    Page<IdmTreeNodeDto> res10 = treeNodeService.find(fullTextFilter2, null);
    Assert.assertEquals(5, res10.getTotalElements());
    // 
    final IdmTreeNodeFilter fullTextFilter3 = new IdmTreeNodeFilter();
    fullTextFilter3.setText("odE");
    fullTextFilter3.setTreeTypeId(t1Id);
    Page<IdmTreeNodeDto> res13 = treeNodeService.find(fullTextFilter3, null);
    Assert.assertEquals(5, res13.getTotalElements());
    // 
    // Property - value pairs
    // 
    final IdmTreeNodeFilter dynPropFilter1 = new IdmTreeNodeFilter();
    dynPropFilter1.setProperty("name");
    dynPropFilter1.setValue("ROOT1");
    Page<IdmTreeNodeDto> res11 = treeNodeService.find(dynPropFilter1, null);
    Assert.assertEquals(1, res11.getTotalElements());
    Assert.assertEquals(r1Uuid, res11.getContent().get(0).getId());
    // 
    final IdmTreeNodeFilter dynPropFilter2 = new IdmTreeNodeFilter();
    dynPropFilter2.setProperty("code");
    dynPropFilter2.setValue("ROOT2");
    Page<IdmTreeNodeDto> res12 = treeNodeService.find(dynPropFilter2, null);
    Assert.assertEquals(1, res12.getTotalElements());
    Assert.assertEquals(r2Uuid, res12.getContent().get(0).getId());
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) UUID(java.util.UUID) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 22 with IdmTreeNodeFilter

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

the class TreeSynchronizationExecutor method getEntityFilter.

@Override
protected CorrelationFilter getEntityFilter(SynchronizationContext context) {
    SysSystemMappingDto mapping = this.getSystemMapping(context.getMappedAttributes());
    UUID treeType = mapping.getTreeType();
    Assert.notNull(treeType, "Tree type cannot be null!");
    IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
    filter.setTreeTypeId(treeType);
    return filter;
}
Also used : IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) UUID(java.util.UUID)

Example 23 with IdmTreeNodeFilter

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

the class ComplexHrProcessIntegrationTest method initOrgStructure.

/**
 * Creates organization structure common for all test cases
 */
private void initOrgStructure() {
    IdmTreeNodeDto root = null;
    IdmTreeNodeDto node = null;
    // get tree type dto
    IdmTreeTypeFilter typeFilt = new IdmTreeTypeFilter();
    typeFilt.setCode(orgTreeTypeName);
    IdmTreeTypeDto treeType = treeTypeService.find(typeFilt, null).getContent().get(0);
    IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
    filter.setCode(rootNodeName);
    filter.setTreeTypeId(treeType.getId());
    List<IdmTreeNodeDto> roots = treeNodeService.find(filter, null).getContent();
    if (roots.size() == 0) {
        root = new IdmTreeNodeDto();
        root.setCode(rootNodeName);
        root.setName(rootNodeName);
        root.setTreeType(treeType.getId());
        root = treeNodeService.save(root);
    } else {
        root = roots.get(0);
    }
    // Department1
    node = new IdmTreeNodeDto();
    node.setCode(dep1NodeName);
    node.setName(dep1NodeName);
    node.setTreeType(treeType.getId());
    node.setParent(root.getId());
    node = treeNodeService.save(node);
    // Department2
    node = new IdmTreeNodeDto();
    node.setCode(dep2NodeName);
    node.setName(dep2NodeName);
    node.setTreeType(treeType.getId());
    node.setParent(root.getId());
    node = treeNodeService.save(node);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmTreeTypeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeTypeFilter)

Example 24 with IdmTreeNodeFilter

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

the class DefaultTreeSynchronizationServiceTest method provisioningE_DeleteAccount_IntegrityException.

@Test(expected = TreeNodeException.class)
public void provisioningE_DeleteAccount_IntegrityException() {
    IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
    filter.setProperty(NODE_NAME);
    filter.setValue("P1");
    IdmTreeNodeDto nodeRoot = treeNodeService.find(filter, null).getContent().get(0);
    Assert.assertNotNull(nodeRoot);
    // Delete IDM node (must invoke provisioning) .. We delete node with some
    // children ... must throw integrity exception
    // Generally we counts with provisioning on every node ... include children
    // (Recursively delete is not good idea!)
    treeNodeService.delete(nodeRoot);
}
Also used : IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 25 with IdmTreeNodeFilter

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

the class DefaultTreeSynchronizationServiceTest method syncCorellationAttribute.

@Test
public void syncCorellationAttribute() {
    this.getBean().deleteAllResourceData();
    this.getBean().initTreeData();
    SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
    configFilter.setName(SYNC_CONFIG_NAME);
    List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
    Assert.assertEquals(1, syncConfigs.size());
    AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
    Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
    IdmTreeTypeDto treeTypeOne = getHelper().createTreeType();
    IdmTreeTypeDto treeTypeTwo = getHelper().createTreeType();
    // Set tree type to the mapping
    SysSystemMappingDto mappingDto = DtoUtils.getEmbedded(syncConfigCustom, SysSyncConfig_.systemMapping.getName(), SysSystemMappingDto.class);
    mappingDto.setTreeType(treeTypeOne.getId());
    systemMappingService.save(mappingDto);
    // Set sync config
    syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE);
    syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK);
    syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
    syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
    syncConfigCustom.setRootsFilterScript(null);
    SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
    attributeMappingFilter.setSystemMappingId(syncConfigCustom.getSystemMapping());
    attributeMappingFilter.setIdmPropertyName(IdmTreeNode_.code.getName());
    // Set correlation attribute
    List<SysSystemAttributeMappingDto> attributes = attributeMappingService.find(attributeMappingFilter, null).getContent();
    Assert.assertEquals(1, attributes.size());
    SysSystemAttributeMappingDto correlationAttribute = attributes.get(0);
    syncConfigCustom.setCorrelationAttribute(correlationAttribute.getId());
    syncConfigService.save(syncConfigCustom);
    // Check state before sync
    // For first tree type
    IdmTreeNodeFilter nodeFilter = new IdmTreeNodeFilter();
    nodeFilter.setProperty(IdmTreeNode_.code.getName());
    nodeFilter.setValue("111");
    nodeFilter.setTreeTypeId(treeTypeOne.getId());
    List<IdmTreeNodeDto> nodes = treeNodeService.find(nodeFilter, null).getContent();
    Assert.assertEquals(0, nodes.size());
    // For second tree type
    nodeFilter.setTreeTypeId(treeTypeTwo.getId());
    nodes = treeNodeService.find(nodeFilter, null).getContent();
    Assert.assertEquals(0, nodes.size());
    IdmTreeNodeDto node = new IdmTreeNodeDto();
    node.setTreeType(treeTypeTwo.getId());
    node.setName("111");
    node.setCode(node.getName());
    node = treeNodeService.save(node);
    nodes = treeNodeService.find(nodeFilter, null).getContent();
    Assert.assertEquals(1, nodes.size());
    // Start sync
    helper.startSynchronization(syncConfigCustom);
    SysSyncLogFilter logFilter = new SysSyncLogFilter();
    logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
    List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
    Assert.assertEquals(1, logs.size());
    SysSyncLogDto log = logs.get(0);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
    actionLogFilter.setSynchronizationLogId(log.getId());
    List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
    boolean linkActionLogExists = actions.stream().filter(action -> {
        return SynchronizationActionType.LINK == action.getSyncAction();
    }).findFirst().isPresent();
    // Must be false, because node is in the different tree type!
    assertFalse(linkActionLogExists);
    // Delete log
    syncLogService.delete(log);
    treeNodeService.delete(node);
    // Create node for tree type One
    node = new IdmTreeNodeDto();
    node.setTreeType(treeTypeOne.getId());
    node.setName("111");
    node.setCode(node.getName());
    node = treeNodeService.save(node);
    nodeFilter.setTreeTypeId(treeTypeOne.getId());
    nodes = treeNodeService.find(nodeFilter, null).getContent();
    Assert.assertEquals(1, nodes.size());
    // Start sync again
    helper.startSynchronization(syncConfigCustom);
    logFilter = new SysSyncLogFilter();
    logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
    logs = syncLogService.find(logFilter, null).getContent();
    Assert.assertEquals(1, logs.size());
    log = logs.get(0);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    actionLogFilter = new SysSyncActionLogFilter();
    actionLogFilter.setSynchronizationLogId(log.getId());
    actions = syncActionLogService.find(actionLogFilter, null).getContent();
    SysSyncActionLogDto linkActionLog = actions.stream().filter(action -> {
        return SynchronizationActionType.LINK == action.getSyncAction();
    }).findFirst().get();
    // Must exists, because node is in the tree type One!
    assertNotNull(linkActionLog);
    assertEquals(1, linkActionLog.getOperationCount().intValue());
    SysSchemaObjectClassDto schemaObjectDto = DtoUtils.getEmbedded(mappingDto, SysSystemMapping_.objectClass.getName(), SysSchemaObjectClassDto.class);
    AccTreeAccountFilter treeAccountFilter = new AccTreeAccountFilter();
    treeAccountFilter.setSystemId(schemaObjectDto.getSystem());
    treeAccountFilter.setTreeNodeId(node.getId());
    List<AccTreeAccountDto> treeAccounts = treeAccountService.find(treeAccountFilter, null).getContent();
    assertEquals(1, treeAccounts.size());
    // Delete log
    syncLogService.delete(log);
}
Also used : SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) AccTreeAccountDto(eu.bcvsolutions.idm.acc.dto.AccTreeAccountDto) AccTreeAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccTreeAccountFilter) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter)35 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)30 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)20 Test (org.junit.Test)20 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)15 UUID (java.util.UUID)11 Transactional (org.springframework.transaction.annotation.Transactional)7 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)5 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)5 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)5 SysSyncLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter)4 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)3 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)3 TestTreeResource (eu.bcvsolutions.idm.acc.entity.TestTreeResource)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)3 List (java.util.List)3 Assert (org.junit.Assert)3