use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class SetNodeChildOrderCommandTest method order_by_data_value.
@Test
public void order_by_data_value() throws Exception {
final FindNodesByParentResult result = createNodeAndReturnOrderedChildren(IndexPath.from("displayName"), OrderExpr.Direction.ASC);
String previousName = "";
for (final NodeId n : result.getNodeIds()) {
final Node node = getNode(n);
final boolean smallerThanPreviousName = previousName.compareTo(node.name().toString()) < 0;
assertTrue(Objects.equals(previousName, "") || smallerThanPreviousName);
previousName = node.name().toString();
}
}
use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class SetNodeChildOrderCommandTest method order_manual.
@Test
public void order_manual() throws Exception {
final Node node = createParentNode();
createChildNodes(node);
setChildOrder(node, ChildOrder.create().add(FieldOrderExpr.create(NodeIndexPath.MANUAL_ORDER_VALUE, OrderExpr.Direction.ASC)).build());
refresh();
final FindNodesByParentResult result = findChildren(node);
Long previousOrderValue = null;
for (final NodeId n : result.getNodeIds()) {
final Node currentNode = getNode(n);
assertTrue(previousOrderValue == null || currentNode.getManualOrderValue() > previousOrderValue, "Wrong orderValue, previousOrderValue = " + previousOrderValue + ", current = " + currentNode.getManualOrderValue());
previousOrderValue = currentNode.getManualOrderValue();
}
}
use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class ReorderChildNodeCommandTest method move_first.
@Test
public void move_first() 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"))).nodeToMoveBefore(getNodeById(NodeId.from("a"))).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: c,a,b,d,e,f
final Iterator<NodeId> iterator = reOrderedResult.getNodeIds().iterator();
assertEquals("c", iterator.next().toString());
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());
}
use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class ReorderChildNodeCommandTest method move_in_between.
@Test
public void move_in_between() 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"))).nodeToMoveBefore(getNodeById(NodeId.from("b"))).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,c,b,d,e,f
final Iterator<NodeId> iterator = reOrderedResult.getNodeIds().iterator();
assertEquals("a", iterator.next().toString());
assertEquals("c", iterator.next().toString());
assertEquals("b", iterator.next().toString());
assertEquals("d", iterator.next().toString());
assertEquals("e", iterator.next().toString());
assertEquals("f", iterator.next().toString());
}
use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.
the class RepoDumper method dumpBranch.
private void dumpBranch(final BranchDumpResult.Builder dumpResult, Consumer<NodeId> nodeIdsAccumulator) {
final Node rootNode = this.nodeService.getRoot();
final FindNodesByParentResult children = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(rootNode.id()).recursive(true).childOrder(ChildOrder.from("_path asc")).build());
final Branch branch = ContextAccessor.current().getBranch();
this.listener.dumpingBranch(repository.getId(), branch, children.getTotalHits() + 1);
LOG.info("Dumping repository [{}], branch [{}]", repository.getId(), branch);
doDumpNode(rootNode.id(), dumpResult);
nodeIdsAccumulator.accept(rootNode.id());
for (final NodeId child : children.getNodeIds()) {
doDumpNode(child, dumpResult);
nodeIdsAccumulator.accept(child);
}
}
Aggregations