Search in sources :

Example 41 with ChangeNotes

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");
    }
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.entities.Change) StorageException(com.google.gerrit.exceptions.StorageException)

Example 42 with ChangeNotes

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");
    }
}
Also used : ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.entities.Change) StorageException(com.google.gerrit.exceptions.StorageException)

Example 43 with ChangeNotes

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);
}
Also used : RobotComment(com.google.gerrit.entities.RobotComment) RobotCommentResource(com.google.gerrit.server.change.RobotCommentResource) IdString(com.google.gerrit.extensions.restapi.IdString) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 44 with ChangeNotes

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());
        }
    }
}
Also used : Project(com.google.gerrit.entities.Project) IOException(java.io.IOException) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) ChangeNotesResult(com.google.gerrit.server.notedb.ChangeNotes.Factory.ChangeNotesResult)

Example 45 with ChangeNotes

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;
}
Also used : NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) ArrayList(java.util.ArrayList) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Aggregations

ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)134 Test (org.junit.Test)54 Change (com.google.gerrit.entities.Change)47 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)43 PatchSet (com.google.gerrit.entities.PatchSet)42 ObjectId (org.eclipse.jgit.lib.ObjectId)33 StorageException (com.google.gerrit.exceptions.StorageException)22 Change (com.google.gerrit.reviewdb.client.Change)21 Project (com.google.gerrit.entities.Project)17 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 FixInput (com.google.gerrit.extensions.api.changes.FixInput)16 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)14 HumanComment (com.google.gerrit.entities.HumanComment)13 TestChanges.newPatchSet (com.google.gerrit.testing.TestChanges.newPatchSet)12 IOException (java.io.IOException)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)11 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)10 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)10 AuthException (com.google.gerrit.extensions.restapi.AuthException)9