Search in sources :

Example 11 with FindNodesByParentResult

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();
    }
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

Example 12 with FindNodesByParentResult

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();
    }
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

Example 13 with FindNodesByParentResult

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());
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

Example 14 with FindNodesByParentResult

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());
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

Example 15 with FindNodesByParentResult

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);
    }
}
Also used : Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Aggregations

FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)39 Node (com.enonic.xp.node.Node)28 Test (org.junit.jupiter.api.Test)17 NodeId (com.enonic.xp.node.NodeId)14 Nodes (com.enonic.xp.node.Nodes)9 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)5 Context (com.enonic.xp.context.Context)3 ContextAccessor (com.enonic.xp.context.ContextAccessor)3 NodeBranchEntries (com.enonic.xp.node.NodeBranchEntries)3 RefreshMode (com.enonic.xp.node.RefreshMode)3 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)3 ArchiveConstants (com.enonic.xp.archive.ArchiveConstants)2 Branch (com.enonic.xp.branch.Branch)2 ContentAccessException (com.enonic.xp.content.ContentAccessException)2 ContentConstants (com.enonic.xp.content.ContentConstants)2 ContentIds (com.enonic.xp.content.ContentIds)2 ContentInheritType (com.enonic.xp.content.ContentInheritType)2 ARCHIVED_BY (com.enonic.xp.content.ContentPropertyNames.ARCHIVED_BY)2 ARCHIVED_TIME (com.enonic.xp.content.ContentPropertyNames.ARCHIVED_TIME)2 ORIGINAL_NAME (com.enonic.xp.content.ContentPropertyNames.ORIGINAL_NAME)2