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);
}
}
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");
}
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();
}
}
Aggregations