use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class SetNodeChildOrderCommandTest method order_manual_initial_as_previous.
@Test
public void order_manual_initial_as_previous() throws Exception {
final Node node = createParentNode();
createChildNodes(node);
// Order initially by name
setChildOrder(node, ChildOrder.create().add(FieldOrderExpr.create(NodeIndexPath.NAME, OrderExpr.Direction.ASC)).build());
refresh();
// Now set order manual
setChildOrder(node, ChildOrder.create().add(FieldOrderExpr.create(NodeIndexPath.MANUAL_ORDER_VALUE, OrderExpr.Direction.DESC)).build());
refresh();
final FindNodesByParentResult result = findChildren(node);
// Verify same order as initial ordering, name desc
String previousName = "";
Long previousOrderValue = null;
for (final NodeId n : result.getNodeIds()) {
final Node currentNode = getNode(n);
final boolean largerThanPreviousName = previousName.compareTo(currentNode.name().toString()) < 0;
assertTrue(Objects.equals(previousName, "") || largerThanPreviousName, "Wrong value, previousValue = " + previousName + ", current = " + currentNode.name());
assertTrue(previousOrderValue == null || currentNode.getManualOrderValue() < previousOrderValue, "Wrong orderValue, previousOrderValue = " + previousOrderValue + ", current = " + currentNode.getManualOrderValue());
previousOrderValue = currentNode.getManualOrderValue();
previousName = currentNode.name().toString();
}
}
use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class ReorderChildNodeCommandTest method move_last.
@Test
public void move_last() throws Exception {
final Node parentNode = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build());
createChildNodes(parentNode);
setChildOrder(parentNode, NodeIndexPath.NAME, OrderExpr.Direction.ASC);
setChildOrder(parentNode, NodeIndexPath.MANUAL_ORDER_VALUE, OrderExpr.Direction.DESC);
// current node order: a,b,c,d,e,f
ReorderChildNodeCommand.create().parentNode(getNodeById(parentNode.id())).nodeToMove(getNodeById(NodeId.from("c"))).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
refresh();
final FindNodesByParentResult reOrderedResult = findByParent(FindNodesByParentParams.create().parentPath(parentNode.path()).build());
// updated node order: a,b,d,e,f,c
final Iterator<NodeId> iterator = reOrderedResult.getNodeIds().iterator();
assertEquals("a", iterator.next().toString());
assertEquals("b", iterator.next().toString());
assertEquals("d", iterator.next().toString());
assertEquals("e", iterator.next().toString());
assertEquals("f", iterator.next().toString());
assertEquals("c", iterator.next().toString());
}
use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class ApplicationRepoServiceImpl method getApplications.
@Override
public Nodes getApplications() {
this.nodeService.refresh(RefreshMode.ALL);
final FindNodesByParentResult byParent = ApplicationHelper.runAsAdmin(() -> this.nodeService.findByParent(FindNodesByParentParams.create().parentPath(APPLICATION_PATH).build()));
return this.nodeService.getByIds(byParent.getNodeIds());
}
use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class FindContentIdsByParentCommand method execute.
FindContentIdsByParentResult execute() {
final FindNodesByParentResult result = nodeService.findByParent(createFindNodesByParentParams());
final ContentIds contentIds = ContentIds.from(result.getNodeIds().getAsStrings());
return FindContentIdsByParentResult.create().contentIds(contentIds).totalHits(result.getTotalHits()).hits(result.getHits()).build();
}
use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class NodeServiceImpl method findByParent.
@Override
public FindNodesByParentResult findByParent(final FindNodesByParentParams params) {
final Trace trace = Tracer.newTrace("node.findByParent");
if (trace == null) {
return executeFindByParent(params);
}
return Tracer.trace(trace, () -> {
trace.put("parent", params.getParentPath() != null ? params.getParentPath() : params.getParentId());
trace.put("from", params.getFrom());
trace.put("size", params.getSize());
final FindNodesByParentResult result = executeFindByParent(params);
trace.put("hits", result.getTotalHits());
return result;
});
}
Aggregations