BrightSide Workbench Full Report + Source Code
MyIssuesNotifierTask.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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 
19 package org.turro.dossier.issue;
20 
21 import java.util.Date;
22 import java.util.List;
23 import org.apache.commons.mail.EmailException;
24 import org.turro.action.Contacts;
25 import org.turro.dossier.db.DossierPU;
26 import org.turro.dossier.entity.IssueStatus;
27 import org.turro.elephant.db.WhereClause;
28 import org.turro.i18n.I_;
29 import org.turro.log.WebLoggers;
30 import org.turro.plugin.contacts.ContactList;
31 import org.turro.plugin.contacts.IContact;
32 import org.turro.scheduler.task.AbstractTask;
33 
38 public class MyIssuesNotifierTask extends AbstractTask {
39 
40  @Override
41  public void execute() {
42  ContactList list = new ContactList();
43  for(String idContact : getParticipants()) {
44  IContact ic = Contacts.getContactById(idContact);
45  if(ic.isValid() && ic.isWebUser()) {
46  list.add(ic);
47  }
48  }
49  for(IContact c : list) {
50  try {
52  } catch (EmailException ex) {
53  WebLoggers.severe(this).exception(ex).log();
54  }
55  }
56  }
57 
58  @Override
59  public boolean isSystem() {
60  return false;
61  }
62 
63  @Override
64  public String getName() {
65  return I_.get("My issues notifier");
66  }
67 
68  @Override
69  public String getDataLabel() {
70  return null;
71  }
72 
73  private List<String> getParticipants() {
74  Date now = new Date();
75  WhereClause wc = new WhereClause();
76  wc.addClause("select distinct ip.idContact from IssueParticipant as ip");
77  wc.addClause("where ip.issue.status <> :status");
79  wc.addClause("and (ip.issue.startDate is null or ip.issue.startDate <= :date)");
80  wc.addNamedValue("date", now);
81  return new DossierPU().getResultList(wc);
82  }
83 
84 }
static IContact getContactById(String id)
Definition: Contacts.java:72
void addNamedValue(String name, Object value)
static String get(String msg)
Definition: I_.java:41
static WebLoggers severe(Object entity)
Definition: WebLoggers.java:51
WebLoggers exception(Throwable throwable)
Definition: WebLoggers.java:29