BrightSide Workbench Full Report + Source Code
EntityItemContentIterator.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 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.jpa.content;
20 
21 import java.io.Writer;
22 import java.util.List;
23 import java.util.Optional;
24 import org.turro.collections.CollectionHtmlIterator;
25 import org.turro.elephant.context.IConstructor;
26 import org.turro.entities.EmptyController;
27 import org.turro.entities.Entities;
28 import org.turro.entities.IElephantEntity;
29 import org.turro.marker.ElephantMarker;
30 import org.turro.plugin.contacts.IContact;
31 
36 public abstract class EntityItemContentIterator<E, ID> extends CollectionHtmlIterator<E, ID> {
37 
38  private final String contextPath;
39  private final IContact contact;
40  private final boolean mail;
41  private boolean allowInterest, allowComments, allowVotes,
42  allowDescriptions, allowAttachments, allowFiles, allowPolls;
43 
45  Writer writer, IContact contact, boolean mail, String contextPath) {
46  super(collection, new ElephantMarker(constructor, mail), writer);
47  this.contextPath = Optional.ofNullable(contextPath)
48  .orElse(
49  Optional.ofNullable(constructor)
50  .map(cons -> cons.getCurrentContext())
51  .map(ctx -> ctx.getFullPath())
52  .filter(path -> !path.endsWith("/user"))
53  .orElse(null)
54  );
55  this.contact = contact;
56  this.mail = mail;
57  }
58 
59  public String getContextPath() {
60  return contextPath;
61  }
62 
63  public IContact getContact() {
64  return contact;
65  }
66 
67  public boolean isAllowInterest() {
68  return allowInterest;
69  }
70 
71  public void setAllowInterest(boolean allowInterest) {
72  this.allowInterest = allowInterest;
73  }
74 
75  public boolean isAllowComments() {
76  return allowComments;
77  }
78 
79  public void setAllowComments(boolean allowComments) {
80  this.allowComments = allowComments;
81  }
82 
83  public boolean isAllowVotes() {
84  return allowVotes;
85  }
86 
87  public void setAllowVotes(boolean allowVotes) {
88  this.allowVotes = allowVotes;
89  }
90 
91  public boolean isAllowDescriptions() {
92  return allowDescriptions;
93  }
94 
95  public void setAllowDescriptions(boolean allowDescriptions) {
96  this.allowDescriptions = allowDescriptions;
97  }
98 
99  public boolean isAllowAttachments() {
100  return allowAttachments;
101  }
102 
103  public void setAllowAttachments(boolean allowAttachments) {
104  this.allowAttachments = allowAttachments;
105  }
106 
107  public boolean isAllowFiles() {
108  return allowFiles;
109  }
110 
111  public void setAllowFiles(boolean allowFiles) {
112  this.allowFiles = allowFiles;
113  }
114 
115  public boolean isAllowPolls() {
116  return allowPolls;
117  }
118 
119  public void setAllowPolls(boolean allowPolls) {
120  this.allowPolls = allowPolls;
121  }
122 
123  public boolean isMail() {
124  return mail;
125  }
126 
127  public Object getVotesCtrl(E e) {
128  if(allowVotes) {
129  return doVotesCtrl(e);
130  }
131  return null;
132  }
133 
134  public Object getInterestCtrl(E e) {
135  if(allowInterest) {
136  return doInterestCtrl(e);
137  }
138  return null;
139  }
140 
141  public Object getCommentsCtrl(E e) {
142  if(allowComments) {
143  return doCommentsCtrl(e);
144  }
145  return null;
146  }
147 
148  public Object getAttachmentsCtrl(E e) {
149  if(allowAttachments) {
150  return doAttachmentsCtrl(e);
151  }
152  return null;
153  }
154 
155  public Object getFilesCtrl(E e) {
156  if(allowFiles) {
157  return doFilesCtrl(e);
158  }
159  return null;
160  }
161 
162  public Object getDescriptionsCtrl(E e) {
163  if(allowDescriptions) {
164  return doDescriptionsCtrl(e);
165  }
166  return null;
167  }
168 
169  public Object getPollsCtrl(E e) {
170  if(allowPolls) {
171  return doPollsCtrl(e);
172  }
173  return null;
174  }
175 
176  protected void prepareControls(E entity, int page) {
177  marker.put("entiter", this);
178  if(!marker.contains("iee")) {
179  IElephantEntity iee = Entities.getController(entity);
180  if(!(iee instanceof EmptyController)) {
181  marker.put("iee", iee);
182  }
183  }
184  if(isMail()) {
185  marker.put("itemLink", "{liveref:" + getItemLink(entity) + "}");
186  marker.put("allLink", "{liveref:" + getReadAllLink() + "}");
187  marker.put("restrictedLink", "{liveref:" + getRestrictedLink() + "}");
188  } else {
189  marker.put("itemLink", getItemLink(entity));
190  marker.put("allLink", getReadAllLink());
191  marker.put("restrictedLink", getRestrictedLink());
192  }
193  }
194 
195  protected abstract String getTemplateRoot();
196  protected abstract Object doVotesCtrl(E e);
197  protected abstract Object doInterestCtrl(E e);
198  protected abstract Object doCommentsCtrl(E e);
199  protected abstract Object doAttachmentsCtrl(E e);
200  protected abstract Object doFilesCtrl(E e);
201  protected abstract Object doDescriptionsCtrl(E e);
202  protected abstract Object doPollsCtrl(E e);
203  protected abstract String getItemLink(E e);
204  protected abstract String getReadAllLink();
205  protected abstract String getRestrictedLink();
206 
207 }
208 
static IElephantEntity getController(String path)
Definition: Entities.java:78
EntityItemContentIterator(List collection, IConstructor constructor, Writer writer, IContact contact, boolean mail, String contextPath)
Object put(Object key, Object value)