BrightSide Workbench Full Report + Source Code
ProjectGrantCollectionIterator.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2024 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.alliance.client;
20 
21 import java.io.Writer;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Optional;
25 import org.turro.alliance.db.entities.AxProjectGrant;
26 import org.turro.alliance.db.entities.ProcedenceId;
27 import org.turro.collections.CollectionHtmlIterator;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.context.IConstructor;
30 import org.turro.elephant.db.ElephantPU;
31 import org.turro.elephant.impl.repository.Repository;
32 import org.turro.elephant.impl.repository.RepositoryFile;
33 import org.turro.elephant.web.SocialImageMap;
34 import org.turro.elephant.web.SocialNet;
35 import org.turro.entities.EmptyController;
36 import org.turro.entities.Entities;
37 import org.turro.entities.IElephantEntity;
38 import org.turro.file.util.FileAttach;
39 import org.turro.jpa.entity.EntityWebUrls;
40 import org.turro.jpa.search.DaoHtmlSearch;
41 import org.turro.marker.ElephantMarker;
42 import org.turro.marker.MarkerHelper;
43 import org.turro.string.Strings;
44 import org.turro.tags.TagCloud;
45 import org.turro.tags.TagSet;
46 import org.turro.tags.Tags;
47 
52 public class ProjectGrantCollectionIterator extends CollectionHtmlIterator<AxProjectGrant, ProcedenceId> {
53 
54  public ProjectGrantCollectionIterator(IConstructor constructor, Writer writer, boolean mail) {
55  super(new ProjectGrantList(), new ElephantMarker(constructor, mail), writer);
56  init();
57  }
58 
59  public void init() {
61  dhs.setIterator(this);
62  ((ProjectGrantList) collection).doFilter(dhs);
63  }
64 
65  @Override
66  protected AxProjectGrant entity(ProcedenceId value) {
67  return ((ProjectGrantList) collection).getProjectGrant(value);
68  }
69 
70  @Override
71  public String renderSearchEngine() {
73  return dhs.render(constructor);
74  }
75 
76  @Override
77  protected void renderSummary(ElephantMarker marker, AxProjectGrant e, int page) {
78  if(e != null) {
79  marker.put("projectGrant", e);
80  prepareValues(e, page);
81  }
83  }
84 
85  @Override
86  protected void renderItem(ElephantMarker marker, AxProjectGrant e, int page) {
87  marker.put("projectGrant", e);
88  prepareValues(e, page);
90  }
91 
92  @Override
93  protected String title(AxProjectGrant e) {
94  return e.getTitle();
95  }
96 
97  public TagSet getCloudTags() {
98  return TagCloud.getTags(constructor, "axproject-grant");
99  }
100 
101  public TagSet getEntityTags(Object entity) {
102  return Tags.getTags(entity);
103  }
104 
105  private String getItemLink(AxProjectGrant projectGrant, int page) {
106  return constructor.getCurrentContext().getFullPath() + "?item=" + projectGrant.getId();
107  }
108 
109  private String getPageLink(int page) {
110  return constructor.getCurrentContext().getFullPath() + "?page=" + page;
111  }
112 
113  private void prepareValues(final AxProjectGrant projectGrant, int page) {
114  prepareControls(projectGrant, page);
115  }
116 
117  @Override
118  protected Collection<String> metas(AxProjectGrant e) {
119  ArrayList<RepositoryFile> files = new ArrayList<>();
120  String path = getItemLink(e, 0);
121  if(!SocialImageMap.hasImage(path)) {
124  files.addAll(repository.getRepositoryFiles("*_social.png,*_social.jpg"));
125  files.addAll(repository.getRepositoryFiles("*.png,*.jpg"));
126  }
127  SocialNet sn = new SocialNet(path, e.getTitle(), e.getGoal(), files);
128  return sn.getMetas();
129  }
130 
131  @Override
132  protected ProcedenceId parseId(String value) {
133  return ProcedenceId.from(value);
134  }
135 
136 
137  protected String getTemplateRoot() {
138  return "alliance/client/projectgrant";
139  }
140 
141  protected void prepareControls(AxProjectGrant entity, int page) {
142  marker.put("entiter", this);
143  if(!marker.contains("iee")) {
144  IElephantEntity iee = Entities.getController(entity);
145  if(!(iee instanceof EmptyController)) {
146  marker.put("iee", iee);
147  }
148  }
149  marker.put("itemLink", getItemLink(entity));
150  marker.put("allLink", getReadAllLink());
151  marker.put("restrictedLink", getRestrictedLink());
152  }
153 
154  protected String getItemLink(AxProjectGrant project) {
155  return doItemLink(project, project.getProjectGrantId(), true);
156  }
157 
158  protected String getReadAllLink() {
159  String path = Optional.ofNullable(constructor)
160  .map(cons -> cons.getCurrentContext())
161  .map(ctx -> ctx.getFullPath())
162  .filter(p -> !p.endsWith("/user"))
163  .orElse(null);
164  if(Strings.isBlank(path)) {
165  path = ElephantContext.getEntityWebContext("/axproject-grant");
166  }
167  if(Strings.isBlank(path)) {
168  return getRestrictedLink();
169  }
170  return path;
171  }
172 
173  protected String doItemLink(AxProjectGrant entity, ProcedenceId id, boolean obfuscated) {
174  String ewu = EntityWebUrls.getUrlFromEntity(entity);
175  if(ewu != null) {
176  return getReadAllLink() + ewu;
177  } else {
178  if(obfuscated) {
179  return getReadAllLink() + "?" + MarkerHelper.setObfuscatedPars("item=" + id.stringify());
180  } else {
181  return getReadAllLink() + "?item=" + id.stringify();
182  }
183  }
184  }
185 
186  protected String getRestrictedLink() {
187  return "/user/alliance/projectgrants";
188  }
189 
190 }
void renderItem(ElephantMarker marker, AxProjectGrant e, int page)
String doItemLink(AxProjectGrant entity, ProcedenceId id, boolean obfuscated)
void renderSummary(ElephantMarker marker, AxProjectGrant e, int page)
ProjectGrantCollectionIterator(IConstructor constructor, Writer writer, boolean mail)
static ProcedenceId from(String id)
static String getContextVariable(IConstructor constructor)
static String getEntityWebContext(String path)
static String getObjectPath(Object object)
Definition: ElephantPU.java:63
static boolean hasImage(String url)
static IElephantEntity getController(String path)
Definition: Entities.java:78
Repository getPublishableRepository(IConstructor constructor)
Definition: FileAttach.java:47
static String getUrlFromEntity(Object entity)
String render(IConstructor constructor)
void setIterator(IContentIterator iterator)
static DaoHtmlSearch getInstance(IConstructor constructor, String context)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
static String setObfuscatedPars(String parameters)
static TagSet getTags(IConstructor constructor, String root)
Definition: TagCloud.java:36
static TagSet getTags(Object entity)
Definition: Tags.java:351