Search in sources :

Example 11 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 12 with IdmTreeNodeFilter

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

Example 13 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)

Aggregations

IdmTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter)13 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)12 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)10 Test (org.junit.Test)10 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)4 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)3 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)3 TestTreeResource (eu.bcvsolutions.idm.acc.entity.TestTreeResource)3 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)2 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)2 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)2 SysSyncActionLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter)2 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)2 SysSyncItemLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter)2 SysSyncLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter)2 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)1 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)1 CorrelationFilter (eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter)1 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)1