BrightSide Workbench Full Report + Source Code
IssueNotifier.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 org.turro.dossier.db.DossierPU;
23 import org.turro.dossier.entity.Issue;
24 import org.turro.dossier.entity.IssueStatus;
25 import org.turro.elephant.context.ElephantContext;
26 import org.turro.elephant.db.WhereClause;
27 import org.turro.i18n.I_;
28 import org.turro.mail.impl.MessagePool;
29 import org.turro.scheduler.motor.DefaultTask;
30 
35 public class IssueNotifier extends DefaultTask {
36 
37  @Override
38  public String getName() {
39  return I_.get("Issue notifier");
40  }
41 
42  @Override
43  public void run() {
44  Date now = new Date();
45  MessagePool pool = new MessagePool();
46  for(Issue issue : getIssues(now)) {
47  if((issue.getControlDate() != null && now.after(issue.getControlDate())) ||
48  (issue.getDelivery() != null && now.after(issue.getDelivery()))) {
49  new IssueNotification(I_.get("Date surpassed"), issue).poolMail(constructor, pool);
50  }
51  }
52  pool.sendIt("[" + I_.get("Issue notifier") +
53  " " + ElephantContext.getSiteName() + "]"
54  , "IMailPool_Dossier");
55  }
56 
57  private List<Issue> getIssues(Date now) {
58  WhereClause wc = new WhereClause();
59  wc.addClause("select distinct issue from Issue as issue");
60  wc.addClause("where issue.status <> :status");
62  wc.addClause("and (issue.startDate is null or issue.startDate <= :date)");
63  wc.addNamedValue("date", now);
64  return new DossierPU().getResultList(wc);
65  }
66 
67  @Override
68  public String getDataLabel() {
69  return null;
70  }
71 }
void poolMail(IConstructor constructor, MessagePool pool)
void addNamedValue(String name, Object value)
static String get(String msg)
Definition: I_.java:41
void sendIt(String subject, String implementation)