use of com.enonic.xp.node.NodePath 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.NodePath in project xp by enonic.
the class FindNodeIdsByParentCommand method execute.
public FindNodesByParentResult execute() {
NodePath parentPath = getParentPath();
if (parentPath == null) {
return FindNodesByParentResult.empty();
}
final ChildOrder order = NodeChildOrderResolver.create(this).nodePath(parentPath).childOrder(childOrder).build().resolve();
final SearchResult result = this.nodeSearchService.query(createFindChildrenQuery(parentPath, order), SingleRepoSearchSource.from(ContextAccessor.current()));
if (result.getNumberOfHits() == 0) {
return FindNodesByParentResult.create().totalHits(result.getTotalHits()).build();
}
return FindNodesByParentResult.create().nodeIds(NodeIds.from(result.getIds())).totalHits(result.getTotalHits()).hits(result.getNumberOfHits()).build();
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class FindNodesByParentCommand method execute.
public FindNodesByParentResult execute() {
NodePath parentPath = params.getParentPath();
if (parentPath == null) {
Node parent = GetNodeByIdCommand.create(this).id(params.getParentId()).build().execute();
if (parent == null) {
return FindNodesByParentResult.empty();
}
parentPath = parent.path();
}
final ChildOrder order = NodeChildOrderResolver.create(this).nodePath(parentPath).childOrder(params.getChildOrder()).build().resolve();
final SearchResult result = this.nodeSearchService.query(NodeQuery.create().parent(parentPath).addQueryFilters(params.getQueryFilters()).from(params.getFrom()).size(params.getSize()).searchMode(params.isCountOnly() ? SearchMode.COUNT : SearchMode.SEARCH).setOrderExpressions(order.getOrderExpressions()).accurateScoring(true).build(), SingleRepoSearchSource.from(ContextAccessor.current()));
if (result.isEmpty()) {
return FindNodesByParentResult.create().hits(0).totalHits(result.getTotalHits()).nodeIds(NodeIds.empty()).build();
}
return FindNodesByParentResult.create().nodeIds(NodeIds.from(result.getIds())).totalHits(result.getTotalHits()).hits(result.getNumberOfHits()).build();
}
use of com.enonic.xp.node.NodePath 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.NodePath in project xp by enonic.
the class MoveNodeCommand method verifyNoExistingAtNewPath.
private void verifyNoExistingAtNewPath(final NodePath newParentPath, final NodeName newNodeName) {
final NodePath newNodePath = NodePath.create(newParentPath, newNodeName.toString()).build();
CheckNodeExistsCommand.create(this).nodePath(newNodePath).throwIfExists().build().execute();
}
Aggregations