BrightSide Workbench Full Report + Source Code
DossierNotifierTask.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.dossier;
20 
21 import java.util.Date;
22 import java.util.List;
23 import org.amic.util.date.CheckDate;
24 import org.turro.dossier.db.DossierPU;
25 import org.turro.dossier.entity.Dossier;
26 import org.turro.dossier.entity.DossierStatus;
27 import org.turro.elephant.db.WhereClause;
28 import org.turro.i18n.I_;
29 import org.turro.scheduler.task.AbstractTask;
30 
35 public class DossierNotifierTask extends AbstractTask {
36 
37  @Override
38  public void execute() {
39  Date now = new Date();
40  int days = Integer.parseInt(getSettings().getData()) * -1;
41  Date from = new CheckDate(now).addDays(days).getDate();
42  for(Dossier dossier : getDossiers(now)) {
43  DossierActivitySet das = new DossierActivitySet(dossier, from);
44  if(!das.isEmpty()) {
45  new DossierNotification(dossier, das, from).sendMail(getConstructor());
46  }
47  }
48  }
49 
50  @Override
51  public boolean isSystem() {
52  return false;
53  }
54 
55  @Override
56  public String getName() {
57  return I_.get("Dossier notifier");
58  }
59 
60  @Override
61  public String getDataLabel() {
62  return I_.get("Days");
63  }
64 
65  private List<Dossier> getDossiers(Date now) {
66  WhereClause wc = new WhereClause();
67  wc.addClause("select distinct dossier from Dossier as dossier");
68  wc.addClause("where dossier.status <> :status");
70  return new DossierPU().getResultList(wc);
71  }
72 
73 }
void addNamedValue(String name, Object value)
static String get(String msg)
Definition: I_.java:41