Search in sources :

Example 31 with OrmException

use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.

the class MergeSuperSet method topicClosure.

/**
   * Completes {@code cs} with any additional changes from its topics
   *
   * <p>{@link #completeChangeSetIncludingTopics} calls this repeatedly, alternating with {@link
   * #completeChangeSetWithoutTopic}, to discover what additional changes should be submitted with a
   * change until the set stops growing.
   *
   * <p>{@code topicsSeen} and {@code visibleTopicsSeen} keep track of topics already explored to
   * avoid wasted work.
   *
   * @return the resulting larger {@link ChangeSet}
   */
private ChangeSet topicClosure(ReviewDb db, ChangeSet cs, CurrentUser user, Set<String> topicsSeen, Set<String> visibleTopicsSeen) throws OrmException {
    List<ChangeData> visibleChanges = new ArrayList<>();
    List<ChangeData> nonVisibleChanges = new ArrayList<>();
    for (ChangeData cd : cs.changes()) {
        visibleChanges.add(cd);
        String topic = cd.change().getTopic();
        if (Strings.isNullOrEmpty(topic) || visibleTopicsSeen.contains(topic)) {
            continue;
        }
        for (ChangeData topicCd : query().byTopicOpen(topic)) {
            try {
                topicCd.changeControl(user);
                if (topicCd.changeControl().isVisible(db, topicCd)) {
                    visibleChanges.add(topicCd);
                } else {
                    nonVisibleChanges.add(topicCd);
                }
            } catch (OrmException e) {
                if (e.getCause() instanceof NoSuchChangeException) {
                // Ignore and skip this change
                } else {
                    throw e;
                }
            }
        }
        topicsSeen.add(topic);
        visibleTopicsSeen.add(topic);
    }
    for (ChangeData cd : cs.nonVisibleChanges()) {
        nonVisibleChanges.add(cd);
        String topic = cd.change().getTopic();
        if (Strings.isNullOrEmpty(topic) || topicsSeen.contains(topic)) {
            continue;
        }
        for (ChangeData topicCd : query().byTopicOpen(topic)) {
            topicCd.changeControl(user);
            nonVisibleChanges.add(topicCd);
        }
        topicsSeen.add(topic);
    }
    return new ChangeSet(visibleChanges, nonVisibleChanges);
}
Also used : NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) OrmException(com.google.gwtorm.server.OrmException) ArrayList(java.util.ArrayList) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Example 32 with OrmException

use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.

the class ChangeEditUtil method getBasePatchSet.

private PatchSet getBasePatchSet(ChangeControl ctl, Ref ref) throws IOException {
    try {
        int pos = ref.getName().lastIndexOf("/");
        checkArgument(pos > 0, "invalid edit ref: %s", ref.getName());
        String psId = ref.getName().substring(pos + 1);
        return psUtil.get(db.get(), ctl.getNotes(), new PatchSet.Id(ctl.getId(), Integer.parseInt(psId)));
    } catch (OrmException | NumberFormatException e) {
        throw new IOException(e);
    }
}
Also used : OrmException(com.google.gwtorm.server.OrmException) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) IOException(java.io.IOException)

Example 33 with OrmException

use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.

the class StreamEventsApiListener method onReviewerDeleted.

@Override
public void onReviewerDeleted(final ReviewerDeletedListener.Event ev) {
    try {
        ChangeNotes notes = getNotes(ev.getChange());
        Change change = notes.getChange();
        ReviewerDeletedEvent event = new ReviewerDeletedEvent(change);
        event.change = changeAttributeSupplier(change);
        event.patchSet = patchSetAttributeSupplier(change, psUtil.current(db.get(), notes));
        event.reviewer = accountAttributeSupplier(ev.getReviewer());
        event.comment = ev.getComment();
        event.approvals = approvalsAttributeSupplier(change, ev.getNewApprovals(), ev.getOldApprovals());
        dispatcher.get().postEvent(change, event);
    } catch (OrmException e) {
        log.error("Failed to dispatch event", e);
    }
}
Also used : OrmException(com.google.gwtorm.server.OrmException) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.reviewdb.client.Change)

Example 34 with OrmException

use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.

the class StreamEventsApiListener method onChangeMerged.

@Override
public void onChangeMerged(ChangeMergedListener.Event ev) {
    try {
        ChangeNotes notes = getNotes(ev.getChange());
        Change change = notes.getChange();
        ChangeMergedEvent event = new ChangeMergedEvent(change);
        event.change = changeAttributeSupplier(change);
        event.submitter = accountAttributeSupplier(ev.getWho());
        event.patchSet = patchSetAttributeSupplier(change, psUtil.current(db.get(), notes));
        event.newRev = ev.getNewRevisionId();
        dispatcher.get().postEvent(change, event);
    } catch (OrmException e) {
        log.error("Failed to dispatch event", e);
    }
}
Also used : OrmException(com.google.gwtorm.server.OrmException) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.reviewdb.client.Change)

Example 35 with OrmException

use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.

the class StreamEventsApiListener method onDraftPublished.

@Override
public void onDraftPublished(DraftPublishedListener.Event ev) {
    try {
        ChangeNotes notes = getNotes(ev.getChange());
        Change change = notes.getChange();
        PatchSet ps = getPatchSet(notes, ev.getRevision());
        DraftPublishedEvent event = new DraftPublishedEvent(change);
        event.change = changeAttributeSupplier(change);
        event.patchSet = patchSetAttributeSupplier(change, ps);
        event.uploader = accountAttributeSupplier(ev.getWho());
        dispatcher.get().postEvent(change, event);
    } catch (OrmException e) {
        log.error("Failed to dispatch event", e);
    }
}
Also used : OrmException(com.google.gwtorm.server.OrmException) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.reviewdb.client.Change)

Aggregations

OrmException (com.google.gwtorm.server.OrmException)172 IOException (java.io.IOException)78 Change (com.google.gerrit.reviewdb.client.Change)50 Repository (org.eclipse.jgit.lib.Repository)41 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)33 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)31 ObjectId (org.eclipse.jgit.lib.ObjectId)29 Account (com.google.gerrit.reviewdb.client.Account)28 RevWalk (org.eclipse.jgit.revwalk.RevWalk)28 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)24 ChangeData (com.google.gerrit.server.query.change.ChangeData)24 Map (java.util.Map)22 ArrayList (java.util.ArrayList)21 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)20 Inject (com.google.inject.Inject)18 Provider (com.google.inject.Provider)17 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)16 Set (java.util.Set)16 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)15 CurrentUser (com.google.gerrit.server.CurrentUser)14