Line data Source code
1 : // Copyright (C) 2016 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.mail.send; 16 : 17 : import com.google.gerrit.entities.Account; 18 : import com.google.gerrit.entities.Change; 19 : import com.google.gerrit.entities.Project; 20 : import com.google.gerrit.exceptions.EmailException; 21 : import com.google.gerrit.extensions.api.changes.RecipientType; 22 : import com.google.inject.Inject; 23 : import com.google.inject.assistedinject.Assisted; 24 : 25 : /** 26 : * Sender that informs a user by email that they were set as assignee on a change. 27 : * 28 : * <p>In contrast to other change emails this email is not sent to the change authors (owner, patch 29 : * set uploader, author). This is why this class extends {@link ChangeEmail} directly, instead of 30 : * extending {@link ReplyToChangeSender}. 31 : */ 32 : public class SetAssigneeSender extends ChangeEmail { 33 : public interface Factory { 34 : SetAssigneeSender create(Project.NameKey project, Change.Id changeId, Account.Id assignee); 35 : } 36 : 37 : private final Account.Id assignee; 38 : 39 : @Inject 40 : public SetAssigneeSender( 41 : EmailArguments args, 42 : @Assisted Project.NameKey project, 43 : @Assisted Change.Id changeId, 44 : @Assisted Account.Id assignee) { 45 6 : super(args, "setassignee", newChangeData(args, project, changeId)); 46 6 : this.assignee = assignee; 47 6 : } 48 : 49 : @Override 50 : protected void init() throws EmailException { 51 6 : super.init(); 52 : 53 6 : add(RecipientType.TO, assignee); 54 6 : } 55 : 56 : @Override 57 : protected void formatChange() throws EmailException { 58 6 : appendText(textTemplate("SetAssignee")); 59 6 : if (useHtml()) { 60 6 : appendHtml(soyHtmlTemplate("SetAssigneeHtml")); 61 : } 62 6 : } 63 : 64 : @Override 65 : protected void setupSoyContext() { 66 6 : super.setupSoyContext(); 67 6 : soyContextEmailData.put("assigneeName", getNameFor(assignee)); 68 6 : } 69 : }