Search in sources :

Example 31 with FindNodesByParentResult

use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.

the class PushNodesCommand method updateTargetChildrenMetaData.

private void updateTargetChildrenMetaData(final NodeBranchEntry nodeBranchEntry, PushNodesResult.Builder resultBuilder) {
    final Context context = ContextAccessor.current();
    final Context targetContext = ContextBuilder.create().authInfo(context.getAuthInfo()).branch(this.target).repositoryId(context.getRepositoryId()).build();
    final FindNodesByParentResult result = FindNodesByParentCommand.create(this).params(FindNodesByParentParams.create().parentPath(nodeBranchEntry.getNodePath()).childOrder(ChildOrder.from(NodeIndexPath.PATH + " asc")).build()).build().execute();
    final NodeBranchEntries childEntries = this.nodeStorageService.getBranchNodeVersions(result.getNodeIds(), false, InternalContext.from(ContextAccessor.current()));
    for (final NodeBranchEntry child : childEntries) {
        final NodeBranchEntry targetNodeEntry = this.nodeStorageService.getBranchNodeVersion(child.getNodeId(), InternalContext.from(targetContext));
        if (targetNodeEntry != null) {
            final Node childNode = GetNodeByIdCommand.create(this).id(child.getNodeId()).build().execute();
            this.nodeStorageService.move(StoreMovedNodeParams.create().nodeVersionId(child.getVersionId()).node(childNode).build(), InternalContext.from(targetContext));
            resultBuilder.addSuccess(child);
            updateTargetChildrenMetaData(child, resultBuilder);
        }
    }
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Example 32 with FindNodesByParentResult

use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.

the class ResolveInsertOrderValueCommand method execute.

public Long execute() {
    RefreshCommand.create().indexServiceInternal(this.indexServiceInternal).refreshMode(RefreshMode.SEARCH).build().execute();
    final ChildOrder childOrder = InsertManualStrategy.LAST.equals(insertManualStrategy) ? ChildOrder.reverseManualOrder() : ChildOrder.manualOrder();
    final FindNodesByParentResult findNodesByParentResult = doFindNodesByParent(FindNodesByParentParams.create().parentPath(parentPath).childOrder(childOrder).size(1).build());
    if (findNodesByParentResult.isEmpty()) {
        return NodeManualOrderValueResolver.START_ORDER_VALUE;
    } else {
        if (InsertManualStrategy.LAST.equals(insertManualStrategy)) {
            return insertAsLast(findNodesByParentResult);
        } else {
            return insertAsFirst(findNodesByParentResult);
        }
    }
}
Also used : ChildOrder(com.enonic.xp.index.ChildOrder) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Example 33 with FindNodesByParentResult

use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.

the class ResolveSyncWorkCommand method markChildrenForDeletion.

private void markChildrenForDeletion(final NodeComparison comparison) {
    final FindNodesByParentResult result = FindNodeIdsByParentCommand.create(this).size(NodeSearchService.GET_ALL_SIZE_FLAG).parentId(comparison.getNodeId()).childOrder(ChildOrder.from(NodeIndexPath.PATH + " asc")).recursive(true).build().execute();
    final NodeBranchEntries brancEntries = this.nodeStorageService.getBranchNodeVersions(result.getNodeIds(), false, InternalContext.from(ContextAccessor.current()));
    addToResult(NodeComparisons.create().addAll(brancEntries.stream().map((branchEntry) -> new NodeComparison(branchEntry, branchEntry, CompareStatus.PENDING_DELETE)).collect(Collectors.toSet())).build());
}
Also used : NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) NodeComparison(com.enonic.xp.node.NodeComparison) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Example 34 with FindNodesByParentResult

use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.

the class SetNodeStateCommand method setNodeStateWithChildren.

private Node setNodeStateWithChildren(final Node node, final SetNodeStateResult.Builder setNodeStateResultBuilder) {
    final Node updatedNode = setNodeState(node, setNodeStateResultBuilder);
    final FindNodesByParentResult result = doFindNodesByParent(FindNodesByParentParams.create().parentPath(node.path()).size(NodeSearchService.GET_ALL_SIZE_FLAG).build());
    final Nodes children = GetNodesByIdsCommand.create(this).ids(result.getNodeIds()).build().execute();
    for (final Node child : children) {
        setNodeStateWithChildren(child, setNodeStateResultBuilder);
    }
    return updatedNode;
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Nodes(com.enonic.xp.node.Nodes)

Example 35 with FindNodesByParentResult

use of com.enonic.xp.node.FindNodesByParentResult in project xp by enonic.

the class FindNodesByParentCommandTest method child_order_use_root_node.

@Test
public void child_order_use_root_node() throws Exception {
    CreateRootNodeCommand.create().params(CreateRootNodeParams.create().childOrder(ChildOrder.from("order ASC")).permissions(AccessControlList.of(AccessControlEntry.create().allowAll().principal(TEST_DEFAULT_USER.getKey()).build())).build()).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    final Node node1 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("node1")).name("node1").parent(NodePath.ROOT).data(createOrderProperty(4.0)).build());
    final Node node2 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("node2")).name("node2").parent(NodePath.ROOT).data(createOrderProperty(1.0)).build());
    final Node node3 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("node3")).name("node3").parent(NodePath.ROOT).data(createOrderProperty(3.0)).build());
    final FindNodesByParentResult result = findByParent(FindNodesByParentParams.create().parentPath(NodePath.ROOT).build());
    final Iterator<Node> iterator = GetNodesByIdsCommand.create().ids(result.getNodeIds()).indexServiceInternal(indexServiceInternal).storageService(storageService).searchService(searchService).build().execute().iterator();
    assertEquals(node2.id(), iterator.next().id());
    assertEquals(node3.id(), iterator.next().id());
    assertEquals(node1.id(), iterator.next().id());
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

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