Search in sources :

Example 16 with NodeNotFoundException

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

the class VersionTableVacuumCommand method findVersionsInBranches.

private BRANCH_CHECK_RESULT findVersionsInBranches(final Repository repository, final NodeVersionMetadata versionMetadata) {
    final NodeId nodeId = versionMetadata.getNodeId();
    final NodeVersionId versionId = versionMetadata.getNodeVersionId();
    boolean nodeFound = false;
    for (final Branch branch : repository.getBranches()) {
        try {
            final Node node = ContextBuilder.from(ContextAccessor.current()).branch(branch).repositoryId(repository.getId()).build().callWith(() -> this.nodeService.getById(nodeId));
            if (versionId.equals(node.getNodeVersionId())) {
                return BRANCH_CHECK_RESULT.SAME_VERSION_FOUND;
            }
            nodeFound = true;
        } catch (NodeNotFoundException e) {
        // Ignore
        }
    }
    return nodeFound ? BRANCH_CHECK_RESULT.OTHER_VERSION_FOUND : BRANCH_CHECK_RESULT.NO_VERSION_FOUND;
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeVersionId(com.enonic.xp.node.NodeVersionId) Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId)

Example 17 with NodeNotFoundException

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

the class SecurityServiceImpl method query.

@Override
public UserQueryResult query(final UserQuery query) {
    try {
        final NodeQuery nodeQueryBuilder = UserQueryNodeQueryTranslator.translate(query);
        final FindNodesByQueryResult result = callWithContext(() -> this.nodeService.findByQuery(nodeQueryBuilder));
        final Nodes nodes = callWithContext(() -> this.nodeService.getByIds(result.getNodeIds()));
        final Principals principals = PrincipalNodeTranslator.fromNodes(nodes);
        return UserQueryResult.create().addUsers(principals).totalSize(Ints.checkedCast(result.getTotalHits())).build();
    } catch (NodeNotFoundException e) {
        return UserQueryResult.create().build();
    }
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Principals(com.enonic.xp.security.Principals) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) Nodes(com.enonic.xp.node.Nodes)

Example 18 with NodeNotFoundException

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

the class SecurityServiceImpl method query.

@Override
public PrincipalQueryResult query(final PrincipalQuery query) {
    try {
        final NodeQuery nodeQueryBuilder = PrincipalQueryNodeQueryTranslator.translate(query);
        final FindNodesByQueryResult result = callWithContext(() -> this.nodeService.findByQuery(nodeQueryBuilder));
        final Nodes nodes = callWithContext(() -> this.nodeService.getByIds(result.getNodeIds()));
        final Principals principals = PrincipalNodeTranslator.fromNodes(nodes);
        return PrincipalQueryResult.create().addPrincipals(principals).totalSize(Ints.checkedCast(result.getTotalHits())).build();
    } catch (NodeNotFoundException e) {
        return PrincipalQueryResult.create().build();
    }
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Principals(com.enonic.xp.security.Principals) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) Nodes(com.enonic.xp.node.Nodes)

Example 19 with NodeNotFoundException

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

the class FindIssueCommentsCommandTest method testFindIssuesIssueNotExists.

@Test
public void testFindIssuesIssueNotExists() throws Exception {
    final IssueId issueId = IssueId.create();
    final PrincipalKey creator = PrincipalKey.from("user:store:one");
    final IssueCommentQuery commentQuery = IssueCommentQuery.create().from(0).size(20).issue(issueId).creator(creator).build();
    final FindIssueCommentsCommand command = createCommand(commentQuery);
    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) NodeId(com.enonic.xp.node.NodeId) IssueId(com.enonic.xp.issue.IssueId) IssueCommentQuery(com.enonic.xp.issue.IssueCommentQuery) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 20 with NodeNotFoundException

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

the class UpdateIssueCommentCommandTest method updateCommentNotExists.

@Test
public void updateCommentNotExists() {
    final UpdateIssueCommentParams params = UpdateIssueCommentParams.create().comment(NodeId.from(UUID.randomUUID())).text("Comment text...").build();
    final UpdateIssueCommentCommand command = updateIssueCommentCommand(params);
    Mockito.when(this.nodeService.update(Mockito.any(UpdateNodeParams.class))).thenThrow(new NodeNotFoundException("Node not found"));
    assertThrows(NodeNotFoundException.class, () -> command.execute());
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) UpdateIssueCommentParams(com.enonic.xp.issue.UpdateIssueCommentParams) 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