Search in sources :

Example 6 with NodeNotFoundException

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

the class CreateIssueCommentCommandTest method createIssueNotExists.

@Test
public void createIssueNotExists() {
    final PrincipalKey creator = PrincipalKey.from("user:store:one");
    final CreateIssueCommentParams params = CreateIssueCommentParams.create().creator(creator).issue(IssueId.create()).creatorDisplayName("Creator One").text("Comment text...").build();
    final CreateIssueCommentCommand command = createIssueCommentCommand(params);
    Mockito.when(this.nodeService.findByQuery(Mockito.any(NodeQuery.class))).thenReturn(FindNodesByQueryResult.create().build());
    Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenThrow(new NodeNotFoundException("Node not found"));
    assertThrows(NodeNotFoundException.class, () -> command.execute());
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeQuery(com.enonic.xp.node.NodeQuery) NodeId(com.enonic.xp.node.NodeId) PrincipalKey(com.enonic.xp.security.PrincipalKey) CreateIssueCommentParams(com.enonic.xp.issue.CreateIssueCommentParams) Test(org.junit.jupiter.api.Test)

Example 7 with NodeNotFoundException

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

the class CreateNodeCommand method execute.

public Node execute() {
    Preconditions.checkNotNull(params.getParent(), "Path of parent Node must be specified");
    Preconditions.checkArgument(params.getParent().isAbsolute(), "Path to parent Node must be absolute: " + params.getParent());
    NodeHelper.runAsAdmin(this::verifyNotExistsAlready);
    final Node parentNode = NodeHelper.runAsAdmin(this::verifyParentExists);
    if (parentNode == null) {
        throw new NodeNotFoundException("Parent node to node with name '" + params.getName() + "' with parent path '" + params.getParent() + "' not found");
    }
    requireContextUserPermission(Permission.CREATE, parentNode);
    final PrincipalKey user = getCurrentPrincipalKey();
    final AccessControlList permissions = getAccessControlEntries(user);
    final Long manualOrderValue = NodeHelper.runAsAdmin(() -> resolvePotentialManualOrderValue(parentNode));
    final AttachedBinaries attachedBinaries = storeAndAttachBinaries();
    final Node.Builder nodeBuilder = Node.create().id(this.params.getNodeId() != null ? params.getNodeId() : new NodeId()).parentPath(params.getParent()).name(NodeName.from(params.getName())).data(params.getData()).indexConfigDocument(params.getIndexConfigDocument()).childOrder(params.getChildOrder() != null ? params.getChildOrder() : ChildOrder.defaultOrder()).manualOrderValue(manualOrderValue).permissions(permissions).inheritPermissions(params.inheritPermissions()).nodeType(params.getNodeType() != null ? params.getNodeType() : NodeType.DEFAULT_NODE_COLLECTION).attachedBinaries(attachedBinaries).timestamp(this.timestamp != null ? this.timestamp : Instant.now(CLOCK));
    final Node newNode = nodeBuilder.build();
    return StoreNodeCommand.create(this).node(newNode).updateMetadataOnly(false).build().execute();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) AttachedBinaries(com.enonic.xp.node.AttachedBinaries) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 8 with NodeNotFoundException

use of com.enonic.xp.node.NodeNotFoundException 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 9 with NodeNotFoundException

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

the class MoveNodeCommand method checkContextUserPermissionOrAdmin.

private void checkContextUserPermissionOrAdmin(final Node existingSourceNode, final NodePath newParentPath) {
    NodePermissionsResolver.requireContextUserPermissionOrAdmin(Permission.MODIFY, existingSourceNode);
    final Node newParentNode = GetNodeByPathCommand.create(this).nodePath(newParentPath).build().execute();
    if (newParentNode == null) {
        throw new NodeNotFoundException("Cannot move node to parent with path '" + newParentPath + "', does not exist");
    }
    NodePermissionsResolver.requireContextUserPermissionOrAdmin(Permission.CREATE, newParentNode);
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Node(com.enonic.xp.node.Node)

Example 10 with NodeNotFoundException

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

the class NodeServiceImpl method executeGetById.

private Node executeGetById(final NodeId id) {
    verifyContext();
    final Node node = doGetById(id);
    if (node == null) {
        throw new NodeNotFoundException("Node with id " + id + " not found in branch " + ContextAccessor.current().getBranch().getValue());
    }
    return node;
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Node(com.enonic.xp.node.Node)

Aggregations

NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)25 Node (com.enonic.xp.node.Node)13 NodeId (com.enonic.xp.node.NodeId)11 Test (org.junit.jupiter.api.Test)5 NodePath (com.enonic.xp.node.NodePath)4 NodeVersionId (com.enonic.xp.node.NodeVersionId)4 NodeQuery (com.enonic.xp.node.NodeQuery)3 OperationNotPermittedException (com.enonic.xp.node.OperationNotPermittedException)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)3 Content (com.enonic.xp.content.Content)2 ContentId (com.enonic.xp.content.ContentId)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)2 Nodes (com.enonic.xp.node.Nodes)2 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)2 InternalContext (com.enonic.xp.repo.impl.InternalContext)2 Principals (com.enonic.xp.security.Principals)2 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)1 Branch (com.enonic.xp.branch.Branch)1 MoveContentParams (com.enonic.xp.content.MoveContentParams)1