BrightSide Workbench Full Report + Source Code
MyIssuesNotification.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.net.URLEncoder;
21 import java.util.EnumSet;
22 import java.util.HashMap;
23 import org.apache.commons.mail.EmailException;
24 import org.turro.action.Actions;
25 import org.turro.action.LinkType;
26 import org.turro.action.queue.NotificationCategory;
27 import org.turro.dossier.command.DossierEntityInfo;
28 import org.turro.dossier.db.DossierPU;
29 import org.turro.dossier.entity.Issue;
30 import org.turro.dossier.util.DossierElephantNotification;
31 import org.turro.dossier.workload.WorkloadItem;
32 import org.turro.dossier.workload.WorkloadQuery;
33 import org.turro.dossier.workload.WorkloadSet;
34 import org.turro.dossier.zul.issue.IssueStage;
35 import org.turro.elephant.context.ElephantContext;
36 import org.turro.elephant.context.IConstructor;
37 import org.turro.elephant.security.IUser;
38 import org.turro.i18n.I_;
39 import org.turro.mail.message.MailMessageTemplate;
40 import org.turro.mail.pool.MailMessagePool;
41 import org.turro.mail.provider.MailProviders;
42 import org.turro.mail.queue.QueueManager;
43 import org.turro.marker.ElephantMarker;
44 import org.turro.path.Path;
45 import org.turro.plugin.contacts.IContact;
46 
51 public class MyIssuesNotification {
52 
53  private final IContact contact;
54 
55  public MyIssuesNotification(IContact contact) {
56  this.contact = contact;
57  }
58 
59  public void sendMailTemplate(IConstructor constructor) throws EmailException {
60  WorkloadQuery wq = new WorkloadQuery(contact);
61  WorkloadSet ws = wq.getResults();
62  ws.keep(EnumSet.of(
67  if(!ws.isEmpty()) {
68  MailMessagePool pool = MailProviders.instance().getPool(constructor, "Dossier");
69  if(pool != null) {
71  mmt.setRoot("/issues");
72  mmt.setSubject(getSubject(constructor));
73  mmt.addTo(contact.getConnector(IUser.CONNECTOR_EMAIL), contact.getName());
74  ElephantMarker em = new ElephantMarker(constructor, true);
75  em.put("workloadSet", ws);
76  em.put("contact", contact);
77  em.put("email", contact.getConnector(IUser.CONNECTOR_EMAIL));
78  em.put("notifier", this);
79  mmt.setMessage(em, "myissues", contact);
80  pool.addToPool(mmt);
81  }
82  pool.sendPool();
83  }
84  }
85 
86  public void addToQueue(IConstructor constructor) throws EmailException {
87  QueueManager qm = new QueueManager();
89  if(qm.contactMayWant(contact, nc.getIdCategory())) {
90  WorkloadQuery wq = new WorkloadQuery(contact);
91  WorkloadSet ws = wq.getResults();
92  ws.keep(EnumSet.of(
97  if(!ws.isEmpty()) {
99  mmt.setRoot("/issues");
100  mmt.setSubject(getSubject(constructor));
101  mmt.addTo(contact.getConnector(IUser.CONNECTOR_EMAIL), contact.getName());
102  ElephantMarker em = new ElephantMarker(constructor, true);
103  em.put("workloadSet", ws);
104  em.put("contact", contact);
105  em.put("email", contact.getConnector(IUser.CONNECTOR_EMAIL));
106  em.put("notifier", this);
107  mmt.setMessage(em, "myissues", contact);
108  qm.addToQueue(nc, contact, mmt, null, "Dossier");
109  }
110  }
111  }
112 
113  public String create(IConstructor constructor, Issue issue, IContact contact) throws Exception {
114  return create(constructor,
117  }
118 
119  public String create(IConstructor constructor, String redir, IContact contact) throws Exception {
120  return create(constructor, redir,
122  }
123 
124  public String create(IConstructor constructor, String redir, String email) throws Exception {
125  HashMap<String, String> values = new HashMap<>();
126  values.put(Actions.USER_PAR, email);
127  values.put(Actions.REDIR_PAR, URLEncoder.encode(redir, "UTF-8"));
128  return Actions.createAction(values, 7, false);
129  }
130 
131  public String createRef(IConstructor constructor, Issue issue) throws Exception {
132  return createRef(constructor,
134  }
135 
136  public String createRef(IConstructor constructor, String redir) throws Exception {
137  return "{liveref:" + redir + "}";
138  }
139 
141  return WorkloadSet.getStage(item);
142  }
143 
144  private String getSubject(IConstructor constructor) {
145  return "[" + I_.get("Issue notifier") + " " + ElephantContext.getSiteName() + "]";
146  }
147 
148 }
static String createAction(String email, String redir)
Definition: Actions.java:90
static final String USER_PAR
Definition: Actions.java:66
static String linkForPath(Path path, IContact contact, LinkType type)
static String getObjectPath(Object object)
Definition: DossierPU.java:66
String createRef(IConstructor constructor, Issue issue)
String createRef(IConstructor constructor, String redir)
String create(IConstructor constructor, Issue issue, IContact contact)
String create(IConstructor constructor, String redir, String email)
String create(IConstructor constructor, String redir, IContact contact)
static String get(String msg)
Definition: I_.java:41
MailMessage addToPool(String from, String to, String cc, String subject, String message)
MailProvider getProvider(String name)
MailMessagePool getPool(IConstructor constructor, String name)
MailItem addToQueue(NotificationCategory category, IContact contact, MailMessage mmt, String reason, String poolName)
boolean contactMayWant(IContact contact, String idCategory)
Object put(Object key, Object value)
static final String CONNECTOR_EMAIL
Definition: IUser.java:27