use of com.enonic.xp.node.ReorderChildNodeParams in project xp by enonic.
the class ReorderChildNodesCommand method execute.
public ReorderChildNodesResult execute() {
final ReorderChildNodesResult.Builder result = ReorderChildNodesResult.create();
final List<Node> parents = new ArrayList<>();
for (final ReorderChildNodeParams reorderChildNodeParams : params) {
RefreshCommand.create().refreshMode(RefreshMode.SEARCH).indexServiceInternal(this.indexServiceInternal).build().execute();
final Node nodeToMove = doGetById(reorderChildNodeParams.getNodeId());
final Node nodeToMoveBefore = reorderChildNodeParams.getMoveBefore() == null ? null : doGetById(reorderChildNodeParams.getMoveBefore());
final Node parentNode = parents.stream().filter(node -> node.path().equals(nodeToMove.parentPath())).findAny().orElse(GetNodeByPathCommand.create(this).nodePath(nodeToMove.parentPath()).build().execute());
final Node reorderedNode = ReorderChildNodeCommand.create().indexServiceInternal(this.indexServiceInternal).searchService(this.nodeSearchService).storageService(this.nodeStorageService).parentNode(parentNode).nodeToMove(nodeToMove).nodeToMoveBefore(nodeToMoveBefore).build().execute();
result.addNodeId(reorderedNode.id());
if (parents.stream().noneMatch(parent -> parent.id().equals(parentNode.id()))) {
parents.add(parentNode);
}
}
parents.forEach(this::processParent);
parents.forEach(result::addParentNode);
return result.build();
}
Aggregations