use of com.enonic.xp.node.NodePath 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();
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class UpdateNodeCommand method createUpdatedNode.
private Node createUpdatedNode(final Node editedNode) {
final NodePath parentPath = editedNode.path().getParentPath();
final AccessControlList permissions = evaluatePermissions(parentPath, editedNode.inheritsPermissions(), editedNode.getPermissions());
final Node.Builder updateNodeBuilder = Node.create(editedNode).permissions(permissions);
return updateNodeBuilder.build();
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class DuplicateNodeCommandTest method isWithinDuplicatedTree.
private boolean isWithinDuplicatedTree(final NodePath duplicatedRootPath, final Property ref) {
final Value referredNode = ref.getValue();
final NodePath referredPath = getNode(referredNode.asReference().getNodeId()).path();
return isChildOrSamePath(duplicatedRootPath, referredPath);
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class NodeEventListenerTest method node_moved_event.
@Test
public void node_moved_event() throws Exception {
final NodeId nodeId = NodeId.from("node1");
final NodePath nodePath = NodePath.create(NodePath.ROOT, "nodeName").build();
final Node sourceNode = Node.create().id(nodeId).parentPath(nodePath.getParentPath()).name(nodePath.getLastElement().toString()).build();
final Node movedNode = Node.create(sourceNode).parentPath(NodePath.create("newParent").build()).build();
final Event localEvent = NodeEvents.moved(MoveNodeResult.create().addMovedNode(MoveNodeResult.MovedNode.create().node(movedNode).previousPath(sourceNode.path()).build()).sourceNode(sourceNode).build());
nodeEventListener.onEvent(Event.create(localEvent).localOrigin(false).build());
final NodeMovedParams nodeMovedParams = new NodeMovedParams(sourceNode.path(), movedNode.path(), sourceNode.id());
Mockito.verify(nodeStorageService, Mockito.times(1)).handleNodeMoved(Mockito.eq(nodeMovedParams), Mockito.isA(InternalContext.class));
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class NodeEventListenerTest method local_event_ignored.
@Test
public void local_event_ignored() throws Exception {
final NodeId nodeId = NodeId.from("node1");
final NodePath nodePath = NodePath.create(NodePath.ROOT, "nodeName").build();
final Event localEvent = NodeEvents.created(Node.create().id(nodeId).parentPath(nodePath.getParentPath()).name(nodePath.getLastElement().toString()).build());
nodeEventListener.onEvent(localEvent);
Mockito.verify(nodeStorageService, Mockito.never()).handleNodeCreated(Mockito.eq(nodeId), Mockito.eq(nodePath), Mockito.isA(InternalContext.class));
}
Aggregations