BrightSide Workbench Full Report + Source Code
AcceptanceMail.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.acceptance;
19 
20 import java.util.List;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.apache.commons.mail.EmailException;
24 import org.turro.action.IAcceptance;
25 import org.turro.auth.Authentication;
26 import org.turro.elephant.context.ElephantContext;
27 import org.turro.i18n.I_;
28 import org.turro.mail.sender.MailPool;
29 import org.turro.plugin.contacts.ContactList;
30 import org.turro.plugin.contacts.IContact;
31 
36 public class AcceptanceMail {
37 
38  private final IAcceptance acceptance;
39 
40  public AcceptanceMail(IAcceptance acceptance) {
41  this.acceptance = acceptance;
42  }
43 
44  public void sendMail() {
45  if(acceptance == null) return;
46  try {
47  new MailPool()
48  .setRoot("/acceptances")
49  .addContacts(getPlayers())
50  .put("reason", I_.format("%s has modified", Authentication.getIContact().getName()))
51  .put("acceptance", acceptance)
52  .sendTemplate("requiredAcceptance", getSubject());
53  } catch (EmailException ex) {
54  Logger.getLogger(AcceptanceMail.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(acceptance.getPath()), ex);
55  }
56  }
57 
58  private String getSubject() {
59  return "[" + I_.get("Acceptance") + "] " + acceptance.getEntity().getName() + " : " + ElephantContext.getSiteName();
60  }
61 
62  private List<IContact> getPlayers() {
63  ContactList list = new ContactList();
64  list.add(acceptance.getIContact());
65  list.add(acceptance.getIPetitioner());
66  return list;
67  }
68 
69 }
AcceptanceMail(IAcceptance acceptance)
static String format(String msg, Object... arguments)
Definition: I_.java:49
static String get(String msg)
Definition: I_.java:41
IElephantEntity getEntity()
T addContacts(Collection< IContact > contacts)