use of eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeDtoLookupByExample method lookup.
@Override
public IdmTreeNodeDto lookup(IdmTreeNodeDto example) {
IdmTreeNodeFilter nodeFilter = new IdmTreeNodeFilter();
nodeFilter.setCode(example.getCode());
//
IdmTreeTypeDto embeddedTreeType = DtoUtils.getEmbedded(example, IdmTreeNode_.treeType, IdmTreeTypeDto.class, null);
if (embeddedTreeType != null) {
// code has higher priority, if embedded object is available (can be used between different environments - e.g. in import)
nodeFilter.setTreeTypeCode(embeddedTreeType.getCode());
} else {
nodeFilter.setTreeTypeId(example.getTreeType());
}
//
Page<IdmTreeNodeDto> result = treeNodeService.find(nodeFilter, PageRequest.of(0, 1));
long count = result.getTotalElements();
// not found
if (count == 0) {
return null;
}
//
if (count > 1) {
LOG.trace("More result found [{}] for given example, returning null (~ not found by example).", count);
return null;
}
//
return result.getContent().get(0);
}
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);
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 && StringUtils.isNotEmpty((String) value)) {
// 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);
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 {
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;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeControllerRestTest method testFindByRootsAndChildrenByRest.
@Test
public void testFindByRootsAndChildrenByRest() {
try {
IdmTreeTypeDto treeType = getHelper().createTreeType();
IdmTreeNodeDto nodeOne = getHelper().createTreeNode(treeType, null);
IdmTreeNodeDto nodeTwo = getHelper().createTreeNode(treeType, nodeOne);
//
// roots
IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
filter.setTreeTypeId(treeType.getId());
String response = getMockMvc().perform(get(String.format("%s/search/roots", getBaseUrl())).with(authentication(getAdminAuthentication())).params(toQueryParams(filter)).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
//
List<IdmTreeNodeDto> results = toDtos(response);
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(nodeOne.getId())));
//
// children
filter = new IdmTreeNodeFilter();
filter.setParent(nodeOne.getId());
response = getMockMvc().perform(get(String.format("%s/search/children", getBaseUrl())).with(authentication(getAdminAuthentication())).params(toQueryParams(filter)).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
//
results = toDtos(response);
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(nodeTwo.getId())));
} catch (Exception ex) {
throw new RuntimeException("Failed to find entities", ex);
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeControllerRestTest method testFindChildrenRecursivelyWithoutTreeTypeSpecified.
@Test
@Transactional
public void testFindChildrenRecursivelyWithoutTreeTypeSpecified() {
IdmTreeNodeDto rootOne;
IdmTreeNodeDto childOne;
try {
getHelper().loginAdmin();
//
IdmTreeTypeDto treeTypeOne = getHelper().createTreeType();
IdmTreeTypeDto treeTypeTwo = getHelper().createTreeType();
//
rootOne = getHelper().createTreeNode(treeTypeOne, null);
childOne = getHelper().createTreeNode(treeTypeOne, rootOne);
IdmTreeNodeDto rootTwo = getHelper().createTreeNode(treeTypeTwo, null);
getHelper().createTreeNode(treeTypeTwo, rootTwo);
} finally {
getHelper().logout();
}
//
IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
filter.setParent(rootOne.getId());
//
List<IdmTreeNodeDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(childOne, results.get(0));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeControllerRestTest method testFilters.
@Test
@Transactional
public void testFilters() {
// ****** PREPARE DATA ******
//
UUID t1Id = null;
UUID t2Id = null;
UUID r1Uuid = null;
UUID n1Uuid = null;
UUID n5Uuid = null;
UUID r2Uuid = null;
UUID n12Uuid = null;
try {
getHelper().loginAdmin();
//
IdmTreeTypeDto t1 = getHelper().createTreeType("TYPE1");
IdmTreeTypeDto t2 = getHelper().createTreeType("TYPE2");
t1Id = t1.getId();
t2Id = t2.getId();
/*
o r1
/ \
n1 o o n3
/ \
n2 o o n4
\
o n5
*/
IdmTreeNodeDto r1 = getHelper().createTreeNode(t1, "ROOT1", null);
IdmTreeNodeDto n1 = getHelper().createTreeNode(t1, "NODE1", r1);
getHelper().createTreeNode(t1, "NODE2", n1);
getHelper().createTreeNode(t1, "NODE3", r1);
IdmTreeNodeDto n4 = getHelper().createTreeNode(t1, "NODE4", n1);
IdmTreeNodeDto n5 = getHelper().createTreeNode(t1, "NODE5", n4);
/*
o r2
/
n12 o-o n11
*/
IdmTreeNodeDto r2 = getHelper().createTreeNode(t2, "ROOT2", null);
IdmTreeNodeDto n11 = getHelper().createTreeNode(t2, "NODE11", r2);
IdmTreeNodeDto n12 = getHelper().createTreeNode(t2, "NODE12", n11);
//
r1Uuid = r1.getId();
n1Uuid = n1.getId();
n5Uuid = n5.getId();
r2Uuid = r2.getId();
n12Uuid = n12.getId();
} finally {
getHelper().logout();
}
//
// ******* TEST *******
//
final IdmTreeNodeFilter t1Flter = new IdmTreeNodeFilter();
t1Flter.setTreeTypeId(t1Id);
List<IdmTreeNodeDto> result = find(t1Flter);
Assert.assertEquals(6, result.size());
//
final IdmTreeNodeFilter t2Flter = new IdmTreeNodeFilter();
t2Flter.setTreeTypeId(t2Id);
result = find(t2Flter);
Assert.assertEquals(3, result.size());
//
// Subtrees
//
final IdmTreeNodeFilter subTreeFilter1 = new IdmTreeNodeFilter();
subTreeFilter1.setParent(n1Uuid);
subTreeFilter1.setTreeTypeId(t1Id);
subTreeFilter1.setRecursively(true);
result = find(subTreeFilter1);
Assert.assertEquals(3, result.size());
//
final IdmTreeNodeFilter subTreeFilter2 = new IdmTreeNodeFilter();
subTreeFilter2.setParent(n1Uuid);
subTreeFilter2.setRecursively(false);
result = find(subTreeFilter2);
Assert.assertEquals(2, result.size());
//
final IdmTreeNodeFilter subTreeFilter3 = new IdmTreeNodeFilter();
subTreeFilter3.setParent(r2Uuid);
subTreeFilter3.setRecursively(false);
result = find(subTreeFilter3);
Assert.assertEquals(1, result.size());
//
final IdmTreeNodeFilter subTreeFilter4 = new IdmTreeNodeFilter();
subTreeFilter4.setParent(r2Uuid);
subTreeFilter4.setTreeTypeId(t2Id);
subTreeFilter4.setRecursively(true);
result = find(subTreeFilter4);
Assert.assertEquals(2, result.size());
//
final IdmTreeNodeFilter subTreeFilter5 = new IdmTreeNodeFilter();
subTreeFilter5.setParent(n12Uuid);
subTreeFilter5.setTreeTypeId(t2Id);
subTreeFilter5.setRecursively(true);
result = find(subTreeFilter5);
Assert.assertEquals(0, result.size());
//
final IdmTreeNodeFilter subTreeFilter6 = new IdmTreeNodeFilter();
subTreeFilter6.setParent(n12Uuid);
subTreeFilter6.setTreeTypeId(t2Id);
subTreeFilter6.setRecursively(false);
result = find(subTreeFilter6);
Assert.assertEquals(0, result.size());
//
// Fulltext
//
final IdmTreeNodeFilter fullTextFilter1 = new IdmTreeNodeFilter();
fullTextFilter1.setText("NODE5");
result = find(fullTextFilter1);
Assert.assertEquals(1, result.size());
Assert.assertEquals(n5Uuid, result.get(0).getId());
//
final IdmTreeNodeFilter fullTextFilter2 = new IdmTreeNodeFilter();
fullTextFilter2.setText("NODE");
fullTextFilter2.setTreeTypeId(t1Id);
result = find(fullTextFilter2);
Assert.assertEquals(5, result.size());
//
final IdmTreeNodeFilter fullTextFilter3 = new IdmTreeNodeFilter();
fullTextFilter3.setText("odE");
fullTextFilter3.setTreeTypeId(t1Id);
result = find(fullTextFilter3);
Assert.assertEquals(5, result.size());
//
// Property - value pairs
//
final IdmTreeNodeFilter dynPropFilter1 = new IdmTreeNodeFilter();
dynPropFilter1.setProperty("name");
dynPropFilter1.setValue("ROOT1");
result = find(dynPropFilter1);
Assert.assertEquals(1, result.size());
Assert.assertEquals(r1Uuid, result.get(0).getId());
//
final IdmTreeNodeFilter dynPropFilter2 = new IdmTreeNodeFilter();
dynPropFilter2.setProperty("code");
dynPropFilter2.setValue("ROOT2");
result = find(dynPropFilter2);
Assert.assertEquals(1, result.size());
Assert.assertEquals(r2Uuid, result.get(0).getId());
}
Aggregations