Merge "RevisionApi: Offer get{Comments,Drafts}AsList() methods"

This commit is contained in:
Edwin Kempin
2015-05-19 19:24:59 +00:00
committed by Gerrit Code Review
5 changed files with 74 additions and 0 deletions

View File

@@ -297,6 +297,15 @@ class RevisionApiImpl implements RevisionApi {
}
}
@Override
public List<CommentInfo> commentsAsList() throws RestApiException {
try {
return listComments.getComments(revision);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve comments", e);
}
}
@Override
public Map<String, List<CommentInfo>> drafts() throws RestApiException {
try {
@@ -306,6 +315,15 @@ class RevisionApiImpl implements RevisionApi {
}
}
@Override
public List<CommentInfo> draftsAsList() throws RestApiException {
try {
return listDrafts.getComments(revision);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve drafts", e);
}
}
@Override
public DraftApi draft(String id) throws RestApiException {
try {

View File

@@ -16,7 +16,9 @@ package com.google.gerrit.server.change;
import static com.google.gerrit.server.PatchLineCommentsUtil.COMMENT_INFO_ORDER;
import com.google.common.base.Function;
import com.google.common.base.Strings;
import com.google.common.collect.FluentIterable;
import com.google.gerrit.extensions.client.Comment.Range;
import com.google.gerrit.extensions.client.Side;
import com.google.gerrit.extensions.common.CommentInfo;
@@ -96,6 +98,27 @@ class CommentJson {
return out;
}
List<CommentInfo> formatAsList(Iterable<PatchLineComment> l)
throws OrmException {
final AccountLoader accountLoader = fillAccounts
? accountLoaderFactory.create(true)
: null;
List<CommentInfo> out = FluentIterable
.from(l)
.transform(new Function<PatchLineComment, CommentInfo>() {
@Override
public CommentInfo apply(PatchLineComment c) {
return toCommentInfo(c, accountLoader);
}
}).toSortedList(COMMENT_INFO_ORDER);
if (accountLoader != null) {
accountLoader.fill();
}
return out;
}
private CommentInfo toCommentInfo(PatchLineComment c, AccountLoader loader) {
CommentInfo r = new CommentInfo();
if (fillPatchSet) {

View File

@@ -59,4 +59,11 @@ public class ListRevisionDrafts implements RestReadView<RevisionResource> {
.setFillAccounts(includeAuthorInfo())
.format(listComments(rsrc));
}
public List<CommentInfo> getComments(RevisionResource rsrc)
throws OrmException {
return commentJson.get()
.setFillAccounts(includeAuthorInfo())
.formatAsList(listComments(rsrc));
}
}