use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class IdentityFindPositionsTest method findManagers.
@Test
public void findManagers() {
IdmIdentityDto user = createAndSaveIdentity("test_position_01");
IdmIdentityDto user2 = createAndSaveIdentity("test_position_02");
IdmIdentityDto user3 = createAndSaveIdentity("test_position_03");
IdmIdentityDto user4 = createAndSaveIdentity("test_position_04");
IdmTreeTypeDto treeTypeFirst = new IdmTreeTypeDto();
treeTypeFirst.setCode("TEST_TYPE_CODE_FIRST");
treeTypeFirst.setName("TEST_TYPE_NAME_FIRST");
treeTypeFirst = treeTypeService.save(treeTypeFirst);
IdmTreeTypeDto treeTypeSecond = new IdmTreeTypeDto();
treeTypeSecond.setCode("TEST_TYPE_CODE_SECOND");
treeTypeSecond.setName("TEST_TYPE_NAME_SECOND");
treeTypeSecond = treeTypeService.save(treeTypeSecond);
// create root for second type
IdmTreeNodeDto nodeRootSec = new IdmTreeNodeDto();
nodeRootSec.setName("TEST_NODE_NAME_ROOT_SEC");
nodeRootSec.setCode("TEST_NODE_CODE_ROOT_SEC");
nodeRootSec.setTreeType(treeTypeSecond.getId());
nodeRootSec = treeNodeService.save(nodeRootSec);
// create root for first type
IdmTreeNodeDto nodeRoot = new IdmTreeNodeDto();
nodeRoot.setName("TEST_NODE_NAME_ROOT");
nodeRoot.setCode("TEST_NODE_CODE_ROOT");
nodeRoot.setTreeType(treeTypeFirst.getId());
nodeRoot = treeNodeService.save(nodeRoot);
// create one for first type
IdmTreeNodeDto nodeOne = new IdmTreeNodeDto();
nodeOne.setName("TEST_NODE_NAME_ONE");
nodeOne.setCode("TEST_NODE_CODE_ONE");
nodeOne.setParent(nodeRoot.getId());
nodeOne.setTreeType(treeTypeFirst.getId());
nodeOne = treeNodeService.save(nodeOne);
// create two for first type
IdmTreeNodeDto nodeTwo = new IdmTreeNodeDto();
nodeTwo.setName("TEST_NODE_NAME_TWO");
nodeTwo.setCode("TEST_NODE_CODE_TWO");
nodeTwo.setParent(nodeOne.getId());
nodeTwo.setTreeType(treeTypeFirst.getId());
nodeTwo = treeNodeService.save(nodeTwo);
createIdentityContract(user, null, nodeRoot);
createIdentityContract(user2, null, nodeOne);
createIdentityContract(user3, null, nodeOne);
createIdentityContract(user4, null, nodeTwo);
// createIdentityContract(user, manager3, null);
List<IdmIdentityDto> managersList = identityService.findAllManagers(user3.getId(), treeTypeFirst.getId());
assertEquals(1, managersList.size());
IdmIdentityDto manager = managersList.get(0);
assertEquals(user.getId(), manager.getId());
managersList = identityService.findAllManagers(user4.getId(), treeTypeFirst.getId());
assertEquals(2, managersList.size());
managersList = identityService.findAllManagers(user.getId(), treeTypeFirst.getId());
assertEquals(1, managersList.size());
createIdentityContract(user, null, nodeTwo);
managersList = identityService.findAllManagers(user.getId(), treeTypeFirst.getId());
assertEquals(2, managersList.size());
List<IdmIdentityDto> managersListSec = identityService.findAllManagers(user.getId(), treeTypeSecond.getId());
// user with superAdminRole
assertEquals(1, managersListSec.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeServiceIntegrationTest method testBadTreeTypeCreate.
@Test
public void testBadTreeTypeCreate() {
IdmTreeTypeDto parent1 = helper.createTreeType();
IdmTreeTypeDto parent2 = helper.createTreeType();
//
IdmTreeNodeDto node1 = helper.createTreeNode(parent1, null);
IdmTreeNodeDto node2 = helper.createTreeNode(parent1, node1);
IdmTreeNodeDto node3 = helper.createTreeNode(parent1, node2);
//
try {
helper.createTreeNode(parent2, node1);
Assert.fail();
} catch (TreeNodeException ex) {
Assert.assertTrue(ex.getMessage().contains("bad type"));
} catch (Exception e) {
Assert.fail();
}
//
try {
helper.createTreeNode(parent2, node3);
Assert.fail();
} catch (TreeNodeException ex) {
Assert.assertTrue(ex.getMessage().contains("bad type"));
} catch (Exception e) {
Assert.fail();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto 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());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeServiceIntegrationTest method testBadTreeTypeUpdate.
@Test
public void testBadTreeTypeUpdate() {
IdmTreeTypeDto parent1 = helper.createTreeType();
IdmTreeTypeDto parent2 = helper.createTreeType();
//
IdmTreeNodeDto node1 = helper.createTreeNode(parent1, null);
IdmTreeNodeDto node2 = helper.createTreeNode(parent1, node1);
IdmTreeNodeDto node3 = helper.createTreeNode(parent1, node2);
//
node3.setTreeType(parent2.getId());
try {
node3 = treeNodeService.save(node3);
Assert.fail();
} catch (TreeNodeException ex) {
Assert.assertTrue(ex.getMessage().contains("bad type"));
} catch (Exception e) {
Assert.fail();
}
//
node1.setTreeType(parent2.getId());
try {
node1 = treeNodeService.save(node1);
Assert.fail();
} catch (TreeNodeException ex) {
Assert.assertTrue(ex.getMessage().contains("bad type"));
} catch (Exception e) {
Assert.fail();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method testEvaluateScriptWithCreateEntityAndWorkWith.
@Test(expected = IdmSecurityException.class)
public void testEvaluateScriptWithCreateEntityAndWorkWith() {
IdmScriptDto subScript = new IdmScriptDto();
subScript.setCategory(IdmScriptCategory.DEFAULT);
subScript.setCode(getHelper().createName());
subScript.setName(getHelper().createName());
//
subScript.setScript(createTreeNodeScript(TREE_TYPE_CODE + "_2", TREE_TYPE_NAME + "_2"));
//
subScript = scriptService.save(subScript);
//
createAuthority(subScript.getId(), ScriptAuthorityType.CLASS_NAME, IdmTreeTypeDto.class.getName(), null);
//
createAuthority(subScript.getId(), ScriptAuthorityType.SERVICE, this.treeTypeService.getClass().getName(), "treeTypeService");
//
IdmScriptDto parent = new IdmScriptDto();
parent.setCategory(IdmScriptCategory.DEFAULT);
parent.setCode(getHelper().createName());
parent.setName(getHelper().createName());
//
StringBuilder scriptToEnd = new StringBuilder();
scriptToEnd.append("import eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto;\n");
scriptToEnd.append("IdmTreeTypeDto entity = new IdmTreeTypeDto();\n");
scriptToEnd.append("entity.setCode('" + TREE_TYPE_CODE + "_3');\n");
scriptToEnd.append("entity.setName('" + TREE_TYPE_NAME + "_3');\n");
scriptToEnd.append("return 'test';\n");
//
parent.setScript(createScriptThatCallAnother(subScript, IdmScriptCategory.DEFAULT, null, false, scriptToEnd.toString()));
parent = scriptService.saveInternal(parent);
//
groovyScriptService.evaluate(parent.getScript(), createParametersWithEvaluator(IdmScriptCategory.DEFAULT), createExtraAllowedClass());
//
fail();
}
Aggregations