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);
}
}
}
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);
}
}
}
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());
}
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;
}
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());
}
Aggregations