use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeService method toPredicates.
@Override
protected List<Predicate> toPredicates(Root<IdmTreeNode> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmTreeNodeFilter filter) {
List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
// fulltext
if (!StringUtils.isEmpty(filter.getText())) {
predicates.add(builder.or(builder.like(builder.lower(root.get(IdmTreeNode_.code)), "%" + filter.getText().toLowerCase() + "%"), builder.like(builder.lower(root.get(IdmTreeNode_.name)), "%" + filter.getText().toLowerCase() + "%")));
}
// tree type identifier
if (filter.getTreeTypeId() != null) {
predicates.add(builder.equal(root.get(IdmTreeNode_.treeType).get(AbstractEntity_.id), filter.getTreeTypeId()));
}
// tree type code
String treeTypeCode = filter.getTreeTypeCode();
if (StringUtils.isNotEmpty(treeTypeCode)) {
predicates.add(builder.equal(root.get(IdmTreeNode_.treeType).get(IdmTreeType_.code), treeTypeCode));
}
// parent node
UUID parent = filter.getParent();
if (parent != null) {
if (filter.isRecursively()) {
// forest index needs tree type => same numbers in different trees
Subquery<IdmTreeType> subqueryTreeType = query.subquery(IdmTreeType.class);
Root<IdmTreeNode> subRootTreeType = subqueryTreeType.from(IdmTreeNode.class);
subqueryTreeType.select(subRootTreeType.get(IdmTreeNode_.treeType));
subqueryTreeType.where(builder.equal(subRootTreeType.get(IdmTreeNode_.id), parent));
//
Subquery<IdmTreeNode> subquery = query.subquery(IdmTreeNode.class);
Root<IdmTreeNode> subRoot = subquery.from(IdmTreeNode.class);
subquery.select(subRoot);
Join<IdmTreeNode, IdmForestIndexEntity> forestIndexPath = subRoot.join(IdmTreeNode_.forestIndex);
subquery.where(builder.and(builder.equal(subRoot.get(IdmTreeNode_.id), parent), // join tree type
builder.equal(root.get(IdmTreeNode_.treeType), subqueryTreeType), // Remember that between clause looks like this a >= x <= b, where a and b are boundaries, in our case lft+1 and rgt-1.
builder.between(root.join(IdmTreeNode_.forestIndex).get(IdmForestIndexEntity_.lft), builder.sum(forestIndexPath.get(IdmForestIndexEntity_.lft), 1L), builder.diff(forestIndexPath.get(IdmForestIndexEntity_.rgt), 1L))));
predicates.add(builder.exists(subquery));
} else {
predicates.add(builder.equal(root.get(IdmTreeNode_.parent).get(AbstractEntity_.id), parent));
}
}
// default tree type
if (filter.getDefaultTreeType() != null) {
IdmTreeTypeDto defaultTreeType = treeTypeService.getDefaultTreeType();
if (defaultTreeType == null) {
// nothing to find
predicates.add(builder.disjunction());
} else {
predicates.add(builder.equal(root.get(IdmTreeNode_.treeType).get(IdmTreeType_.id), defaultTreeType.getId()));
}
}
// roots
Boolean roots = filter.getRoots();
if (roots != null) {
if (roots) {
predicates.add(builder.isNull(root.get(IdmTreeNode_.parent)));
} else {
predicates.add(builder.isNotNull(root.get(IdmTreeNode_.parent)));
}
}
//
return predicates;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeTypeService method getConfigurations.
@Override
@Transactional(readOnly = true)
public List<IdmConfigurationDto> getConfigurations(UUID treeTypeId) {
Assert.notNull(treeTypeId, "Tree type identifier is required.");
IdmTreeTypeDto treeType = get(treeTypeId);
Assert.notNull(treeType, "Tree type is required.");
//
return new ArrayList<>(configurationService.getConfigurations(getConfigurationPrefix(treeType.getCode())).values());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityControllerRestTest method testFindByTreeNodeRecursively.
@Test
public void testFindByTreeNodeRecursively() {
IdmTreeTypeDto treeTypeOne = getHelper().createTreeType();
IdmTreeTypeDto treeTypeTwo = getHelper().createTreeType();
IdmTreeNodeDto treeNodeOne = getHelper().createTreeNode(treeTypeOne, null);
IdmTreeNodeDto treeNodeOneSub = getHelper().createTreeNode(treeTypeOne, treeNodeOne);
IdmTreeNodeDto treeNodeTwo = getHelper().createTreeNode(treeTypeTwo, null);
IdmTreeNodeDto treeNodeTwoSub = getHelper().createTreeNode(treeTypeTwo, treeNodeTwo);
//
IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
getHelper().createContract(identityOne, treeNodeOneSub);
//
// FIXME: map parameter values in filter into data
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.add("treeNodeId", treeNodeTwo.getId().toString());
parameters.add("recursively", Boolean.TRUE.toString());
List<IdmIdentityDto> identities = find(parameters);
//
Assert.assertTrue(identities.isEmpty());
//
IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
getHelper().createContract(identityTwo, treeNodeTwoSub);
//
identities = find(parameters);
//
Assert.assertEquals(1, identities.size());
Assert.assertTrue(identities.stream().anyMatch(i -> i.getId().equals(identityTwo.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class TreeNodeAndTypeRestTest method addChildrenToParent.
@Test
public void addChildrenToParent() {
IdmTreeTypeDto type = getHelper().createTreeType();
IdmTreeNodeDto node1 = getHelper().createTreeNode(type, null);
IdmTreeNodeDto node2 = getHelper().createTreeNode(type, node1);
IdmTreeNodeDto node3 = getHelper().createTreeNode(type, node2);
IdmTreeNodeDto node4 = getHelper().createTreeNode(type, node3);
// set parent of node4 to his children
Map<String, String> body = new HashMap<>();
body.put("id", node2.getId().toString());
body.put("code", "TEST_NODE_2_update");
body.put("name", "TEST_NODE_2_update");
body.put("treeType", node4.getTreeType().toString());
body.put("parent", node4.getId().toString());
String jsonContent = toJson(body);
int status = 0;
Exception ex = null;
try {
status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes").with(authentication(getAdminAuthentication())).content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
} catch (Exception e) {
ex = e;
}
assertNull(ex);
assertEquals(400, status);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class TreeNodeAndTypeRestTest method changeType.
@Test
public void changeType() {
IdmTreeTypeDto type = getHelper().createTreeType();
IdmTreeTypeDto type2 = getHelper().createTreeType();
// save node trought rest
Map<String, String> body = new HashMap<>();
body.put("code", getHelper().createName());
body.put("name", getHelper().createName());
body.put("treeType", type.getId().toString());
String jsonContent = toJson(body);
int status = 0;
Exception ex = null;
// test save without privileges
try {
status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes").content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
} catch (Exception e) {
ex = e;
}
assertNull(ex);
assertEquals(403, status);
// test with privileges
try {
status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes").with(authentication(getAdminAuthentication())).content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
} catch (Exception e) {
ex = e;
}
assertNull(ex);
assertEquals(201, status);
Page<IdmTreeNode> nodes = this.treeNodeRepository.findChildren(type.getId(), null, PageRequest.of(0, 1));
assertFalse(nodes.getContent().isEmpty());
IdmTreeNode node = nodes.getContent().get(0);
// change treeType
body.put("id", node.getId().toString());
body.put("name", node.getName() + "_update");
body.put("treeType", type2.getId().toString());
jsonContent = toJson(body);
status = 0;
ex = null;
try {
status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes/").with(authentication(getAdminAuthentication())).content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
} catch (Exception e) {
ex = e;
}
assertEquals(400, status);
assertNull(ex);
}
Aggregations