Search in sources :

Example 1 with NotFoundException

use of sonia.scm.NotFoundException in project scm-review-plugin by scm-manager.

the class CommentService method modifyComment.

public void modifyComment(String namespace, String name, String pullRequestId, String commentId, Comment changedComment) {
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    PullRequest pullRequest = pullRequestService.get(repository, pullRequestId);
    Comment rootComment = findRootComment(repository, pullRequestId, commentId).<NotFoundException>orElseThrow(() -> {
        throw notFound(entity(BasicComment.class, String.valueOf(changedComment.getId())).in(PullRequest.class, pullRequestId).in(repository.getNamespaceAndName()));
    });
    PermissionCheck.checkModifyComment(repository, rootComment);
    Comment clone = rootComment.clone();
    rootComment.setComment(changedComment.getComment());
    handleMentions(repository, pullRequest, rootComment, clone);
    rootComment.addTransition(new ExecutedTransition<>(keyGenerator.createKey(), CHANGE_TEXT, System.currentTimeMillis(), getCurrentUserId()));
    getCommentStore(repository).update(pullRequestId, rootComment);
    eventBus.post(new CommentEvent(repository, pullRequest, rootComment, clone, HandlerEventType.MODIFY));
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) NotFoundException(sonia.scm.NotFoundException)

Example 2 with NotFoundException

use of sonia.scm.NotFoundException in project scm-review-plugin by scm-manager.

the class CommentService method markAsOutdated.

public void markAsOutdated(String namespace, String name, String pullRequestId, String commentId) {
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    Comment rootComment = findRootComment(repository, pullRequestId, commentId).<NotFoundException>orElseThrow(() -> {
        throw notFound(entity(BasicComment.class, commentId).in(PullRequest.class, pullRequestId).in(repository.getNamespaceAndName()));
    });
    if (!rootComment.isOutdated()) {
        rootComment.setOutdated(true);
        getCommentStore(repository).update(pullRequestId, rootComment);
    }
}
Also used : Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) NotFoundException(sonia.scm.NotFoundException)

Example 3 with NotFoundException

use of sonia.scm.NotFoundException in project scm-review-plugin by scm-manager.

the class RepositoryResolverTest method testResolveRepositoryNotFound.

@Test
public void testResolveRepositoryNotFound() {
    NotFoundException exception = assertThrows(NotFoundException.class, () -> resolver.resolve(namespaceAndName));
    ContextEntry contextEntry = exception.getContext().get(0);
    assertThat(contextEntry.getType()).isEqualTo("Repository");
    assertThat(contextEntry.getId()).isEqualTo("hitchhiker/heartOfGold");
}
Also used : NotFoundException(sonia.scm.NotFoundException) ContextEntry(sonia.scm.ContextEntry) Test(org.junit.jupiter.api.Test)

Example 4 with NotFoundException

use of sonia.scm.NotFoundException in project scm-review-plugin by scm-manager.

the class PullRequestRootResourceTest method shouldFailOnUpdatingNonExistingPullRequest.

@Test
@SubjectAware(username = "slarti")
public void shouldFailOnUpdatingNonExistingPullRequest() throws URISyntaxException, IOException {
    initRepoWithPRs("ns", "repo");
    when(store.get("opened_1")).thenThrow(new NotFoundException("x", "y"));
    MockHttpRequest request = MockHttpRequest.put("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/opened_1").content("{\"title\": \"new Title\", \"description\": \"new description\"}".getBytes()).contentType(PullRequestMediaType.PULL_REQUEST);
    dispatcher.invoke(request, response);
    assertThat(response.getContentAsString()).containsPattern("could not find.*");
    verify(store, never()).update(any());
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) NotFoundException(sonia.scm.NotFoundException) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 5 with NotFoundException

use of sonia.scm.NotFoundException in project scm-review-plugin by scm-manager.

the class PullRequestRootResourceTest method shouldHandleMissingRepository.

@Test
@SubjectAware(username = "trillian")
public void shouldHandleMissingRepository() throws URISyntaxException, IOException {
    when(repositoryResolver.resolve(new NamespaceAndName("space", "X"))).thenThrow(new NotFoundException("x", "y"));
    byte[] pullRequestJson = loadJson("com/cloudogu/scm/review/pullRequest.json");
    MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/X").content(pullRequestJson).contentType(PullRequestMediaType.PULL_REQUEST);
    dispatcher.invoke(request, response);
    assertThat(response.getContentAsString()).containsPattern("could not find.*");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) NamespaceAndName(sonia.scm.repository.NamespaceAndName) NotFoundException(sonia.scm.NotFoundException) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Aggregations

NotFoundException (sonia.scm.NotFoundException)6 SubjectAware (com.github.sdorra.shiro.SubjectAware)3 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)3 Test (org.junit.Test)3 NamespaceAndName (sonia.scm.repository.NamespaceAndName)3 Repository (sonia.scm.repository.Repository)2 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)1 Test (org.junit.jupiter.api.Test)1 ContextEntry (sonia.scm.ContextEntry)1