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