Search in sources :

Example 26 with FindNodesByParentResult

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();
    }
}
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 27 with FindNodesByParentResult

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());
}
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 28 with FindNodesByParentResult

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

Example 29 with FindNodesByParentResult

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();
}
Also used : FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) ContentIds(com.enonic.xp.content.ContentIds)

Example 30 with FindNodesByParentResult

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;
    });
}
Also used : Trace(com.enonic.xp.trace.Trace) 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