Search in sources :

Example 1 with NodeNotFoundException

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

the class DiffBranchesHandler method execute.

@Override
public Object execute() {
    final NodeId nodeId = getNodeId(this.nodeKey);
    if (nodeId == null) {
        throw new NodeNotFoundException("Node with key [" + this.nodeKey + "] not found");
    }
    final ResolveSyncWorkResult result = this.nodeService.resolveSyncWork(SyncWorkResolverParams.create().includeChildren(includeChildren).nodeId(nodeId).branch(targetBranch).build());
    return new ResolveSyncWorkResultMapper(result);
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) ResolveSyncWorkResultMapper(com.enonic.xp.lib.node.mapper.ResolveSyncWorkResultMapper) NodeId(com.enonic.xp.node.NodeId) ResolveSyncWorkResult(com.enonic.xp.node.ResolveSyncWorkResult)

Example 2 with NodeNotFoundException

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

the class GetContentByIdCommand method execute.

Content execute() {
    final Content content;
    final NodeId nodeId = NodeId.from(contentId.toString());
    try {
        final Node node = nodeService.getById(nodeId);
        content = filter(translator.fromNode(node, true));
    } catch (NodeNotFoundException e) {
        return null;
    } catch (Exception e) {
        throw Exceptions.newRuntime("Error getting node").withCause(e);
    }
    return content;
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException)

Example 3 with NodeNotFoundException

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

the class GetContentByPathAndVersionIdCommand method execute.

public Content execute() {
    final NodePath nodePath = ContentNodeHelper.translateContentPathToNodePath(contentPath);
    final NodeVersionId nodeVersionId = NodeVersionId.from(contentVersionId.toString());
    try {
        final Node node = nodeService.getByPathAndVersionId(nodePath, nodeVersionId);
        final Content content = filter(translator.fromNode(node, true));
        if (content != null) {
            return content;
        }
        throw createContentNotFoundException();
    } catch (NodeNotFoundException e) {
        throw createContentNotFoundException();
    }
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeVersionId(com.enonic.xp.node.NodeVersionId) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath)

Example 4 with NodeNotFoundException

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

the class MoveContentCommandTest method move_non_existing_content.

@Test
public void move_non_existing_content() throws Exception {
    PropertyTree existingContentData = new PropertyTree();
    existingContentData.addString("myData", "aaa");
    ContentId contentId = ContentId.from("mycontent");
    MoveContentParams params = MoveContentParams.create().contentId(contentId).parentContentPath(ContentPath.ROOT).build();
    MoveContentCommand command = MoveContentCommand.create(params).contentTypeService(this.contentTypeService).nodeService(this.nodeService).translator(this.translator).eventPublisher(this.eventPublisher).build();
    Mockito.when(nodeService.getById(Mockito.isA(NodeId.class))).thenThrow(new NodeNotFoundException("Node not found"));
    // exercise
    assertThrows(ContentNotFoundException.class, () -> command.execute());
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) MoveContentParams(com.enonic.xp.content.MoveContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) NodeId(com.enonic.xp.node.NodeId) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 5 with NodeNotFoundException

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

the class UpdateContentCommandTest method given_content_not_found_when_handle_then_NOT_FOUND_is_returned.

@Test
public void given_content_not_found_when_handle_then_NOT_FOUND_is_returned() throws Exception {
    // setup
    PropertyTree existingContentData = new PropertyTree();
    existingContentData.addString("myData", "aaa");
    ContentId contentId = ContentId.from("mycontent");
    UpdateContentParams params = new UpdateContentParams().contentId(contentId).editor(edit -> {
    });
    UpdateContentCommand command = UpdateContentCommand.create(params).contentTypeService(this.contentTypeService).nodeService(this.nodeService).translator(this.translator).eventPublisher(this.eventPublisher).mediaInfo(this.mediaInfo).xDataService(this.xDataService).siteService(this.siteService).build();
    Mockito.when(nodeService.getById(Mockito.isA(NodeId.class))).thenThrow(new NodeNotFoundException("Node not found"));
    // exercise
    assertThrows(ContentNotFoundException.class, () -> command.execute());
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) NodeId(com.enonic.xp.node.NodeId) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

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