BrightSide Workbench Full Report + Source Code
MyIssuesNotifier.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.Date;
21 import java.util.List;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import org.apache.commons.mail.EmailException;
25 import org.turro.action.Contacts;
26 import org.turro.dossier.db.DossierPU;
27 import org.turro.dossier.entity.IssueStatus;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.db.WhereClause;
30 import org.turro.i18n.I_;
31 import org.turro.plugin.contacts.ContactList;
32 import org.turro.plugin.contacts.IContact;
33 import org.turro.scheduler.motor.DefaultTask;
34 
39 public class MyIssuesNotifier extends DefaultTask {
40 
41  @Override
42  public String getName() {
43  return I_.get("My issues notifier");
44  }
45 
46  @Override
47  public void run() {
48  ContactList list = new ContactList();
49  for(String idContact : getParticipants()) {
50  IContact ic = Contacts.getContactById(idContact);
51  if(ic.isValid() && ic.isWebUser()) {
52  list.add(ic);
53  }
54  }
55  for(IContact c : list) {
56  try {
58  } catch (EmailException ex) {
59  Logger.getLogger(MyIssuesNotifier.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
60  }
61  }
62  }
63 
64  private List<String> getParticipants() {
65  Date now = new Date();
66  WhereClause wc = new WhereClause();
67  wc.addClause("select distinct ip.idContact from IssueParticipant as ip");
68  wc.addClause("where ip.issue.status <> :status");
70  wc.addClause("and (ip.issue.startDate is null or ip.issue.startDate <= :date)");
71  wc.addNamedValue("date", now);
72  return new DossierPU().getResultList(wc);
73  }
74 
75  @Override
76  public String getDataLabel() {
77  return null;
78  }
79 
80 }
static IContact getContactById(String id)
Definition: Contacts.java:72
void addNamedValue(String name, Object value)
static String get(String msg)
Definition: I_.java:41