use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class StreamEventsApiListener method onPrivateStateChanged.
@Override
public void onPrivateStateChanged(PrivateStateChangedListener.Event ev) {
try {
ChangeNotes notes = getNotes(ev.getChange());
Change change = notes.getChange();
PatchSet patchSet = getPatchSet(notes, ev.getRevision());
PrivateStateChangedEvent event = new PrivateStateChangedEvent(change);
event.change = changeAttributeSupplier(change, notes);
event.changer = accountAttributeSupplier(ev.getWho());
event.patchSet = patchSetAttributeSupplier(change, patchSet);
dispatcher.run(d -> d.postEvent(change, event));
} catch (StorageException e) {
logger.atSevere().withCause(e).log("Failed to dispatch event");
}
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class StreamEventsApiListener method onVoteDeleted.
@Override
public void onVoteDeleted(VoteDeletedListener.Event ev) {
try {
ChangeNotes notes = getNotes(ev.getChange());
Change change = notes.getChange();
VoteDeletedEvent event = new VoteDeletedEvent(change);
event.change = changeAttributeSupplier(change, notes);
event.patchSet = patchSetAttributeSupplier(change, psUtil.current(notes));
event.comment = ev.getMessage();
event.reviewer = accountAttributeSupplier(ev.getReviewer());
event.remover = accountAttributeSupplier(ev.getWho());
event.approvals = approvalsAttributeSupplier(change, ev.getApprovals(), ev.getOldApprovals());
dispatcher.run(d -> d.postEvent(change, event));
} catch (StorageException e) {
logger.atSevere().withCause(e).log("Failed to dispatch event");
}
}
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 {
String uuid = id.get();
ChangeNotes notes = rev.getNotes();
for (RobotComment c : commentsUtil.robotCommentsByPatchSet(notes, rev.getPatchSet().id())) {
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 VisibleChangesCache method visibleChangesByScan.
private void visibleChangesByScan() throws PermissionBackendException {
visibleChanges = new HashMap<>();
Project.NameKey p = projectState.getNameKey();
ImmutableList<ChangeNotesResult> changes;
try {
changes = changeNotesFactory.scan(repository, p).collect(toImmutableList());
} catch (IOException e) {
logger.atSevere().withCause(e).log("Cannot load changes for project %s, assuming no changes are visible", p);
return;
}
for (ChangeNotesResult notesResult : changes) {
ChangeNotes notes = toNotes(notesResult);
if (notes != null) {
visibleChanges.put(notes.getChangeId(), notes.getChange().getDest());
}
}
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class ChangeFinder method asChangeNotes.
private List<ChangeNotes> asChangeNotes(List<ChangeData> cds) {
List<ChangeNotes> notes = new ArrayList<>(cds.size());
if (!indexConfig.separateChangeSubIndexes()) {
for (ChangeData cd : cds) {
try {
notes.add(cd.notes());
} catch (NoSuchChangeException e) {
logger.atWarning().log("Change %s seen in index, but missing in NoteDb", e.getMessage());
}
}
return notes;
}
// If an index implementation uses separate non-atomic subindexes, it's possible to temporarily
// observe a change as present in both subindexes, if this search is concurrent with a write.
// Dedup to avoid confusing the caller. We can choose an arbitrary ChangeData instance because
// the index results have no stored fields, so the data is already reloaded. (It's also possible
// that a change might appear in zero subindexes, but there's nothing we can do here to help
// this case.)
Set<Change.Id> seen = Sets.newHashSetWithExpectedSize(cds.size());
for (ChangeData cd : cds) {
if (seen.add(cd.getId())) {
try {
notes.add(cd.notes());
} catch (NoSuchChangeException e) {
logger.atWarning().log("Change %s seen in index, but missing in NoteDb", e.getMessage());
}
}
}
return notes;
}
Aggregations