BrightSide Workbench Full Report + Source Code
PublicationLastActivity.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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.activity;
20 
21 import java.util.Date;
22 import java.util.List;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.entities.Entities;
25 import org.turro.jpa.Dao;
26 import org.turro.publication.db.PublicationPU;
27 import org.turro.publication.entity.Publication;
28 import org.zkoss.lang.Strings;
29 
34 @LastActivity
35 public class PublicationLastActivity implements ILastActivity {
36 
37  @Override
38  public EntityActivitySet getActivities(Date from, String entityPath, String type) {
40  for(Object obj : getPublications(entityPath, from, null)) {
41  Publication publication = (Publication) obj;
43  publication, PublicationPU.getObjectPath(publication), publication.getDate(), "Published");
45  set.add(ela);
46  }
47  return set;
48  }
49 
50  @Override
51  public Object getMainEntity(Object entity) {
52  return null;
53  }
54 
55  public List getPublications(String path, Date from, String select) {
56  WhereClause wc = new WhereClause();
57  wc.addClause("select publication" + check(select) + " from Publication as publication");
58  wc.addClause("where publication.date >= :date");
59  wc.addNamedValue("date", from);
60  return getDao().getResultList(wc);
61  }
62 
63  private String check(String select) {
64  return Strings.isBlank(select) ? "" : select;
65  }
66 
67  /* Dao */
68 
69  private Dao _dao;
70 
71  private Dao getDao() {
72  if(_dao == null) {
73  _dao = new PublicationPU();
74  }
75  return _dao;
76  }
77 
78 }
List getPublications(String path, Date from, String select)
EntityActivitySet getActivities(Date from, String entityPath, String type)
void addNamedValue(String name, Object value)
static IElephantEntity getController(String path)
Definition: Entities.java:78
static String getObjectPath(Object object)