Search in sources :

Example 1 with EdisonHalAppender

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

the class CommentMapper method appendLinks.

@AfterMapping
void appendLinks(@MappingTarget CommentDto target, Comment source, @Context Repository repository, @Context String pullRequestId, @Context BranchRevisionResolver.RevisionResult revisions) {
    String namespace = repository.getNamespace();
    String name = repository.getName();
    final Links.Builder linksBuilder = new Links.Builder();
    linksBuilder.self(commentPathBuilder.createCommentSelfUri(namespace, name, pullRequestId, target.getId()));
    if (!target.isSystemComment() && PermissionCheck.mayModifyComment(repository, source)) {
        linksBuilder.single(link("update", commentPathBuilder.createUpdateCommentUri(namespace, name, pullRequestId, target.getId(), revisions)));
        linksBuilder.single(link("possibleTransitions", commentPathBuilder.createPossibleTransitionUri(namespace, name, pullRequestId, target.getId())));
        if (source.getReplies().isEmpty()) {
            linksBuilder.single(link("delete", commentPathBuilder.createDeleteCommentUri(namespace, name, pullRequestId, target.getId(), revisions)));
        }
    }
    applyEnrichers(new EdisonHalAppender(linksBuilder, new Embedded.Builder()), source, repository);
    target.add(linksBuilder.build());
}
Also used : EdisonHalAppender(sonia.scm.web.EdisonHalAppender) Links(de.otto.edison.hal.Links) AfterMapping(org.mapstruct.AfterMapping)

Example 2 with EdisonHalAppender

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

the class ReplyMapper method appendLinks.

@AfterMapping
void appendLinks(@MappingTarget ReplyDto target, Reply source, @Context Repository repository, @Context String pullRequestId, @Context Comment comment, @Context BranchRevisionResolver.RevisionResult revisions) {
    String namespace = repository.getNamespace();
    String name = repository.getName();
    final Links.Builder linksBuilder = new Links.Builder();
    linksBuilder.self(commentPathBuilder.createReplySelfUri(namespace, name, pullRequestId, comment.getId(), target.getId()));
    if (PermissionCheck.mayModifyComment(repository, source) && !source.isSystemReply()) {
        linksBuilder.single(link("update", commentPathBuilder.createUpdateReplyUri(namespace, name, pullRequestId, comment.getId(), target.getId(), revisions)));
        linksBuilder.single(link("delete", commentPathBuilder.createDeleteReplyUri(namespace, name, pullRequestId, comment.getId(), target.getId(), revisions)));
    }
    applyEnrichers(new EdisonHalAppender(linksBuilder, new Embedded.Builder()), source, repository);
    target.add(linksBuilder.build());
}
Also used : EdisonHalAppender(sonia.scm.web.EdisonHalAppender) Links(de.otto.edison.hal.Links) AfterMapping(org.mapstruct.AfterMapping)

Example 3 with EdisonHalAppender

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

the class PullRequestMapper method createDto.

@ObjectFactory
PullRequestDto createDto(PullRequest pullRequest, @Context Repository repository) {
    String namespace = repository.getNamespace();
    String name = repository.getName();
    String pullRequestId = pullRequest.getId();
    Links.Builder linksBuilder = linkingTo().self(pullRequestResourceLinks.pullRequest().self(namespace, name, pullRequestId));
    linksBuilder.single(link("comments", pullRequestResourceLinks.pullRequestComments().all(namespace, name, pullRequestId)));
    linksBuilder.single(link("events", pullRequestResourceLinks.pullRequest().events(namespace, name, pullRequestId)));
    if (PermissionCheck.mayComment(repository) && CurrentUserResolver.getCurrentUser() != null) {
        if (pullRequest.getStatus() == PullRequestStatus.OPEN) {
            if (pullRequestService.hasUserApproved(repository, pullRequest.getId())) {
                linksBuilder.single(link("disapprove", pullRequestResourceLinks.pullRequest().disapprove(namespace, name, pullRequestId)));
            } else {
                linksBuilder.single(link("approve", pullRequestResourceLinks.pullRequest().approve(namespace, name, pullRequestId)));
            }
        }
        if (!Strings.isNullOrEmpty(CurrentUserResolver.getCurrentUser().getMail())) {
            linksBuilder.single(link("subscription", pullRequestResourceLinks.pullRequest().subscription(namespace, name, pullRequestId)));
        }
    }
    if (PermissionCheck.mayModifyPullRequest(repository, pullRequest)) {
        linksBuilder.single(link("update", pullRequestResourceLinks.pullRequest().update(namespace, name, pullRequestId)));
    }
    if (PermissionCheck.mayMerge(repository) && pullRequest.getStatus() == PullRequestStatus.OPEN) {
        linksBuilder.single(link("reject", pullRequestResourceLinks.pullRequest().reject(namespace, name, pullRequestId)));
        if (RepositoryPermissions.push(repository).isPermitted() && pullRequest.getStatus() == PullRequestStatus.OPEN) {
            linksBuilder.single(link("mergeCheck", pullRequestResourceLinks.mergeLinks().check(namespace, name, pullRequest.getId())));
            linksBuilder.single(link("mergeConflicts", pullRequestResourceLinks.mergeLinks().conflicts(namespace, name, pullRequest.getId())));
            linksBuilder.single(link("defaultCommitMessage", pullRequestResourceLinks.mergeLinks().createDefaultCommitMessage(namespace, name, pullRequest.getId())));
            linksBuilder.single(link("mergeStrategyInfo", pullRequestResourceLinks.mergeLinks().getMergeStrategyInfo(namespace, name, pullRequestId)));
            appendMergeStrategyLinks(linksBuilder, repository, pullRequest);
        }
    }
    linksBuilder.single(link("reviewMark", pullRequestResourceLinks.pullRequest().reviewMark(namespace, name, pullRequestId)));
    linksBuilder.single(link("sourceBranch", branchLinkProvider.get(repository.getNamespaceAndName(), pullRequest.getSource())));
    linksBuilder.single(link("targetBranch", branchLinkProvider.get(repository.getNamespaceAndName(), pullRequest.getTarget())));
    if (pullRequest.getStatus() == PullRequestStatus.OPEN) {
        linksBuilder.single(link("workflowResult", pullRequestResourceLinks.workflowEngineLinks().results(namespace, name, pullRequest.getId())));
    }
    Embedded.Builder embeddedBuilder = embeddedBuilder();
    applyEnrichers(new EdisonHalAppender(linksBuilder, embeddedBuilder), pullRequest, repository);
    return new PullRequestDto(linksBuilder.build(), embeddedBuilder.build());
}
Also used : EdisonHalAppender(sonia.scm.web.EdisonHalAppender) Links(de.otto.edison.hal.Links) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) Embedded(de.otto.edison.hal.Embedded) ObjectFactory(org.mapstruct.ObjectFactory)

Aggregations

Links (de.otto.edison.hal.Links)3 EdisonHalAppender (sonia.scm.web.EdisonHalAppender)3 AfterMapping (org.mapstruct.AfterMapping)2 PullRequestResourceLinks (com.cloudogu.scm.review.PullRequestResourceLinks)1 Embedded (de.otto.edison.hal.Embedded)1 ObjectFactory (org.mapstruct.ObjectFactory)1