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;
}
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();
}
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();
}
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();
}
Aggregations