BrightSide Workbench Full Report + Source Code
BrightSide/elephant-dossier/src/main/java/org/turro/dossier/content/ProjectGrantContentIterator.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.dossier.content;
20 
21 import java.io.Writer;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import org.turro.string.Strings;
25 import org.turro.attach.www.AttachCtrl;
26 import org.turro.contacts.db.ContactsPU;
27 import org.turro.dossier.db.DossierPU;
28 import org.turro.dossier.entity.ProjectGrant;
29 import org.turro.dossier.grant.ProjectGrantCriteria;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.elephant.context.IConstructor;
32 import org.turro.elephant.db.WhereClause;
33 import org.turro.elephant.impl.repository.Repository;
34 import org.turro.elephant.impl.repository.RepositoryFile;
35 import org.turro.elephant.web.SocialImageMap;
36 import org.turro.elephant.web.SocialNet;
37 import org.turro.entities.Entities;
38 import org.turro.file.util.FileAttach;
39 import org.turro.jpa.content.EntityDaoContentIterator;
40 import org.turro.jpa.search.DaoHtmlSearch;
41 import org.turro.jpa.search.DaoSearchKey;
42 import org.turro.marker.ElephantMarker;
43 import org.turro.plugin.contacts.IContact;
44 import org.turro.polls.PollsCtrl;
45 import org.turro.tags.TagCloud;
46 import org.turro.www.commentit.CommentItCtrl;
47 import org.turro.www.describeit.DescribeItCtrl;
48 import org.turro.www.starit.StarItCtrl;
49 import org.turro.www.voteit.VoteItCtrl;
50 
55 public class ProjectGrantContentIterator extends EntityDaoContentIterator<ProjectGrant, Long> {
56 
57  private final ProjectGrantCriteria criteria;
58 
59  public ProjectGrantContentIterator(IConstructor constructor, Writer writer, IContact contact, boolean mail, String pubPath) {
60  super(new DossierPU(), constructor, writer, contact, mail, pubPath);
61  this.criteria = new ProjectGrantCriteria();
62  }
63 
65  return criteria;
66  }
67 
68  @Override
70  processSearch();
71  WhereClause wc = createCriteria();
72  wc.addClause("order by (case when g.endDate < now() then 1 else 0 end) asc, g.endDate asc, g.title");
73  return wc;
74  }
75 
76  @Override
78  processSearch();
79  return createCount();
80  }
81 
82  @Override
83  protected void renderSummary(ElephantMarker marker, ProjectGrant e, int page) {
84  if(e != null) {
85  marker.put("projectGrant", e);
86  prepareValues(e, page);
87  }
89  }
90 
91  @Override
92  protected void renderItem(ElephantMarker marker, ProjectGrant e, int page) {
93  marker.put("projectGrant", e);
94  prepareValues(e, page);
96  }
97 
98  @Override
99  protected String entityRoot() {
100  return "project-grant";
101  }
102 
103  @Override
104  protected ProjectGrant entity(Long value) {
105  processSearch();
106  WhereClause wc = createCriteria();
107  wc.addClause("and g.id = :id");
108  wc.addNamedValue("id", value);
110  }
111 
112  private void processSearch() {
113  if(isSearchOption()) {
115  if(dhs != null) {
116  DaoSearchKey dsk = dhs.get("search-value");
117  if(dsk != null) {
118  criteria.setSearchValue(dsk.getValue());
119  }
120  dsk = dhs.get("minimis");
121  if(dsk != null) {
122  String minimis = dsk.getValue();
123  if("minimis".equals(minimis)) {
124  criteria.setMinimis(true);
125  } else if("nominimis".equals(minimis)) {
126  criteria.setNominimis(true);
127  } else {
128  criteria.clearMinimis();
129  }
130  }
131  dsk = dhs.get("grant");
132  if(dsk != null) {
133  String grant = dsk.getValue();
134  if("subvention".equals(grant)) {
135  criteria.setSubvention(true);
136  } else if("loan".equals(grant)) {
137  criteria.setLoan(true);
138  } else if("combination".equals(grant)) {
139  criteria.setCombination(true);
140  } else {
141  criteria.clearGrant();
142  }
143  }
144  dsk = dhs.get("collab");
145  if(dsk != null) {
146  String collab = dsk.getValue();
147  if("collaboration".equals(collab)) {
148  criteria.setCollaboration(true);
149  } else if("individual".equals(collab)) {
150  criteria.setIndividual(true);
151  } else {
152  criteria.clearCollaboration();
153  }
154  }
155  dsk = dhs.get("micro");
156  if(dsk != null) {
157  criteria.setMicro("true".equals(dsk.getValue()));
158  }
159  dsk = dhs.get("small");
160  if(dsk != null) {
161  criteria.setSmall("true".equals(dsk.getValue()));
162  }
163  dsk = dhs.get("medium");
164  if(dsk != null) {
165  criteria.setMedium("true".equals(dsk.getValue()));
166  }
167  dsk = dhs.get("big");
168  if(dsk != null) {
169  criteria.setBig("true".equals(dsk.getValue()));
170  }
171  dsk = dhs.get("hiring");
172  if(dsk != null) {
173  criteria.setHiring("true".equals(dsk.getValue()));
174  }
175  dsk = dhs.get("idi");
176  if(dsk != null) {
177  criteria.setIdi("true".equals(dsk.getValue()));
178  }
179  dsk = dhs.get("investment");
180  if(dsk != null) {
181  criteria.setInvestment("true".equals(dsk.getValue()));
182  }
183  dsk = dhs.get("start-up");
184  if(dsk != null) {
185  criteria.setStartUp("true".equals(dsk.getValue()));
186  }
187  dsk = dhs.get("deadline");
188  if(dsk != null) {
189  String deadline = dsk.getValue();
190  if("active".equals(deadline)) {
191  criteria.setActive(true);
192  } else if("ended".equals(deadline)) {
193  criteria.setEnded(true);
194  } else if("recurrent".equals(deadline)) {
195  criteria.setRecurrent(true);
196  } else {
197  criteria.clearDeadline();
198  }
199  }
200  }
201  }
202  }
203 
204  @Override
205  protected boolean isValid(ProjectGrant e) {
206  return super.isValid(e);
207  }
208 
209  private WhereClause createCriteria() {
210  WhereClause wc = criteria.create();
211  if(TagCloud.hasSelected(constructor, "project-grant")) {
212  wc.addIn("and", "g.id", TagCloud.getIdentifiersAsLong(constructor, "project-grant"));
213  }
214  return wc;
215  }
216 
217  private WhereClause createCount() {
218  WhereClause wc = criteria.createCount();
219  if(TagCloud.hasSelected(constructor, "project-grant")) {
220  wc.addIn("and", "g.id", TagCloud.getIdentifiersAsLong(constructor, "project-grant"));
221  }
222  return wc;
223  }
224 
225  private void prepareValues(final ProjectGrant practicalWork, int page) {
226  prepareControls(practicalWork, page);
227  }
228 
229  @Override
230  protected String title(ProjectGrant e) {
231  if(!Strings.isBlank(e.getName())) {
232  return e.getName();
233  }
234  return null;
235  }
236 
237  @Override
238  protected Collection<String> metas(ProjectGrant e) {
239  ArrayList<RepositoryFile> files = new ArrayList<>();
240  String path = getItemLink(e);
241  if(!SocialImageMap.hasImage(path)) {
244  files.addAll(repository.getRepositoryFiles("*_social.png,*_social.jpg"));
245  files.addAll(repository.getRepositoryFiles("*.png,*.jpg"));
246  }
247  SocialNet sn;
248  sn = new SocialNet(path, e.getName(), e.getDescription(), files);
249  return sn.getMetas();
250  }
251 
252  @Override
253  protected String getTemplateRoot() {
254  return isMail() ? "content/newsletter/sections/projectgrants" : "projectgrant";
255  }
256 
257  @Override
258  protected Object doVotesCtrl(ProjectGrant e) {
261  }
262 
263  @Override
264  protected Object doInterestCtrl(ProjectGrant e) {
267  }
268 
269  @Override
270  protected Object doCommentsCtrl(ProjectGrant e) {
273  }
274 
275  @Override
276  protected Object doAttachmentsCtrl(ProjectGrant e) {
279  }
280 
281  @Override
282  protected Object doFilesCtrl(ProjectGrant e) {
285  }
286 
287  @Override
288  protected Object doDescriptionsCtrl(ProjectGrant e) {
291  }
292 
293  @Override
294  protected Object doPollsCtrl(ProjectGrant e) {
297  }
298 
299  @Override
300  protected String getItemLink(ProjectGrant e) {
301  return doItemLink(e, e.getId(), true);
302  }
303 
304  @Override
305  protected String getReadAllLink() {
306  String path = getContextPath();
307  if(Strings.isBlank(path)) {
308  path = ElephantContext.getEntityWebContext("/projectgrant");
309  }
310  if(Strings.isBlank(path)) {
311  return getRestrictedLink();
312  }
313  return path;
314  }
315 
316  @Override
317  protected String getRestrictedLink() {
318  return "/user/projectgrants";
319  }
320 
321 }
static String getObjectPath(Object object)
Definition: ContactsPU.java:68
ProjectGrantContentIterator(IConstructor constructor, Writer writer, IContact contact, boolean mail, String pubPath)
static String getContextVariable(IConstructor constructor)
static String getEntityWebContext(String path)
void addIn(String operator, String field, List values)
void addNamedValue(String name, Object value)
static boolean hasImage(String url)
static IElephantEntity getController(String path)
Definition: Entities.java:78
Repository getPublishableRepository(IConstructor constructor)
Definition: FileAttach.java:47
Object getSingleResultOrNull(SqlClause sc)
Definition: Dao.java:419
String doItemLink(E entity, ID id, boolean obfuscated)
static DaoHtmlSearch getInstance(IConstructor constructor, String context)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
static boolean hasSelected(IConstructor constructor, String root)
Definition: TagCloud.java:72
static List< Long > getIdentifiersAsLong(IConstructor constructor, String root)
Definition: TagCloud.java:68
Object configureCtrl(Object ctrl, IContact contact)