Search in sources :

Example 1 with OperationNotPermittedException

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

the class AbstractDeleteNodeCommand method deleteNodeWithChildren.

NodeBranchEntries deleteNodeWithChildren(final Node node, final Context context, final DeleteNodeListener deleteNodeListener) {
    if (node.isRoot() && !allowDeleteRootNode) {
        throw new OperationNotPermittedException("Not allowed to delete root-node");
    }
    doRefresh();
    final NodeBranchEntries nodesToBeDeleted = newResolveNodesToDelete(node);
    final NodeIds nodeIds = NodeIds.from(nodesToBeDeleted.getKeys());
    final boolean allHasPermissions = NodesHasPermissionResolver.create(this).nodeIds(nodeIds).permission(Permission.DELETE).build().execute();
    if (!allHasPermissions) {
        throw new NodeAccessException(context.getAuthInfo().getUser(), node.path(), Permission.DELETE);
    }
    for (final List<NodeId> keysBatch : Iterables.partition(nodeIds, BATCH_SIZE)) {
        this.nodeStorageService.delete(NodeIds.from(keysBatch), InternalContext.from(context));
        if (deleteNodeListener != null) {
            deleteNodeListener.nodesDeleted(keysBatch.size());
        }
    }
    doRefresh();
    return nodesToBeDeleted;
}
Also used : NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) NodeAccessException(com.enonic.xp.node.NodeAccessException) NodeIds(com.enonic.xp.node.NodeIds) NodeId(com.enonic.xp.node.NodeId) OperationNotPermittedException(com.enonic.xp.node.OperationNotPermittedException)

Example 2 with OperationNotPermittedException

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

the class MoveNodeCommand method execute.

public MoveNodeResult execute() {
    final Node existingNode = doGetById(nodeId);
    if (existingNode == null) {
        throw new NodeNotFoundException("cannot move node with id [" + nodeId + "]");
    }
    if (existingNode.isRoot()) {
        throw new OperationNotPermittedException("Not allowed to move root-node");
    }
    final NodeName newNodeName = resolveNodeName(existingNode);
    final NodePath newParentPath = resolvePath(existingNode);
    if (noChanges(existingNode, newParentPath, newNodeName)) {
        return result.build();
    }
    checkNotMovedToSelfOrChild(existingNode, newParentPath, newNodeName);
    checkContextUserPermissionOrAdmin(existingNode, newParentPath);
    verifyNoExistingAtNewPath(newParentPath, newNodeName);
    doMoveNode(newParentPath, newNodeName, nodeId);
    RefreshCommand.create().refreshMode(RefreshMode.ALL).indexServiceInternal(this.indexServiceInternal).build().execute();
    return result.build();
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeName(com.enonic.xp.node.NodeName) Node(com.enonic.xp.node.Node) OperationNotPermittedException(com.enonic.xp.node.OperationNotPermittedException) NodePath(com.enonic.xp.node.NodePath)

Example 3 with OperationNotPermittedException

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

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

the class DuplicateNodeCommand method execute.

public DuplicateNodeResult execute() {
    final Node existingNode = doGetById(params.getNodeId());
    if (existingNode == null) {
        throw new NodeNotFoundException("Cannot duplicate node with id [" + params.getNodeId() + "]");
    }
    if (existingNode.isRoot()) {
        throw new OperationNotPermittedException("Not allowed to duplicate root-node");
    }
    final CreateNodeParams.Builder createNodeParams = CreateNodeParams.from(existingNode);
    attachBinaries(existingNode, createNodeParams);
    Node duplicatedNode = null;
    String newNodeName = existingNode.name().toString();
    do {
        try {
            newNodeName = DuplicateValueResolver.name(newNodeName);
            final CreateNodeParams processedParams = executeProcessors(createNodeParams.name(newNodeName).build());
            duplicatedNode = CreateNodeCommand.create(this).params(processedParams).binaryService(binaryService).build().execute();
        } catch (NodeAlreadyExistAtPathException e) {
            // try again with other name
            LOG.debug(String.format("[%s] node with [%s] parent already exist.", newNodeName, existingNode.parentPath().toString()), e);
        }
    } while (duplicatedNode == null);
    result.node(duplicatedNode);
    nodeDuplicated(1);
    final NodeReferenceUpdatesHolder.Builder builder = NodeReferenceUpdatesHolder.create().add(existingNode.id(), duplicatedNode.id());
    if (params.getIncludeChildren()) {
        storeChildNodes(existingNode, duplicatedNode, builder);
    }
    final NodeReferenceUpdatesHolder nodesToBeUpdated = builder.build();
    RefreshCommand.create().refreshMode(RefreshMode.SEARCH).indexServiceInternal(this.indexServiceInternal).build().execute();
    updateNodeReferences(duplicatedNode, nodesToBeUpdated);
    updateChildReferences(duplicatedNode, nodesToBeUpdated);
    return result.build();
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) OperationNotPermittedException(com.enonic.xp.node.OperationNotPermittedException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Aggregations

OperationNotPermittedException (com.enonic.xp.node.OperationNotPermittedException)4 Node (com.enonic.xp.node.Node)3 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)3 NodeId (com.enonic.xp.node.NodeId)2 NodePath (com.enonic.xp.node.NodePath)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 NodeAccessException (com.enonic.xp.node.NodeAccessException)1 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)1 NodeBranchEntries (com.enonic.xp.node.NodeBranchEntries)1 NodeIds (com.enonic.xp.node.NodeIds)1 NodeName (com.enonic.xp.node.NodeName)1