use of com.enonic.xp.node.Node in project xp by enonic.
the class RenameNodeCommand method execute.
public MoveNodeResult execute() {
final NodeId nodeId = params.getNodeId();
final Node nodeToBeRenamed = doGetById(nodeId);
if (nodeToBeRenamed == null) {
throw new NodeNotFoundException("cannot rename node with id [" + nodeId + "]");
}
if (nodeToBeRenamed.isRoot()) {
throw new OperationNotPermittedException("Not allowed to rename root-node");
}
final NodePath parentPath = nodeToBeRenamed.parentPath().asAbsolute();
return MoveNodeCommand.create(this).id(params.getNodeId()).newParent(parentPath).newNodeName(params.getNewNodeName()).processor(params.getProcessor()).build().execute();
}
use of com.enonic.xp.node.Node 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();
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class ReorderChildNodesCommand method processParent.
private void processParent(final Node parentNode) {
final PropertyTree processedData = params.getProcessor().process(parentNode.data().copy());
if (!processedData.equals(parentNode.data())) {
final Node editedNode = Node.create(parentNode).data(processedData).timestamp(Instant.now(CLOCK)).build();
StoreNodeCommand.create(this).node(editedNode).build().execute();
}
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class SetNodeChildOrderCommand method orderChildNodes.
private void orderChildNodes(final Node parentNode) {
final SearchResult result = nodeSearchService.query(NodeQuery.create().parent(parentNode.path()).query(new QueryExpr(parentNode.getChildOrder().getOrderExpressions())).size(NodeSearchService.GET_ALL_SIZE_FLAG).batchSize(BATCH_SIZE).searchMode(SearchMode.SEARCH).build(), SingleRepoSearchSource.from(ContextAccessor.current()));
final NodeIds childNodeIds = NodeIds.from(result.getIds());
final List<NodeManualOrderValueResolver.NodeIdOrderValue> orderedNodeIds = NodeManualOrderValueResolver.resolve(childNodeIds);
for (final NodeManualOrderValueResolver.NodeIdOrderValue nodeIdOrderValue : orderedNodeIds) {
final Node node = doGetById(nodeIdOrderValue.getNodeId());
final Node editedNode = Node.create(node).manualOrderValue(nodeIdOrderValue.getManualOrderValue()).timestamp(Instant.now(CLOCK)).build();
StoreNodeCommand.create(this).node(editedNode).build().execute();
}
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class SetRootPermissionsCommand method execute.
public Node execute() {
final Node rootNode = doGetById(Node.ROOT_UUID);
if (rootNode == null) {
throw new NodeAccessException(ContextAccessor.current().getAuthInfo().getUser(), NodePath.ROOT, Permission.READ);
}
requireContextUserPermissionOrAdmin(Permission.WRITE_PERMISSIONS, rootNode);
return StoreNodeCommand.create(this).node(Node.create(rootNode).permissions(this.permissions).inheritPermissions(this.inheritPermissions).timestamp(Instant.now(CLOCK)).build()).build().execute();
}
Aggregations