Search in sources :

Example 11 with NodePath

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();
}
Also used : NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath)

Example 12 with NodePath

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();
}
Also used : ChildOrder(com.enonic.xp.index.ChildOrder) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) NodePath(com.enonic.xp.node.NodePath)

Example 13 with NodePath

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();
}
Also used : Node(com.enonic.xp.node.Node) ChildOrder(com.enonic.xp.index.ChildOrder) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) NodePath(com.enonic.xp.node.NodePath)

Example 14 with NodePath

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();
}
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 15 with NodePath

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();
}
Also used : NodePath(com.enonic.xp.node.NodePath)

Aggregations

NodePath (com.enonic.xp.node.NodePath)54 Node (com.enonic.xp.node.Node)27 Test (org.junit.jupiter.api.Test)20 NodeId (com.enonic.xp.node.NodeId)15 InternalContext (com.enonic.xp.repo.impl.InternalContext)12 Content (com.enonic.xp.content.Content)7 Event (com.enonic.xp.event.Event)7 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)4 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)4 NodeVersionId (com.enonic.xp.node.NodeVersionId)4 ChildOrder (com.enonic.xp.index.ChildOrder)3 NodeIds (com.enonic.xp.node.NodeIds)3 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 ContentId (com.enonic.xp.content.ContentId)2 ContentPath (com.enonic.xp.content.ContentPath)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)2 Context (com.enonic.xp.context.Context)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)2 NodeVersion (com.enonic.xp.node.NodeVersion)2