Search in sources :

Example 81 with Node

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();
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) OperationNotPermittedException(com.enonic.xp.node.OperationNotPermittedException) NodePath(com.enonic.xp.node.NodePath)

Example 82 with Node

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

Example 83 with Node

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();
    }
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node)

Example 84 with Node

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();
    }
}
Also used : QueryExpr(com.enonic.xp.query.expr.QueryExpr) NodeIds(com.enonic.xp.node.NodeIds) Node(com.enonic.xp.node.Node) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 85 with Node

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();
}
Also used : NodeAccessException(com.enonic.xp.node.NodeAccessException) Node(com.enonic.xp.node.Node)

Aggregations

Node (com.enonic.xp.node.Node)521 Test (org.junit.jupiter.api.Test)371 PropertyTree (com.enonic.xp.data.PropertyTree)114 NodeId (com.enonic.xp.node.NodeId)52 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)51 NodePath (com.enonic.xp.node.NodePath)45 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)42 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)34 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)32 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)29 NodeQuery (com.enonic.xp.node.NodeQuery)27 AccessControlList (com.enonic.xp.security.acl.AccessControlList)27 BinaryReference (com.enonic.xp.util.BinaryReference)26 ByteSource (com.google.common.io.ByteSource)24 Content (com.enonic.xp.content.Content)23 PropertySet (com.enonic.xp.data.PropertySet)20 NodeIds (com.enonic.xp.node.NodeIds)18 Context (com.enonic.xp.context.Context)17 InternalContext (com.enonic.xp.repo.impl.InternalContext)17 Application (com.enonic.xp.app.Application)16