Search in sources :

Example 16 with NodePath

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

Example 17 with NodePath

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

Example 18 with NodePath

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

Example 19 with NodePath

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));
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) Event(com.enonic.xp.event.Event) NodeMovedParams(com.enonic.xp.repo.impl.storage.NodeMovedParams) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 20 with NodePath

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));
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeId(com.enonic.xp.node.NodeId) Event(com.enonic.xp.event.Event) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

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