Search in sources :

Example 61 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class CreateNodeCommand method execute.

public Node execute() {
    Preconditions.checkNotNull(params.getParent(), "Path of parent Node must be specified");
    Preconditions.checkArgument(params.getParent().isAbsolute(), "Path to parent Node must be absolute: " + params.getParent());
    NodeHelper.runAsAdmin(this::verifyNotExistsAlready);
    final Node parentNode = NodeHelper.runAsAdmin(this::verifyParentExists);
    if (parentNode == null) {
        throw new NodeNotFoundException("Parent node to node with name '" + params.getName() + "' with parent path '" + params.getParent() + "' not found");
    }
    requireContextUserPermission(Permission.CREATE, parentNode);
    final PrincipalKey user = getCurrentPrincipalKey();
    final AccessControlList permissions = getAccessControlEntries(user);
    final Long manualOrderValue = NodeHelper.runAsAdmin(() -> resolvePotentialManualOrderValue(parentNode));
    final AttachedBinaries attachedBinaries = storeAndAttachBinaries();
    final Node.Builder nodeBuilder = Node.create().id(this.params.getNodeId() != null ? params.getNodeId() : new NodeId()).parentPath(params.getParent()).name(NodeName.from(params.getName())).data(params.getData()).indexConfigDocument(params.getIndexConfigDocument()).childOrder(params.getChildOrder() != null ? params.getChildOrder() : ChildOrder.defaultOrder()).manualOrderValue(manualOrderValue).permissions(permissions).inheritPermissions(params.inheritPermissions()).nodeType(params.getNodeType() != null ? params.getNodeType() : NodeType.DEFAULT_NODE_COLLECTION).attachedBinaries(attachedBinaries).timestamp(this.timestamp != null ? this.timestamp : Instant.now(CLOCK));
    final Node newNode = nodeBuilder.build();
    return StoreNodeCommand.create(this).node(newNode).updateMetadataOnly(false).build().execute();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) AttachedBinaries(com.enonic.xp.node.AttachedBinaries) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 62 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class CreateNodeCommand method verifyNotExistsAlready.

private void verifyNotExistsAlready() {
    if (this.params.getNodeId() != null) {
        final Node existingNode = doGetById(this.params.getNodeId());
        if (existingNode != null) {
            throw new NodeIdExistsException(existingNode.id());
        }
    }
    NodePath nodePath = NodePath.create(params.getParent(), params.getName()).build();
    CheckNodeExistsCommand.create(this).nodePath(nodePath).throwIfExists().build().execute();
}
Also used : NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath)

Example 63 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class DeleteNodeByPathCommand method execute.

NodeBranchEntries execute() {
    final Context context = ContextAccessor.current();
    final Node node = GetNodeByPathCommand.create(this).nodePath(nodePath).build().execute();
    return node != null ? deleteNodeWithChildren(node, context) : NodeBranchEntries.empty();
}
Also used : Context(com.enonic.xp.context.Context) Node(com.enonic.xp.node.Node)

Example 64 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class DuplicateNodeCommand method storeChildNodes.

private void storeChildNodes(final Node originalParent, final Node newParent, final NodeReferenceUpdatesHolder.Builder builder) {
    final FindNodesByParentResult findNodesByParentResult = doFindNodesByParent(FindNodesByParentParams.create().parentPath(originalParent.path()).from(0).size(NodeSearchService.GET_ALL_SIZE_FLAG).build());
    final Nodes children = GetNodesByIdsCommand.create(this).ids(findNodesByParentResult.getNodeIds()).build().execute();
    for (final Node node : children) {
        final CreateNodeParams.Builder paramsBuilder = CreateNodeParams.from(node).parent(newParent.path());
        decideInsertStrategy(originalParent, node, paramsBuilder);
        attachBinaries(node, paramsBuilder);
        final CreateNodeParams originalParams = paramsBuilder.build();
        final CreateNodeParams processedParams = executeProcessors(originalParams);
        final Node newChildNode = CreateNodeCommand.create(this).params(processedParams).binaryService(this.binaryService).build().execute();
        builder.add(node.id(), newChildNode.id());
        result.addChild(newChildNode);
        nodeDuplicated(1);
        storeChildNodes(node, newChildNode, builder);
    }
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Nodes(com.enonic.xp.node.Nodes)

Example 65 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class DeleteNodeByIdCommand method execute.

public NodeBranchEntries execute() {
    final Context context = ContextAccessor.current();
    final Node node = doGetById(nodeId);
    return node != null ? deleteNodeWithChildren(node, context, deleteNodeListener) : NodeBranchEntries.empty();
}
Also used : Context(com.enonic.xp.context.Context) 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