Search in sources :

Example 1 with ReorderChildNodeParams

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();
}
Also used : Node(com.enonic.xp.node.Node) ArrayList(java.util.ArrayList) ReorderChildNodeParams(com.enonic.xp.node.ReorderChildNodeParams) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult)

Aggregations

Node (com.enonic.xp.node.Node)1 ReorderChildNodeParams (com.enonic.xp.node.ReorderChildNodeParams)1 ReorderChildNodesResult (com.enonic.xp.node.ReorderChildNodesResult)1 ArrayList (java.util.ArrayList)1