Add PatchLineCommentsUtil to assist with notedb migration

Like ApprovalsUtil and ChangeMessagesUtil, we added an abstraction
layer to assist in the migration to notedb. So far, we have only
migrated published comments over to the notedb (drafts still are only
stored in the reviewdb). This utility class helps to read published
comments from either the notedb or the ReviewDb depending on the state
of the NotesMigration instance.

Additionally, in this change, I modified all callers of
PatchLineCommentAccess that query for only published comments to
instead use the corresponding methods in the PatchLineCommentsUtil.

Finally, the test class, CommentsTest, had to be modified to add the
ability to test reading published comments from the notedb, so I
created a separate Config in that class to test the notedb path.

Change-Id: I3a5637dda5d97df335c40d5cda22165ecf1d8232
This commit is contained in:
Yacob Yonas
2014-07-02 16:31:27 -07:00
parent 712022f675
commit d710c0cfd8
10 changed files with 341 additions and 36 deletions

View File

@@ -34,10 +34,12 @@ import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.PatchLineCommentsUtil;
import com.google.gerrit.server.change.ChangesCollection;
import com.google.gerrit.server.change.RevisionResource;
import com.google.gerrit.server.change.Revisions;
import com.google.gerrit.server.extensions.webui.UiActions;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.patch.PatchList;
import com.google.gerrit.server.patch.PatchListCache;
import com.google.gerrit.server.patch.PatchListKey;
@@ -78,6 +80,7 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
private final ChangeControl.Factory changeControlFactory;
private final ChangesCollection changes;
private final Revisions revisions;
private final PatchLineCommentsUtil plcUtil;
private Project.NameKey projectKey;
private final PatchSet.Id psIdBase;
@@ -96,6 +99,7 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
final ChangeControl.Factory changeControlFactory,
final ChangesCollection changes,
final Revisions revisions,
final PatchLineCommentsUtil plcUtil,
@Assisted("psIdBase") @Nullable final PatchSet.Id psIdBase,
@Assisted("psIdNew") final PatchSet.Id psIdNew,
@Assisted @Nullable final AccountDiffPreference diffPrefs) {
@@ -105,6 +109,7 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
this.changeControlFactory = changeControlFactory;
this.changes = changes;
this.revisions = revisions;
this.plcUtil = plcUtil;
this.psIdBase = psIdBase;
this.psIdNew = psIdNew;
@@ -143,7 +148,8 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
byKey.put(p.getKey(), p);
}
for (final PatchLineComment c : db.patchComments().publishedByPatchSet(psIdNew)) {
ChangeNotes notes = control.getNotes();
for (PatchLineComment c : plcUtil.publishedByPatchSet(db, notes, psIdNew)) {
final Patch p = byKey.get(c.getKey().getParentKey());
if (p != null) {
p.setCommentCount(p.getCommentCount() + 1);