BrightSide Workbench Full Report + Source Code
WebIssuesNotifier.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2014 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 java.util.logging.Level;
23 import java.util.logging.Logger;
24 import org.turro.collections.parser.ParserException;
25 import org.turro.string.ObjectString;
26 import org.apache.commons.mail.EmailException;
27 import org.turro.action.Contacts;
28 import org.turro.action.queue.QueuePeriod;
29 import org.turro.collections.KeyValueMap;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.elephant.entities.db.QueueOptions;
32 import org.turro.i18n.I_;
33 import org.turro.mail.queue.QueueManager;
34 import org.turro.plugin.contacts.ContactList;
35 import org.turro.plugin.contacts.IContact;
36 import org.turro.scheduler.motor.DefaultTask;
37 
42 public class WebIssuesNotifier extends DefaultTask {
43 
44  @Override
45  public String getName() {
46  return I_.get("Web issue notifier");
47  }
48 
49  @Override
50  public void run() {
51  try {
52  KeyValueMap pars = new KeyValueMap(getData());
53  new WebIssuesNotification(getPlayers(pars.get("pubcat")),
54  (Long) ObjectString.parseNativeString(pars.get("doscat"), Long.class, true),
55  (Long) ObjectString.parseNativeString(pars.get("dossier"), Long.class, true),
56  (Long) ObjectString.parseNativeString(pars.get("days"), Long.class, true),
57  pars.get("tmpl")
59  } catch (ParserException | EmailException ex) {
60  Logger.getLogger(WebIssuesNotifier.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
61  }
62  }
63 
64  @Override
65  public String getDataLabel() {
66  return "pubcat=;doscat=;dossier=;days=;tmpl=;";
67  }
68 
69  private ContactList getPlayers(String category) {
70  QueueManager qm = new QueueManager();
71  Collection<QueueOptions> subs = qm.getSubcribers("/publication/" + category);
72  ContactList list = new ContactList();
73  for(QueueOptions qo : subs) {
74  if(qo.getIdContact() != null && !QueuePeriod.DONT_SEND.equals(qo.getPeriod())) {
75  IContact c = Contacts.getContactById(qo.getIdContact());
76  if(c.isWebUser()) {
77  list.add(c);
78  }
79  }
80  }
81  return list;
82  }
83 
84 }
static IContact getContactById(String id)
Definition: Contacts.java:72
static String get(String msg)
Definition: I_.java:41
Collection< QueueOptions > getSubcribers(String idCategory)