Search in sources :

Example 1 with AddReviewerSender

use of com.google.gerrit.server.mail.send.AddReviewerSender in project gerrit by GerritCodeReview.

the class PostReviewersOp method emailReviewers.

public void emailReviewers(Change change, Collection<Account.Id> added, Collection<Account.Id> copied, Collection<Address> addedByEmail, Collection<Address> copiedByEmail, NotifyHandling notify, ListMultimap<RecipientType, Account.Id> accountsToNotify) {
    if (added.isEmpty() && copied.isEmpty() && addedByEmail.isEmpty() && copiedByEmail.isEmpty()) {
        return;
    }
    // Email the reviewers
    //
    // The user knows they added themselves, don't bother emailing them.
    List<Account.Id> toMail = Lists.newArrayListWithCapacity(added.size());
    Account.Id userId = user.get().getAccountId();
    for (Account.Id id : added) {
        if (!id.equals(userId)) {
            toMail.add(id);
        }
    }
    List<Account.Id> toCopy = Lists.newArrayListWithCapacity(copied.size());
    for (Account.Id id : copied) {
        if (!id.equals(userId)) {
            toCopy.add(id);
        }
    }
    if (toMail.isEmpty() && toCopy.isEmpty() && addedByEmail.isEmpty() && copiedByEmail.isEmpty()) {
        return;
    }
    try {
        AddReviewerSender cm = addReviewerSenderFactory.create(change.getProject(), change.getId());
        cm.setNotify(MoreObjects.firstNonNull(notify, NotifyHandling.ALL));
        cm.setAccountsToNotify(accountsToNotify);
        cm.setFrom(userId);
        cm.addReviewers(toMail);
        cm.addReviewersByEmail(addedByEmail);
        cm.addExtraCC(toCopy);
        cm.addExtraCCByEmail(copiedByEmail);
        cm.send();
    } catch (Exception err) {
        log.error("Cannot send email to new reviewers of change " + change.getId(), err);
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) AddReviewerSender(com.google.gerrit.server.mail.send.AddReviewerSender) OrmException(com.google.gwtorm.server.OrmException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) IOException(java.io.IOException)

Aggregations

RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 Account (com.google.gerrit.reviewdb.client.Account)1 AddReviewerSender (com.google.gerrit.server.mail.send.AddReviewerSender)1 OrmException (com.google.gwtorm.server.OrmException)1 IOException (java.io.IOException)1