Search in sources :

Example 11 with NodeNotFoundException

use of com.enonic.xp.node.NodeNotFoundException 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 12 with NodeNotFoundException

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

the class SetActiveVersionCommand method execute.

public NodeVersionId execute() {
    final InternalContext context = InternalContext.from(ContextAccessor.current());
    final Node node = this.nodeStorageService.get(nodeId, nodeVersionId, context);
    if (node == null) {
        throw new NodeNotFoundException("Cannot find nodeVersion [" + this.nodeVersionId + "] in branch " + context.getBranch().getValue());
    }
    if (!node.id().equals(nodeId)) {
        throw new NodeNotFoundException("NodeVersionId [" + nodeVersionId + "] not a version of Node with id [" + nodeId + "]");
    }
    NodePermissionsResolver.requireContextUserPermissionOrAdmin(REQUIRED_PERMISSION, node);
    this.nodeStorageService.updateVersion(node, nodeVersionId, context);
    return nodeVersionId;
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) InternalContext(com.enonic.xp.repo.impl.InternalContext) Node(com.enonic.xp.node.Node)

Example 13 with NodeNotFoundException

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

the class RepositoryServiceImpl method pushRootNode.

private void pushRootNode(final Repository currentRepo, final Branch branch) {
    final Context context = ContextAccessor.current();
    final InternalContext internalContext = InternalContext.create(context).branch(RepositoryConstants.MASTER_BRANCH).build();
    final Node rootNode = this.nodeStorageService.get(Node.ROOT_UUID, internalContext);
    if (rootNode == null) {
        throw new NodeNotFoundException("Cannot find root-node in repository [" + currentRepo + "]");
    }
    this.nodeStorageService.push(rootNode, branch, internalContext);
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) InternalContext(com.enonic.xp.repo.impl.InternalContext) Node(com.enonic.xp.node.Node)

Example 14 with NodeNotFoundException

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

the class NodeStorageServiceImpl method updateMetadata.

@Override
public Node updateMetadata(final Node node, final InternalContext context) {
    final NodeBranchEntry nodeBranchEntry = this.branchService.get(node.id(), context);
    if (nodeBranchEntry == null) {
        throw new NodeNotFoundException("Cannot find node with id: " + node.id() + " in branch " + context.getBranch());
    }
    final NodeVersionId nodeVersionId = nodeBranchEntry.getVersionId();
    final NodeVersionKey nodeVersionKey = nodeBranchEntry.getNodeVersionKey();
    final StoreBranchMetadataParams storeBranchMetadataParams = StoreBranchMetadataParams.create().node(node).nodeVersionId(nodeVersionId).nodeVersionKey(nodeVersionKey).context(context).build();
    storeBranchMetadata(storeBranchMetadataParams);
    indexNode(node, nodeVersionId, context);
    return Node.create(node).nodeVersionId(nodeVersionId).build();
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeVersionId(com.enonic.xp.node.NodeVersionId) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Example 15 with NodeNotFoundException

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

the class NodeStorageServiceImpl method updateVersion.

@Override
public void updateVersion(final Node node, final NodeVersionId nodeVersionId, final InternalContext context) {
    // TODO Check
    final NodeVersionMetadata nodeVersionMetadata = this.versionService.getVersion(node.id(), nodeVersionId, context);
    if (nodeVersionMetadata == null) {
        throw new NodeNotFoundException("Cannot find node version with id: " + nodeVersionId);
    }
    this.branchService.store(NodeBranchEntry.create().nodeVersionId(nodeVersionId).nodeVersionKey(nodeVersionMetadata.getNodeVersionKey()).nodeId(node.id()).nodeState(node.getNodeState()).timestamp(node.getTimestamp()).nodePath(node.path()).build(), context);
    this.indexDataService.store(node, context);
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata)

Aggregations

NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)25 Node (com.enonic.xp.node.Node)13 NodeId (com.enonic.xp.node.NodeId)11 Test (org.junit.jupiter.api.Test)5 NodePath (com.enonic.xp.node.NodePath)4 NodeVersionId (com.enonic.xp.node.NodeVersionId)4 NodeQuery (com.enonic.xp.node.NodeQuery)3 OperationNotPermittedException (com.enonic.xp.node.OperationNotPermittedException)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)3 Content (com.enonic.xp.content.Content)2 ContentId (com.enonic.xp.content.ContentId)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)2 Nodes (com.enonic.xp.node.Nodes)2 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)2 InternalContext (com.enonic.xp.repo.impl.InternalContext)2 Principals (com.enonic.xp.security.Principals)2 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)1 Branch (com.enonic.xp.branch.Branch)1 MoveContentParams (com.enonic.xp.content.MoveContentParams)1