com.google.gerrit.server.mail.send.DeleteReviewerSender Maven / Gradle / Ivy
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.mail.send;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Address;
import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.NotifyConfig.NotifyType;
import com.google.gerrit.entities.Project;
import com.google.gerrit.exceptions.EmailException;
import com.google.gerrit.extensions.api.changes.RecipientType;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/** Let users know that a reviewer and possibly her review have been removed. */
public class DeleteReviewerSender extends ReplyToChangeSender {
private final Set reviewers = new HashSet<>();
private final Set reviewersByEmail = new HashSet<>();
public interface Factory extends ReplyToChangeSender.Factory {
@Override
DeleteReviewerSender create(Project.NameKey project, Change.Id changeId);
}
@Inject
public DeleteReviewerSender(
EmailArguments args, @Assisted Project.NameKey project, @Assisted Change.Id changeId) {
super(args, "deleteReviewer", newChangeData(args, project, changeId));
}
public void addReviewers(Collection cc) {
reviewers.addAll(cc);
}
public void addReviewersByEmail(Collection cc) {
reviewersByEmail.addAll(cc);
}
@Override
protected void init() throws EmailException {
super.init();
ccAllApprovals();
bccStarredBy();
ccExistingReviewers();
includeWatchers(NotifyType.ALL_COMMENTS);
reviewers.stream().forEach(r -> addByAccountId(RecipientType.TO, r));
reviewersByEmail.stream().forEach(address -> addByEmail(RecipientType.TO, address));
}
@Override
protected void formatChange() throws EmailException {
appendText(textTemplate("DeleteReviewer"));
if (useHtml()) {
appendHtml(soyHtmlTemplate("DeleteReviewerHtml"));
}
}
@Nullable
public List getReviewerNames() {
if (reviewers.isEmpty() && reviewersByEmail.isEmpty()) {
return null;
}
List names = new ArrayList<>();
for (Account.Id id : reviewers) {
names.add(getNameFor(id));
}
for (Address a : reviewersByEmail) {
names.add(a.toString());
}
return names;
}
@Override
protected void setupSoyContext() {
super.setupSoyContext();
soyContextEmailData.put("reviewerNames", getReviewerNames());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy