Search in sources :

Example 1 with ModifyReviewerSender

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

the class ModifyReviewersEmail method emailReviewersAsync.

public void emailReviewersAsync(IdentifiedUser user, Change change, Collection<Account.Id> added, Collection<Account.Id> copied, Collection<Account.Id> removed, Collection<Address> addedByEmail, Collection<Address> copiedByEmail, Collection<Address> removedByEmail, NotifyResolver.Result notify) {
    // The user knows they added/removed themselves, don't bother emailing them.
    Account.Id userId = user.getAccountId();
    ImmutableList<Account.Id> immutableToMail = added.stream().filter(id -> !id.equals(userId)).collect(toImmutableList());
    ImmutableList<Account.Id> immutableToCopy = copied.stream().filter(id -> !id.equals(userId)).collect(toImmutableList());
    ImmutableList<Account.Id> immutableToRemove = removed.stream().filter(id -> !id.equals(userId)).collect(toImmutableList());
    if (immutableToMail.isEmpty() && immutableToCopy.isEmpty() && immutableToRemove.isEmpty() && addedByEmail.isEmpty() && copiedByEmail.isEmpty() && removedByEmail.isEmpty()) {
        return;
    }
    // Make immutable copies of collections and hand over only immutable data types to the other
    // thread.
    Change.Id cId = change.getId();
    Project.NameKey projectNameKey = change.getProject();
    ImmutableList<Address> immutableAddedByEmail = ImmutableList.copyOf(addedByEmail);
    ImmutableList<Address> immutableCopiedByEmail = ImmutableList.copyOf(copiedByEmail);
    ImmutableList<Address> immutableRemovedByEmail = ImmutableList.copyOf(removedByEmail);
    @SuppressWarnings("unused") Future<?> possiblyIgnoredError = sendEmailsExecutor.submit(() -> {
        try {
            ModifyReviewerSender emailSender = addReviewerSenderFactory.create(projectNameKey, cId);
            emailSender.setNotify(notify);
            emailSender.setFrom(userId);
            emailSender.addReviewers(immutableToMail);
            emailSender.addReviewersByEmail(immutableAddedByEmail);
            emailSender.addExtraCC(immutableToCopy);
            emailSender.addExtraCCByEmail(immutableCopiedByEmail);
            emailSender.addRemovedReviewers(immutableToRemove);
            emailSender.addRemovedByEmailReviewers(immutableRemovedByEmail);
            emailSender.setMessageId(messageIdGenerator.fromChangeUpdate(change.getProject(), change.currentPatchSetId()));
            emailSender.send();
        } catch (Exception err) {
            logger.atSevere().withCause(err).log("Cannot send email to new reviewers of change %s", change.getId());
        }
    });
}
Also used : ModifyReviewerSender(com.google.gerrit.server.mail.send.ModifyReviewerSender) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Inject(com.google.inject.Inject) Collection(java.util.Collection) Account(com.google.gerrit.entities.Account) MessageIdGenerator(com.google.gerrit.server.mail.send.MessageIdGenerator) Future(java.util.concurrent.Future) ImmutableList(com.google.common.collect.ImmutableList) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) Project(com.google.gerrit.entities.Project) Change(com.google.gerrit.entities.Change) Address(com.google.gerrit.entities.Address) FluentLogger(com.google.common.flogger.FluentLogger) ExecutorService(java.util.concurrent.ExecutorService) SendEmailExecutor(com.google.gerrit.server.config.SendEmailExecutor) Singleton(com.google.inject.Singleton) Account(com.google.gerrit.entities.Account) Address(com.google.gerrit.entities.Address) Change(com.google.gerrit.entities.Change) Project(com.google.gerrit.entities.Project) ModifyReviewerSender(com.google.gerrit.server.mail.send.ModifyReviewerSender)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 FluentLogger (com.google.common.flogger.FluentLogger)1 Account (com.google.gerrit.entities.Account)1 Address (com.google.gerrit.entities.Address)1 Change (com.google.gerrit.entities.Change)1 Project (com.google.gerrit.entities.Project)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1 SendEmailExecutor (com.google.gerrit.server.config.SendEmailExecutor)1 MessageIdGenerator (com.google.gerrit.server.mail.send.MessageIdGenerator)1 ModifyReviewerSender (com.google.gerrit.server.mail.send.ModifyReviewerSender)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 Collection (java.util.Collection)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1