Search in sources :

Example 26 with NodeId

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

the class NodeManualOrderValueResolver method resolve.

public static List<NodeIdOrderValue> resolve(final NodeIds orderedNodeIds) {
    final List<NodeIdOrderValue> result = new ArrayList<>();
    Long currentValue = START_ORDER_VALUE;
    for (final NodeId nodeId : orderedNodeIds) {
        result.add(new NodeIdOrderValue(nodeId, currentValue));
        currentValue = currentValue - ORDER_SPACE;
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) NodeId(com.enonic.xp.node.NodeId)

Example 27 with NodeId

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

the class ReorderChildNodeCommand method resolveInsertInbetweenOrderValue.

private Long resolveInsertInbetweenOrderValue(final Long nodeAfterOrderValue, final SearchResult result) {
    final NodeId nodeBeforeInsertId = NodeId.from(result.getHits().getFirst().getId());
    final Node nodeBeforeInsert = doGetById(nodeBeforeInsertId);
    return (nodeAfterOrderValue + nodeBeforeInsert.getManualOrderValue()) / 2;
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId)

Example 28 with NodeId

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

the class ReorderChildNodeCommand method resolveInsertLastOrderValue.

private Long resolveInsertLastOrderValue(final SearchResult result) {
    final NodeId lastNodeId = NodeId.from(result.getHits().getFirst().getId());
    final Node lastNode = doGetById(lastNodeId);
    if (lastNode.getManualOrderValue() == null) {
        throw new IllegalArgumentException("Node with id [" + lastNode.id() + "] missing manual order value");
    }
    return lastNode.getManualOrderValue() - NodeManualOrderValueResolver.ORDER_SPACE;
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId)

Example 29 with NodeId

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

the class PushNodesCommand method targetAlreadyExists.

private boolean targetAlreadyExists(final NodePath nodePath, final NodeComparisons comparisons, final Context currentContext) {
    // Checks if a node exist
    final Context targetContext = createTargetContext(currentContext);
    final NodeId nodeId = targetContext.callWith(() -> GetNodeIdByPathCommand.create(this).nodePath(nodePath).build().execute());
    // If the node does not exist, returns false
    if (nodeId == null) {
        return false;
    }
    // Else, if the existing node is being deleted or moved during the current push, returns false
    final NodeComparison nodeComparison = comparisons.get(nodeId);
    return nodeComparison == null || (CompareStatus.MOVED != nodeComparison.getCompareStatus() && CompareStatus.PENDING_DELETE != nodeComparison.getCompareStatus());
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) NodeComparison(com.enonic.xp.node.NodeComparison) NodeId(com.enonic.xp.node.NodeId)

Example 30 with NodeId

use of com.enonic.xp.node.NodeId 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)

Aggregations

NodeId (com.enonic.xp.node.NodeId)91 Node (com.enonic.xp.node.Node)44 Test (org.junit.jupiter.api.Test)36 NodePath (com.enonic.xp.node.NodePath)23 InternalContext (com.enonic.xp.repo.impl.InternalContext)18 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)15 NodeIds (com.enonic.xp.node.NodeIds)14 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)11 Context (com.enonic.xp.context.Context)10 PropertyTree (com.enonic.xp.data.PropertyTree)10 Branch (com.enonic.xp.branch.Branch)9 ContextAccessor (com.enonic.xp.context.ContextAccessor)9 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)9 NodeVersionId (com.enonic.xp.node.NodeVersionId)9 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)8 RefreshMode (com.enonic.xp.node.RefreshMode)8 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)6 Event (com.enonic.xp.event.Event)6 RenameNodeParams (com.enonic.xp.node.RenameNodeParams)6