BrightSide Workbench Full Report + Source Code
PublicationSender.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.publication.util;
19 
20 import java.util.List;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.turro.elephant.context.ElephantContext;
24 import org.turro.i18n.I_;
25 import org.turro.jpa.Dao;
26 import org.turro.publication.db.PublicationPU;
27 import org.turro.publication.entity.Publication;
28 import org.turro.publication.entity.PublicationCategory;
29 import org.turro.scheduler.motor.DefaultTask;
30 
35 public class PublicationSender extends DefaultTask {
36 
37  private long idCat;
38  private String path;
39 
40  @Override
41  public String getName() {
42  return I_.get("Publication sender");
43  }
44 
45  @Override
46  public void run() {
47  try {
48  parseData();
49 
50  Dao dao = new PublicationPU();
51 
52  PublicationCategory pubcat = dao.find(PublicationCategory.class, Long.valueOf(idCat));
53 
54  if(pubcat != null) {
55  List<Publication> pubs = PublicationCategories.getNotSentPublications(pubcat.getId());
56 
57  if(!pubs.isEmpty()) {
58  new PublicationNotification(constructor, path, pubs, pubcat).send();
59 
61  }
62  }
63  } catch(Exception ex) {
64  Logger.getLogger(PublicationSender.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
65  }
66  }
67 
68  @Override
69  public String getDataLabel() {
70  return I_.get("Category ID");
71  }
72 
73  private void parseData() {
74  String data = getData();
75  int p = data.indexOf("/");
76  if(p > -1) {
77  idCat = Long.valueOf(data.substring(0, p));
78  path = data.substring(p);
79  } else {
80  idCat = Long.valueOf(data);
81  path = null;
82  }
83  }
84 
85 }
static String get(String msg)
Definition: I_.java:41
static List< Publication > getNotSentPublications(long categoryID)