BrightSide Workbench Full Report + Source Code
ActivityContentIterator.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2023 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.content;
20 
21 import java.io.Writer;
22 import java.util.Collection;
23 import java.util.Collections;
24 import org.turro.elephant.context.ElephantContext;
25 import org.turro.elephant.context.IConstructor;
26 import org.turro.elephant.db.ElephantPU;
27 import org.turro.elephant.db.WhereClause;
28 import org.turro.elephant.entities.db.Activity;
29 import org.turro.elephant.entities.db.ActivityPK;
30 import org.turro.jpa.content.EntityDaoContentIterator;
31 import org.turro.marker.ElephantMarker;
32 import org.turro.plugin.contacts.IContact;
33 import org.turro.string.Strings;
34 
39 public class ActivityContentIterator extends EntityDaoContentIterator<Activity, ActivityPK> {
40 
41  public ActivityContentIterator(IConstructor constructor, Writer writer, IContact contact, boolean mail, String pubPath) {
42  super(new ElephantPU(), constructor, writer, contact, mail, pubPath);
43  }
44 
45  @Override
47  WhereClause wc = new WhereClause();
48  wc.addClause("select activity from Activity as activity");
49  addCriteria(wc);
50  wc.addClause("order by activity.activityDate desc");
51  return wc;
52  }
53 
54  @Override
56  WhereClause wc = new WhereClause();
57  wc.addClause("select count(activity) from Activity as activity");
58  addCriteria(wc);
59  return wc;
60  }
61 
62  @Override
63  protected void renderSummary(ElephantMarker marker, Activity e, int page) {
64  if(e != null) {
65  marker.put("activity", e);
66  prepareValues(e, page);
67  }
69  }
70 
71  @Override
72  protected void renderItem(ElephantMarker marker, Activity e, int page) {
73  marker.put("activity", e);
74  prepareValues(e, page);
76  }
77 
78  @Override
79  protected String entityRoot() {
80  return "activity";
81  }
82 
83  @Override
84  protected Activity entity(ActivityPK value) {
85  WhereClause wc = new WhereClause();
86  wc.addClause("select activity from Activity as activity");
87  addCriteria(wc);
88  wc.addClause("and activity.id = :id");
89  wc.addNamedValue("id", value);
90  return (Activity) dao.getSingleResultOrNull(wc);
91  }
92 
93  private void addCriteria(WhereClause wc) {
94  wc.addClause("where exists (");
95  wc.addClause(" select aa from ActivityAssistant aa");
96  wc.addClause(" where activity.entityPath = aa.entityPath");
97  wc.addClause(" and aa.contactId = :idContact");
98  wc.addClause(")");
99  wc.addNamedValue("idContact", getContact().getId());
100  }
101 
102  @Override
103  protected boolean isValid(Activity e) {
104  return !e.getEntity().isEmpty() && super.isValid(e);
105  }
106 
107  private void prepareValues(final Activity challenge, int page) {
108  prepareControls(challenge, page);
109  }
110 
111  @Override
112  protected String title(Activity e) {
113  return null;
114  }
115 
116  @Override
117  protected Collection<String> metas(Activity e) {
118  return Collections.EMPTY_LIST;
119  }
120 
121  @Override
122  protected String getTemplateRoot() {
123  return isMail() ? null : "activity";
124  }
125 
126  @Override
127  protected String getItemLink(Activity e) {
128  return null;
129  }
130 
131  @Override
132  protected String getReadAllLink() {
133  String path = getContextPath();
134  if(Strings.isBlank(path)) {
135  path = ElephantContext.getEntityWebContext("/activity");
136  }
137  if(Strings.isBlank(path)) {
138  return getRestrictedLink();
139  }
140  return path;
141  }
142 
143  @Override
144  protected String getRestrictedLink() {
145  return "/user/lastactivities";
146  }
147 
148  @Override
149  protected Object doVotesCtrl(Activity e) {
150  return null;
151  }
152 
153  @Override
154  protected Object doInterestCtrl(Activity e) {
155  return null;
156  }
157 
158  @Override
159  protected Object doCommentsCtrl(Activity e) {
160  return null;
161  }
162 
163  @Override
164  protected Object doAttachmentsCtrl(Activity e) {
165  return null;
166  }
167 
168  @Override
169  protected Object doFilesCtrl(Activity e) {
170  return null;
171  }
172 
173  @Override
174  protected Object doDescriptionsCtrl(Activity e) {
175  return null;
176  }
177 
178  @Override
179  protected Object doPollsCtrl(Activity e) {
180  return null;
181  }
182 
183 }
ActivityContentIterator(IConstructor constructor, Writer writer, IContact contact, boolean mail, String pubPath)
void renderItem(ElephantMarker marker, Activity e, int page)
void renderSummary(ElephantMarker marker, Activity e, int page)
static String getEntityWebContext(String path)
void addNamedValue(String name, Object value)
Object getSingleResultOrNull(SqlClause sc)
Definition: Dao.java:419
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)