Search in sources :

Example 1 with HalRepresentation

use of de.otto.edison.hal.HalRepresentation in project scm-review-plugin by scm-manager.

the class BranchDetailsEnricher method enrich.

@Override
public void enrich(HalEnricherContext context, HalAppender appender) {
    Repository repository = context.oneRequireByType(Repository.class);
    String branchName = context.oneRequireByType(BranchDetails.class).getBranchName();
    if (service.supportsPullRequests(repository)) {
        List<HalRepresentation> pullRequestDtos = getPullRequestDtos(repository, branchName);
        appender.appendEmbedded("pullRequests", pullRequestDtos);
    }
}
Also used : Repository(sonia.scm.repository.Repository) HalRepresentation(de.otto.edison.hal.HalRepresentation) BranchDetails(sonia.scm.repository.BranchDetails)

Example 2 with HalRepresentation

use of de.otto.edison.hal.HalRepresentation in project scm-review-plugin by scm-manager.

the class CommentRootResource method getAll.

@GET
@Path("")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Get all pull request comments", description = "Returns all pull request comments.", tags = "Pull Request Comment", operationId = "review_get_comments")
@ApiResponse(responseCode = "200", description = "success", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = HalRepresentation.class)))
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"commentPullRequest\" privilege")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public HalRepresentation getAll(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId) {
    PullRequestResourceLinks resourceLinks = new PullRequestResourceLinks(uriInfo::getBaseUri);
    Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
    PullRequest pullRequest = pullRequestService.get(namespace, name, pullRequestId);
    BranchRevisionResolver.RevisionResult revisions = branchRevisionResolver.getRevisions(new NamespaceAndName(namespace, name), pullRequest);
    List<Comment> list = service.getAll(namespace, name, pullRequestId);
    List<CommentDto> dtoList = list.stream().map(comment -> mapper.map(comment, repository, pullRequestId, service.possibleTransitions(namespace, name, pullRequestId, comment.getId()), revisions)).collect(Collectors.toList());
    boolean permission = PermissionCheck.mayComment(repository);
    return createCollection(permission, resourceLinks.pullRequestComments().all(namespace, name, pullRequestId), resourceLinks.pullRequestComments().create(namespace, name, pullRequestId, revisions), dtoList, "pullRequestComments");
}
Also used : PullRequestMediaType(com.cloudogu.scm.review.PullRequestMediaType) PathParam(javax.ws.rs.PathParam) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Inject(javax.inject.Inject) Valid(javax.validation.Valid) Content(io.swagger.v3.oas.annotations.media.Content) Operation(io.swagger.v3.oas.annotations.Operation) MediaType(javax.ws.rs.core.MediaType) VndMediaType(sonia.scm.web.VndMediaType) QueryParam(javax.ws.rs.QueryParam) HalRepresentation(de.otto.edison.hal.HalRepresentation) Consumes(javax.ws.rs.Consumes) Comment(com.cloudogu.scm.review.comment.service.Comment) ErrorDto(sonia.scm.api.v2.resources.ErrorDto) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) PermissionCheck(com.cloudogu.scm.review.PermissionCheck) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) URI(java.net.URI) Schema(io.swagger.v3.oas.annotations.media.Schema) RepositoryResolver(com.cloudogu.scm.review.RepositoryResolver) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) HalRepresentations.createCollection(com.cloudogu.scm.review.HalRepresentations.createCollection) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) AuthorizationException(org.apache.shiro.authz.AuthorizationException) List(java.util.List) Response(javax.ws.rs.core.Response) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) CommentService(com.cloudogu.scm.review.comment.service.CommentService) RevisionChecker.checkRevision(com.cloudogu.scm.review.comment.api.RevisionChecker.checkRevision) UriInfo(javax.ws.rs.core.UriInfo) NamespaceAndName(sonia.scm.repository.NamespaceAndName) Comment(com.cloudogu.scm.review.comment.service.Comment) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Repository(sonia.scm.repository.Repository) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 3 with HalRepresentation

use of de.otto.edison.hal.HalRepresentation in project scm-review-plugin by scm-manager.

the class PullRequestResource method getSubscription.

@GET
@Path("subscription")
@Produces(PullRequestMediaType.PULL_REQUEST)
@Operation(summary = "Evaluates which subscription link should be used", hidden = true)
@ApiResponse(responseCode = "200", description = "success")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"readPullRequest\" privilege")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public Response getSubscription(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId) {
    Repository repository = service.getRepository(namespace, name);
    PermissionCheck.checkRead(repository);
    if (CurrentUserResolver.getCurrentUser() != null && Strings.isNullOrEmpty(CurrentUserResolver.getCurrentUser().getMail())) {
        return Response.ok().build();
    }
    if (service.isUserSubscribed(repository, pullRequestId)) {
        PullRequestResourceLinks resourceLinks = new PullRequestResourceLinks(uriInfo::getBaseUri);
        String unsubscribe = resourceLinks.pullRequest().unsubscribe(namespace, name, pullRequestId);
        Links.Builder linksBuilder = linkingTo().single(Link.link("unsubscribe", unsubscribe));
        return Response.ok(new HalRepresentation(linksBuilder.build())).build();
    } else {
        PullRequestResourceLinks resourceLinks = new PullRequestResourceLinks(uriInfo::getBaseUri);
        String subscribe = resourceLinks.pullRequest().subscribe(namespace, name, pullRequestId);
        Links.Builder linksBuilder = linkingTo().single(Link.link("subscribe", subscribe));
        return Response.ok(new HalRepresentation(linksBuilder.build())).build();
    }
}
Also used : Repository(sonia.scm.repository.Repository) HalRepresentation(de.otto.edison.hal.HalRepresentation) Links(de.otto.edison.hal.Links) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Aggregations

HalRepresentation (de.otto.edison.hal.HalRepresentation)3 Repository (sonia.scm.repository.Repository)3 PullRequestResourceLinks (com.cloudogu.scm.review.PullRequestResourceLinks)2 Operation (io.swagger.v3.oas.annotations.Operation)2 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 HalRepresentations.createCollection (com.cloudogu.scm.review.HalRepresentations.createCollection)1 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)1 PullRequestMediaType (com.cloudogu.scm.review.PullRequestMediaType)1 RepositoryResolver (com.cloudogu.scm.review.RepositoryResolver)1 RevisionChecker.checkRevision (com.cloudogu.scm.review.comment.api.RevisionChecker.checkRevision)1 Comment (com.cloudogu.scm.review.comment.service.Comment)1 CommentService (com.cloudogu.scm.review.comment.service.CommentService)1 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)1 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)1 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)1 Links (de.otto.edison.hal.Links)1 Content (io.swagger.v3.oas.annotations.media.Content)1