BrightSide Workbench Full Report + Source Code
IssueNotification.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.dossier.issue;
19 
20 import java.util.ArrayList;
21 import java.util.List;
22 import org.amic.util.string.Strings;
23 import org.turro.action.Contacts;
24 import org.turro.action.LinkType;
25 import org.turro.dossier.command.DossierEntityInfo;
26 import org.turro.dossier.entity.IDossierParticipant;
27 import org.turro.dossier.entity.Issue;
28 import org.turro.dossier.entity.IssueParticipant;
29 import org.turro.elephant.context.IConstructor;
30 import org.turro.elephant.impl.util.StringParser;
31 import org.turro.elephant.util.DateFormats;
32 import org.turro.elephant.util.DecimalFormats;
33 import org.turro.html.HTMLGenerator;
34 import org.turro.i18n.I_;
35 import org.turro.mail.impl.MessagePool;
36 import org.turro.path.Path;
37 import org.turro.plugin.contacts.IContact;
38 import org.turro.plugin.contacts.ILinkSolver;
39 import org.turro.plugin.contacts.MailContact;
40 import org.turro.util.Chars;
41 
46 public class IssueNotification {
47 
48  private String comment;
49  private Issue issue;
50 
51  public IssueNotification(String comment, Issue issue) {
52  this.comment = comment != null ? comment.trim() : null;
53  this.issue = issue;
54  }
55 
56  public void sendMail(IConstructor constructor) {
58  getPlayers(constructor),
59  getLinkString(),
60  getSubject(constructor),
61  getMessage(constructor),
62  "",
63  new ILinkSolver() {
64  @Override
65  public String getLink(IContact contact) {
67  new Path("/issue/" + issue.getId()), contact, LinkType.WEB_INTERNAL);
68  }
69  },
70  "IMailPool_Dossier");
71  }
72 
73  public void poolMail(IConstructor constructor, MessagePool pool) {
75  getPlayers(constructor),
76  getLinkString(),
77  getMessage(constructor),
78  "",
79  new ILinkSolver() {
80  @Override
81  public String getLink(IContact contact) {
83  new Path("/issue/" + issue.getId()), contact, LinkType.WEB_INTERNAL);
84  }
85  },
86  pool);
87  }
88 
89  private String getLinkString() {
90  return issue.getDescription();
91  }
92 
93  private String getSubject(IConstructor constructor) {
94  return "[" + I_.get("Issue") + " #" + issue.getId() + " " +
95  I_.get("Issue notifier") + "] " + issue.getDescription() +
96  (issue.getDossier() != null ? Chars.forward().spaced() + issue.getDossier().getFullDescription() : "");
97  }
98 
99  private String getMessage(IConstructor constructor) {
100  HTMLGenerator hg = new HTMLGenerator();
101  hg.startTable("cellspacing='5px' width='100%' style='padding:5px;background-color:#fefefe;color:#444444;border: solid 1px #eeeeee;font-size:12px;font-family:verdana'");
102  hg.startTableCol("");
103  if(issue.getDossier() != null) {
104  hg.startTag("p", " style='color:gray; font-size:11px;'")
105  .write(issue.getDossier().getFullDescription())
106  .endTag();
107  }
108  hg.startTag("p")
109  .write(I_.get("Issue notifier") + " " +
110  I_.get("Issue") + " #" + issue.getId())
111  .endTag();
112  hg.startTag("p")
113  .write("{linkTmpSes}")
114  .endTag();
115  hg.endTableRow();
116 
117  hg.startTableCol("");
118  if(issue.getStartDate() != null) {
119  hg.startTag("p")
120  .startTag("b")
121  .write(I_.get("Start Date") + ": ")
122  .endTag()
123  .write(DateFormats.format(issue.getStartDate(), true))
124  .endTag();
125  }
126  if(issue.getControlDate() != null) {
127  hg.startTag("p")
128  .startTag("b")
129  .write(I_.get("Control Date") + ": ")
130  .endTag()
131  .write(DateFormats.format(issue.getControlDate(), true))
132  .endTag();
133  }
134  if(issue.getDelivery() != null) {
135  hg.startTag("p")
136  .startTag("b")
137  .write(I_.get("Delivery") + ": ")
138  .endTag()
139  .write(DateFormats.format(issue.getDelivery(), true))
140  .endTag();
141  }
142  hg.endTableRow();
143 
144  if(issue.hasData()) {
145  hg.startTableCol("");
146  if(issue.getExpenses() != 0) {
147  hg.startTag("p")
148  .startTag("b")
149  .write(I_.get("Expenses") + ": ")
150  .endTag()
151  .write(DecimalFormats.format(issue.getExpenses()) + " / " + DecimalFormats.format(issue.getSumExpenses()))
152  .endTag();
153  }
154  if(issue.getHours() != 0) {
155  hg.startTag("p")
156  .startTag("b")
157  .write(I_.get("Hours") + ": ")
158  .endTag()
159  .write(DecimalFormats.format(issue.getHours()) + " / " + DecimalFormats.format(issue.getSumHours()))
160  .endTag();
161  }
162  if(issue.getPrice() != 0) {
163  hg.startTag("p")
164  .startTag("b")
165  .write(I_.get("Price") + ": ")
166  .endTag()
167  .write(DecimalFormats.format(issue.getPrice()) + " / " + DecimalFormats.format(issue.getSumPrice()))
168  .endTag();
169  }
170  hg.endTableRow();
171  }
172 
173  if(!Strings.isBlank(comment)) {
174  hg.startTableCol("")
175  .startTag("div", " style='border-bottom: solid 1px #eeeeee;font-weight:bold'")
176  .write(I_.get("Comment"))
177  .endTag()
178  .startTag("p")
179  .write(StringParser.toHTML(comment))
180  .endTag()
181  .endTableRow();
182  }
183  hg.startTableCol("")
184  .startTag("div", " style='border-bottom: solid 1px #eeeeee;font-weight:bold'")
185  .write(I_.get("Participants"))
186  .endTag()
187  .startTag("p");
188  for(IssueParticipant ip : issue.getParticipants()) {
189  hg.write(ip.getName() + ": " + I_.byKey(ip.getRole().toString()))
190  .writeNewLine();
191  }
192  if(issue.getDossier() != null) {
193  for(IDossierParticipant p : issue.getDossier().getFullParticipants()) {
194  if(p.isReceiveAllEmails()) {
195  hg.write("- " + p.getName() + ": " + I_.byKey(p.getRole().toString()))
196  .writeNewLine();
197  }
198  }
199  }
200  hg.endAllTags();
201  return hg.toString();
202  }
203 
204  private List<IContact> getPlayers(IConstructor constructor) {
205  ArrayList<IContact> list = new ArrayList<>();
206  for(IssueParticipant ip : issue.getParticipants()) {
207  IContact ic = Contacts.getContact(ip.getIdContact());
208  if(ic.isValid() && ic.isWebUser()) {
209  list.add(ic);
210  }
211  }
212 // if(issue.getDossier() != null) {
213 // for(IDossierParticipant p : issue.getDossier().getFullParticipants()) {
214 // IContact ic = PluginChecker.getIContact();
215 // if(p.isReceiveAllEmails() && p.getIdContact() != null) {
216 // ic.loadById(p.getIdContact());
217 // list.add(ic);
218 // }
219 // }
220 // }
221  return list;
222  }
223 
224 }
static String linkForPath(Path path, IContact contact, LinkType type)
ParticipantSet< IDossierParticipant > getFullParticipants()
Definition: Dossier.java:369
Set< IssueParticipant > getParticipants()
Definition: Issue.java:113
void poolMail(IConstructor constructor, MessagePool pool)
IssueNotification(String comment, Issue issue)
void sendMail(IConstructor constructor)
static void poolToIPlayers(List< IContact > contacts, String link, String message, String comment, ILinkSolver exParam, MessagePool pool)
static void sendToIPlayers(List< IContact > contacts, String link, String subject, String message, String comment, ILinkSolver exParam, String implementation)