BrightSide Workbench Full Report + Source Code
DocumentationContentIterator.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.documentation.model;
20 
21 import java.io.Writer;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.List;
26 import org.turro.string.Strings;
27 import org.turro.attach.db.AttachPU;
28 import org.turro.attach.entity.EntityDocumentation;
29 import org.turro.attach.entity.EntityDocumentationPK;
30 import org.turro.attach.entity.EntityDocumentationStatus;
31 import org.turro.elephant.context.IConstructor;
32 import org.turro.jpa.content.EntityItemContentIterator;
33 import org.turro.marker.ElephantMarker;
34 import org.turro.plugin.contacts.IContact;
35 import org.turro.sql.SqlClause;
36 
41 public class DocumentationContentIterator extends EntityItemContentIterator<EntityDocumentation, EntityDocumentationPK> {
42 
43  public DocumentationContentIterator(IConstructor constructor, Writer writer, IContact contact, boolean mail, String pubPath) {
44  super(getPending(contact), constructor, writer, contact, mail, pubPath);
45  }
46 
47  @Override
48  protected void renderSummary(ElephantMarker marker, EntityDocumentation e, int page) {
49  marker.put("documentation", e);
50  prepareValues(e, page);
52  }
53 
54  @Override
55  protected void renderItem(ElephantMarker marker, EntityDocumentation e, int page) {
56  marker.put("documentation", e);
57  prepareValues(e, page);
59  }
60 
61  @Override
63  for(EntityDocumentation w : collection) {
65  pk.setContactId(w.getContactId());
66  pk.setDocumentation(w.getDocumentation());
67  pk.setEntityPath(w.getEntityPath());
68  if(pk.equals(value)) {
69  return w;
70  }
71  }
72  return null;
73  }
74 
75  private void prepareValues(EntityDocumentation w, int page) {
76  prepareControls(w, page);
77  }
78 
79  @Override
80  protected String title(EntityDocumentation e) {
81  return "/**/";
82  }
83 
84  @Override
85  protected Collection<String> metas(EntityDocumentation e) {
86  return Collections.EMPTY_LIST;
87  }
88 
89  @Override
90  protected String getTemplateRoot() {
91  return isMail() ? "content/newsletter/sections/attachments" : "attachment";
92  }
93 
94  @Override
95  protected Object doVotesCtrl(EntityDocumentation e) {
96  return null;
97  }
98 
99  @Override
100  protected Object doInterestCtrl(EntityDocumentation e) {
101  return null;
102  }
103 
104  @Override
105  protected Object doCommentsCtrl(EntityDocumentation e) {
106  return null;
107  }
108 
109  @Override
111  return null;
112  }
113 
114  @Override
115  protected Object doFilesCtrl(EntityDocumentation e) {
116  return null;
117  }
118 
119  @Override
121  return null;
122  }
123 
124  @Override
125  protected Object doPollsCtrl(EntityDocumentation e) {
126  return null;
127  }
128 
129  @Override
130  protected String getItemLink(EntityDocumentation e) {
131  return e.getEntity().getEntityUrl();
132  }
133 
134  @Override
135  protected String getReadAllLink() {
136  if(Strings.isBlank(getContextPath())) {
137  return getRestrictedLink();
138  }
139  return getContextPath();
140  }
141 
142  @Override
143  protected String getRestrictedLink() {
144  return "/user/documentation";
145  }
146 
147  private static List<EntityDocumentation> getPending(IContact contact) {
148  String orderBy = "ed.documentation";
149  List<String> contactIds = new ArrayList<>();
150  contactIds.add(contact.getId());
151  contact.getBusinessList().forEach(b -> contactIds.add(b.getId()));
152  List<EntityDocumentation> model = SqlClause.select("ed")
153  .from("EntityDocumentation ed")
154  .where()
155  .group()
156  .and().in("ed.contactId", contactIds)
157  .or().equal("ed.requesterId", contact.getId())
158  .or().member("ed.assistantIds", contact.getId())
159  .endGroup()
160  .and().not().equal("ed.status", EntityDocumentationStatus.VALIDATED)
161  .orderBy(orderBy)
162  .dao(new AttachPU())
163  .resultList(EntityDocumentation.class);
164  model.forEach(ed -> ed.reviewStatus());
165  new AttachPU().saveCollection(model);
166  return model;
167  }
168 
169 }
void renderSummary(ElephantMarker marker, EntityDocumentation e, int page)
void renderItem(ElephantMarker marker, EntityDocumentation e, int page)
DocumentationContentIterator(IConstructor constructor, Writer writer, IContact contact, boolean mail, String pubPath)
void saveCollection(Collection objs)
Definition: Dao.java:144
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
List< IContact > getBusinessList()