use of com.google.gerrit.server.change.HumanCommentResource in project gerrit by GerritCodeReview.
the class DeleteComment method apply.
@Override
public Response<CommentInfo> apply(HumanCommentResource rsrc, DeleteCommentInput input) throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException, UpdateException {
CurrentUser user = userProvider.get();
permissionBackend.user(user).check(GlobalPermission.ADMINISTRATE_SERVER);
if (input == null) {
input = new DeleteCommentInput();
}
String newMessage = getCommentNewMessage(user.asIdentifiedUser().getName(), input.reason);
DeleteCommentOp deleteCommentOp = new DeleteCommentOp(rsrc, newMessage);
try (BatchUpdate batchUpdate = updateFactory.create(rsrc.getRevisionResource().getProject(), user, TimeUtil.now())) {
batchUpdate.addOp(rsrc.getRevisionResource().getChange().getId(), deleteCommentOp).execute();
}
ChangeNotes updatedNotes = notesFactory.createChecked(rsrc.getRevisionResource().getProject(), rsrc.getRevisionResource().getChangeResource().getId());
List<HumanComment> changeComments = commentsUtil.publishedHumanCommentsByChange(updatedNotes);
Optional<HumanComment> updatedComment = changeComments.stream().filter(c -> c.key.equals(rsrc.getComment().key)).findFirst();
if (!updatedComment.isPresent()) {
// This should not happen as this endpoint should not remove the whole comment.
throw new ResourceNotFoundException("comment not found: " + rsrc.getComment().key);
}
return Response.ok(commentJson.get().newHumanCommentFormatter().format(updatedComment.get()));
}
use of com.google.gerrit.server.change.HumanCommentResource in project gerrit by GerritCodeReview.
the class Comments method parse.
@Override
public HumanCommentResource parse(RevisionResource rev, IdString id) throws ResourceNotFoundException {
String uuid = id.get();
ChangeNotes notes = rev.getNotes();
for (HumanComment c : commentsUtil.publishedByPatchSet(notes, rev.getPatchSet().id())) {
if (uuid.equals(c.key.uuid)) {
return new HumanCommentResource(rev, c);
}
}
throw new ResourceNotFoundException(id);
}
Aggregations