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