use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class RobotComments method parse.
@Override
public RobotCommentResource parse(RevisionResource rev, IdString id) throws ResourceNotFoundException, OrmException {
String uuid = id.get();
ChangeNotes notes = rev.getNotes();
for (RobotComment c : commentsUtil.robotCommentsByPatchSet(notes, rev.getPatchSet().getId())) {
if (uuid.equals(c.key.uuid)) {
return new RobotCommentResource(rev, c);
}
}
throw new ResourceNotFoundException(id);
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class UnfusedNoteDbBatchUpdate method newChangeContext.
private ChangeContextImpl newChangeContext(Change.Id id) throws OrmException {
logDebug("Opening change {} for update", id);
Change c = newChanges.get(id);
boolean isNew = c != null;
if (!isNew) {
// Pass a synthetic change into ChangeNotes.Factory, which will take care of checking for
// existence and populating columns from the parsed notes state.
// TODO(dborowitz): This dance made more sense when using Reviewdb; consider a nicer way.
c = ChangeNotes.Factory.newNoteDbOnlyChange(project, id);
} else {
logDebug("Change {} is new", id);
}
ChangeNotes notes = changeNotesFactory.createForBatchUpdate(c, !isNew);
ChangeControl ctl = changeControlFactory.controlFor(notes, user);
return new ChangeContextImpl(ctl);
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class FusedNoteDbBatchUpdate method newChangeContext.
private ChangeContextImpl newChangeContext(Change.Id id) throws OrmException {
logDebug("Opening change {} for update", id);
Change c = newChanges.get(id);
boolean isNew = c != null;
if (!isNew) {
// Pass a synthetic change into ChangeNotes.Factory, which will take care of checking for
// existence and populating columns from the parsed notes state.
// TODO(dborowitz): This dance made more sense when using Reviewdb; consider a nicer way.
c = ChangeNotes.Factory.newNoteDbOnlyChange(project, id);
} else {
logDebug("Change {} is new", id);
}
ChangeNotes notes = changeNotesFactory.createForBatchUpdate(c, !isNew);
ChangeControl ctl = changeControlFactory.controlFor(notes, user);
return new ChangeContextImpl(ctl);
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class ChangeRebuilderIT method highestNumberedPatchSetIsNotCurrent.
@Test
public void highestNumberedPatchSetIsNotCurrent() throws Exception {
PushOneCommit.Result r1 = createChange();
PatchSet.Id psId1 = r1.getPatchSetId();
Change.Id id = psId1.getParentKey();
PushOneCommit.Result r2 = amendChange(r1.getChangeId());
PatchSet.Id psId2 = r2.getPatchSetId();
try (BatchUpdate bu = batchUpdateFactory.create(db, project, identifiedUserFactory.create(user.getId()), TimeUtil.nowTs())) {
bu.addOp(id, new BatchUpdateOp() {
@Override
public boolean updateChange(ChangeContext ctx) throws PatchSetInfoNotAvailableException {
ctx.getChange().setCurrentPatchSet(patchSetInfoFactory.get(ctx.getDb(), ctx.getNotes(), psId1));
return true;
}
});
bu.execute();
}
ChangeNotes notes = notesFactory.create(db, project, id);
assertThat(psUtil.byChangeAsMap(db, notes).keySet()).containsExactly(psId1, psId2);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId1);
assertThat(db.changes().get(id).currentPatchSetId()).isEqualTo(psId1);
checker.rebuildAndCheckChanges(id);
setNotesMigration(true, true);
notes = notesFactory.create(db, project, id);
assertThat(psUtil.byChangeAsMap(db, notes).keySet()).containsExactly(psId1, psId2);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId1);
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class ReceiveCommits method foundInExistingRef.
private boolean foundInExistingRef(Collection<Ref> existingRefs) throws OrmException {
for (Ref ref : existingRefs) {
ChangeNotes notes = notesFactory.create(db, project.getNameKey(), Change.Id.fromRef(ref.getName()));
Change change = notes.getChange();
if (change.getDest().equals(magicBranch.dest)) {
logDebug("Found change {} from existing refs.", change.getKey());
// Reindex the change asynchronously, ignoring errors.
@SuppressWarnings("unused") Future<?> possiblyIgnoredError = indexer.indexAsync(project.getNameKey(), change.getId());
return true;
}
}
return false;
}
Aggregations