BrightSide Workbench Full Report + Source Code
PublicationSenderTask.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.publication.util;
20 
21 import java.util.List;
22 import org.turro.i18n.I_;
23 import org.turro.jpa.Dao;
24 import org.turro.log.WebLoggers;
25 import org.turro.publication.db.PublicationPU;
26 import org.turro.publication.entity.Publication;
27 import org.turro.publication.entity.PublicationCategory;
28 import org.turro.scheduler.task.AbstractTask;
29 
34 public class PublicationSenderTask extends AbstractTask {
35 
36  private long idCat;
37  private String path;
38 
39  @Override
40  public void execute() {
41  try {
42  parseData();
43 
44  Dao dao = new PublicationPU();
45 
46  PublicationCategory pubcat = dao.find(PublicationCategory.class, Long.valueOf(idCat));
47 
48  if(pubcat != null) {
49  List<Publication> pubs = PublicationCategories.getNotSentPublications(pubcat.getId());
50 
51  if(!pubs.isEmpty()) {
52  new PublicationNotification(getConstructor(), path, pubs, pubcat).send();
53 
55  }
56  }
57  } catch(Exception ex) {
58  WebLoggers.severe(this).exception(ex).log();
59  }
60  }
61 
62  @Override
63  public boolean isSystem() {
64  return false;
65  }
66 
67  @Override
68  public String getName() {
69  return I_.get("Publication sender");
70  }
71 
72  @Override
73  public String getDataLabel() {
74  return I_.get("Category ID");
75  }
76 
77  private void parseData() {
78  String data = getSettings().getData();
79  int p = data.indexOf("/");
80  if(p > -1) {
81  idCat = Long.valueOf(data.substring(0, p));
82  path = data.substring(p);
83  } else {
84  idCat = Long.valueOf(data);
85  path = null;
86  }
87  }
88 
89 }
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
static List< Publication > getNotSentPublications(long categoryID)