BrightSide Workbench Full Report + Source Code
ContactLastActivity.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.string.Strings;
24 import org.turro.contacts.CommentIt;
25 import org.turro.contacts.Convocation;
26 import org.turro.contacts.StarIt;
27 import org.turro.contacts.VoteIt;
28 import org.turro.contacts.db.ContactsPU;
29 import org.turro.elephant.db.WhereClause;
30 import org.turro.entities.IElephantEntity;
31 import org.turro.jpa.Dao;
32 
37 @LastActivity
38 public class ContactLastActivity implements ILastActivity {
39 
40  @Override
41  public EntityActivitySet getActivities(Date from, String entityPath, String type) {
43  for(Object obj : getComments(entityPath, from, null)) {
44  CommentIt comment = (CommentIt) obj;
45  IElephantEntity iee = comment.getOwnerEntity();
47  comment, iee.getPath(), comment.getDateCreation(), "Commented");
49  set.add(ela);
50  }
51  for(Object obj : getStars(entityPath, from, null)) {
52  StarIt star = (StarIt) obj;
53  IElephantEntity iee = star.getOwnerEntity();
55  star, iee.getPath(), star.getDateCreation(), "Stared");
57  set.add(ela);
58  }
59  for(Object obj : getVotes(entityPath, from, null)) {
60  VoteIt vote = (VoteIt) obj;
61  IElephantEntity iee = vote.getOwnerEntity();
63  vote, iee.getPath(), vote.getDateCreation(), "Voted");
65  set.add(ela);
66  }
67  for(Object obj : getConvocations(entityPath, from, null)) {
68  Convocation convocation = (Convocation) obj;
70  convocation, ContactsPU.getObjectPath(convocation), convocation.getCallDate(), "Convoked");
71  set.add(ela);
72  }
73  return set;
74  }
75 
76  @Override
77  public Object getMainEntity(Object entity) {
78  return null;
79  }
80 
81  public List getComments(String path, Date from, String select) {
82  WhereClause wc = new WhereClause();
83  wc.addClause("select comment" + check(select) + " from CommentIt as comment");
84  wc.addClause("where comment.dateCreation >= :date");
85  wc.addNamedValue("date", from);
86  if(!Strings.isBlank(path)) {
87  wc.addClause("and path like :path");
88  wc.addNamedValue("path", path + "%");
89  }
90  return getDao().getResultList(wc);
91  }
92 
93  public List getStars(String path, Date from, String select) {
94  WhereClause wc = new WhereClause();
95  wc.addClause("select star" + check(select) + " from StarIt as star");
96  wc.addClause("where star.dateCreation >= :date");
97  wc.addNamedValue("date", from);
98  if(!Strings.isBlank(path)) {
99  wc.addClause("and path like :path");
100  wc.addNamedValue("path", path + "%");
101  }
102  return getDao().getResultList(wc);
103  }
104 
105  public List getVotes(String path, Date from, String select) {
106  WhereClause wc = new WhereClause();
107  wc.addClause("select vote" + check(select) + " from VoteIt as vote");
108  wc.addClause("where vote.dateCreation >= :date");
109  wc.addNamedValue("date", from);
110  if(!Strings.isBlank(path)) {
111  wc.addClause("and path like :path");
112  wc.addNamedValue("path", path + "%");
113  }
114  return getDao().getResultList(wc);
115  }
116 
117  public List getConvocations(String path, Date from, String select) {
118  WhereClause wc = new WhereClause();
119  wc.addClause("select convocation" + check(select) + " from Convocation as convocation");
120  wc.addClause("where convocation.callDate >= :date");
121  wc.addNamedValue("date", from);
122  if(!Strings.isBlank(path)) {
123  wc.addClause("and entityPath like :path");
124  wc.addNamedValue("path", path + "%");
125  }
126  return getDao().getResultList(wc);
127  }
128 
129  private String check(String select) {
130  return Strings.isBlank(select) ? "" : select;
131  }
132 
133  /* Dao */
134 
135  private Dao _dao;
136 
137  private Dao getDao() {
138  if(_dao == null) {
139  _dao = new ContactsPU();
140  }
141  return _dao;
142  }
143 
144 }
List getConvocations(String path, Date from, String select)
List getStars(String path, Date from, String select)
EntityActivitySet getActivities(Date from, String entityPath, String type)
List getVotes(String path, Date from, String select)
List getComments(String path, Date from, String select)
IElephantEntity getOwnerEntity()
Definition: CommentIt.java:183
IElephantEntity getOwnerEntity()
Definition: StarIt.java:121
IElephantEntity getOwnerEntity()
Definition: VoteIt.java:130
static String getObjectPath(Object object)
Definition: ContactsPU.java:68
void addNamedValue(String name, Object value)