BrightSide Workbench Full Report + Source Code
WebIssuesNotifierTask.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.Collection;
22 import org.apache.commons.mail.EmailException;
23 import org.turro.action.Contacts;
24 import org.turro.action.queue.QueuePeriod;
25 import org.turro.collections.KeyValueMap;
26 import org.turro.collections.parser.ParserException;
27 import org.turro.elephant.entities.db.QueueOptions;
28 import org.turro.i18n.I_;
29 import org.turro.log.WebLoggers;
30 import org.turro.mail.queue.QueueManager;
31 import org.turro.plugin.contacts.ContactList;
32 import org.turro.plugin.contacts.IContact;
33 import org.turro.scheduler.task.AbstractTask;
34 import org.turro.string.ObjectString;
35 
40 public class WebIssuesNotifierTask extends AbstractTask {
41 
42  @Override
43  public void execute() {
44  try {
45  KeyValueMap pars = new KeyValueMap(getSettings().getData());
46  new WebIssuesNotification(getPlayers(pars.get("pubcat")),
47  (Long) ObjectString.parseNativeString(pars.get("doscat"), Long.class, true),
48  (Long) ObjectString.parseNativeString(pars.get("dossier"), Long.class, true),
49  (Long) ObjectString.parseNativeString(pars.get("days"), Long.class, true),
50  pars.get("tmpl")
52  } catch (ParserException | EmailException ex) {
53  WebLoggers.severe(this).exception(ex).log();
54  }
55  }
56 
57  @Override
58  public boolean isSystem() {
59  return false;
60  }
61 
62  @Override
63  public String getName() {
64  return I_.get("Web issue notifier");
65  }
66 
67  @Override
68  public String getDataLabel() {
69  return "pubcat=;doscat=;dossier=;days=;tmpl=;";
70  }
71 
72  private ContactList getPlayers(String category) {
73  QueueManager qm = new QueueManager();
74  Collection<QueueOptions> subs = qm.getSubcribers("/publication/" + category);
75  ContactList list = new ContactList();
76  for(QueueOptions qo : subs) {
77  if(qo.getIdContact() != null && !QueuePeriod.DONT_SEND.equals(qo.getPeriod())) {
78  IContact c = Contacts.getContactById(qo.getIdContact());
79  if(c.isWebUser()) {
80  list.add(c);
81  }
82  }
83  }
84  return list;
85  }
86 
87 }
static IContact getContactById(String id)
Definition: Contacts.java:72
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
Collection< QueueOptions > getSubcribers(String idCategory)