BrightSide Workbench Full Report + Source Code
KnowledgeBaseContentIterator.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.dossier.content;
20 
21 import java.io.Writer;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.HashSet;
26 import java.util.List;
27 import org.turro.string.Strings;
28 import org.turro.attach.www.AttachCtrl;
29 import org.turro.dossier.db.DossierPU;
30 import org.turro.dossier.entity.Dossier;
31 import org.turro.dossier.entity.DossierStatus;
32 import org.turro.dossier.entity.Issue;
33 import org.turro.dossier.entity.IssueResolution;
34 import org.turro.dossier.entity.IssueStatus;
35 import org.turro.dossier.entity.IssueType;
36 import org.turro.dossier.issue.IssueWrapper;
37 import org.turro.dossier.kb.KnowledgeBaseQuery;
38 import org.turro.elephant.context.IConstructor;
39 import org.turro.elephant.impl.repository.Repository;
40 import org.turro.elephant.impl.repository.RepositoryFile;
41 import org.turro.elephant.web.SocialImageMap;
42 import org.turro.elephant.web.SocialNet;
43 import org.turro.entities.Entities;
44 import org.turro.file.util.FileAttach;
45 import org.turro.jpa.content.EntityItemContentIterator;
46 import org.turro.marker.ElephantMarker;
47 import org.turro.plugin.contacts.IContact;
48 import org.turro.www.commentit.CommentItCtrl;
49 import org.turro.www.describeit.DescribeItCtrl;
50 import org.turro.www.starit.StarItCtrl;
51 import org.turro.www.voteit.VoteItCtrl;
52 
57 public class KnowledgeBaseContentIterator extends EntityItemContentIterator<IssueWrapper, Long> {
58 
59  private boolean showSubject;
60  private final boolean all;
61 
62  public KnowledgeBaseContentIterator(IConstructor constructor, Writer writer, IContact contact, boolean mail, String pubPath) {
63  super(getKnowledgeBase(contact), constructor, writer, contact, mail, pubPath);
64  this.all = contact.getPermissions().isInRole("issue:all");
65  }
66 
67  public boolean isShowSubject() {
68  return showSubject;
69  }
70 
71  public void setShowSubject(boolean showSubject) {
72  this.showSubject = showSubject;
73  }
74 
75  @Override
76  protected void renderSummary(ElephantMarker marker, IssueWrapper e, int page) {
77  if(e != null) {
78  marker.put("issue", e.getIssue());
79  marker.put("wrapper", e);
80  prepareValues(e, page);
81  }
83  }
84 
85  @Override
86  protected void renderItem(ElephantMarker marker, IssueWrapper e, int page) {
87  marker.put("issue", e.getIssue());
88  marker.put("wrapper", e);
89  prepareValues(e, page);
91  }
92 
93  @Override
94  protected IssueWrapper entity(Long value) {
95  for(IssueWrapper wrapper : collection) {
96  if(wrapper.getIssue().getId().equals(value)) {
97  return wrapper;
98  }
99  }
100  return null;
101  }
102 
103  @Override
104  protected boolean isValid(IssueWrapper e) {
105  if(e != null) {
106  return all || e.getIssue().isKnowledgeBase() || e.isFullParticipant();
107  } else {
108  return super.isValid(e);
109  }
110  }
111 
112  private void prepareValues(IssueWrapper wrapper, int page) {
113  prepareControls(wrapper, page);
114  marker.put("issueClass", getIssueClass(wrapper.getIssue()));
115  Dossier dossier = wrapper.getIssue().getDossier();
116  marker.put("dossierClass", "dossier" +
117  (dossier.getStatus().equals(DossierStatus.DOSSIER_OPENED) ? " openned" : "") +
118  (dossier.getStatus().equals(DossierStatus.DOSSIER_CLOSED) ? " closed" : "") +
119  (dossier.getStatus().equals(DossierStatus.DOSSIER_FROZEN) ? " frozen" : ""));
120  }
121 
122  private String getIssueClass(Issue issue) {
123  return"issue" +
124  (issue.getStatus().equals(IssueStatus.STATUS_NEW) ? " new" : "") +
125  (issue.getStatus().equals(IssueStatus.STATUS_STARTED) ? " started" : "") +
126  (issue.getStatus().equals(IssueStatus.STATUS_INCOMPLETE) ? " incomplete" : "") +
127  (issue.getStatus().equals(IssueStatus.STATUS_REOPENED) ? " reopened" : "") +
128  (issue.getStatus().equals(IssueStatus.STATUS_REUNION) ? " reunion" : "") +
129  (issue.getStatus().equals(IssueStatus.STATUS_FROZEN) ? " frozen" : "") +
130  (issue.getStatus().equals(IssueStatus.STATUS_RESOLVED) ? " resolved" : "") +
131  (issue.getStatus().equals(IssueStatus.STATUS_VERIFIED) ? " verified" : "") +
132  (issue.getStatus().equals(IssueStatus.STATUS_CLOSED) ? " closed" : "") +
133 
134  (issue.getType().equals(IssueType.TYPE_DEFECT) ? " defect" : "") +
135  (issue.getType().equals(IssueType.TYPE_ENHANCEMENT) ? " enhancement" : "") +
136  (issue.getType().equals(IssueType.TYPE_FEATURE) ? " feature" : "") +
137  (issue.getType().equals(IssueType.TYPE_NONCONFORMITY) ? " nonconformity" : "") +
138  (issue.getType().equals(IssueType.TYPE_PATCH) ? " patch" : "") +
139  (issue.getType().equals(IssueType.TYPE_PREVENTION) ? " prevention" : "") +
140  (issue.getType().equals(IssueType.TYPE_QUESTION) ? " question" : "") +
141  (issue.getType().equals(IssueType.TYPE_TASK) ? " task" : "") +
142  (issue.getType().equals(IssueType.TYPE_DOCUMENT) ? " document" : "") +
143  (issue.getType().equals(IssueType.TYPE_BESTPRACTICE) ? " bestpractice" : "") +
144  (issue.getType().equals(IssueType.TYPE_PROCESS) ? " process" : "") +
145  (issue.getType().equals(IssueType.TYPE_PROPOSITION) ? " proposition" : "") +
146 
147  (issue.getResolution().equals(IssueResolution.RESOLUTION_DUPLICATED) ? " duplicated" : "") +
148  (issue.getResolution().equals(IssueResolution.RESOLUTION_FIXED) ? " fixed" : "") +
149  (issue.getResolution().equals(IssueResolution.RESOLUTION_INVALID) ? " invalid" : "") +
150  (issue.getResolution().equals(IssueResolution.RESOLUTION_MOVED) ? " moved" : "") +
151  (issue.getResolution().equals(IssueResolution.RESOLUTION_NONE) ? " none" : "") +
152  (issue.getResolution().equals(IssueResolution.RESOLUTION_WONTFIX) ? " wontfix" : "") +
153  (issue.getResolution().equals(IssueResolution.RESOLUTION_WORKSFORME) ? " worksforme" : "");
154  }
155 
156  @Override
157  protected String title(IssueWrapper e) {
158  if(!Strings.isBlank(e.getIssue().getFullDescription(showSubject))) {
159  return e.getIssue().getFullDescription(showSubject);
160  }
161  return null;
162  }
163 
164  @Override
165  protected Collection<String> metas(IssueWrapper e) {
166  ArrayList<RepositoryFile> files = new ArrayList<>();
167  String path = getItemLink(e);
168  if(!SocialImageMap.hasImage(path)) {
171  files.addAll(repository.getRepositoryFiles("*_social.png,*_social.jpg"));
172  files.addAll(repository.getRepositoryFiles("*.png,*.jpg"));
173  }
174  SocialNet sn = new SocialNet(path, e.getIssue().getDescription(), e.getIssue().getFullDescription(), files);
175  return sn.getMetas();
176  }
177 
178  private static List<IssueWrapper> getKnowledgeBase(IContact contact) {
179  KnowledgeBaseQuery kbq = new KnowledgeBaseQuery(contact);
180  kbq.setSearchValue("*");
181  kbq.setOnlyTitle(true);
182  kbq.setMaxResults(300);
183  kbq.setTypes(new HashSet<>(Arrays.asList(IssueType.values())));
184  kbq.setStatus(new HashSet<>(Arrays.asList(IssueStatus.values())));
185  kbq.setResolutions(new HashSet<>(Arrays.asList(IssueResolution.values())));
186  kbq.setDossierId(null);
187  return kbq.getResultList();
188  }
189 
190  @Override
191  protected String getTemplateRoot() {
192  return isMail() ? "content/newsletter/sections/knowledgeBase" : "issue";
193  }
194 
195  @Override
196  protected Object doVotesCtrl(IssueWrapper e) {
199  }
200 
201  @Override
202  protected Object doInterestCtrl(IssueWrapper e) {
205  }
206 
207  @Override
208  protected Object doCommentsCtrl(IssueWrapper e) {
211  }
212 
213  @Override
214  protected Object doAttachmentsCtrl(IssueWrapper e) {
217  }
218 
219  @Override
220  protected Object doFilesCtrl(IssueWrapper e) {
223  }
224 
225  @Override
226  protected Object doDescriptionsCtrl(IssueWrapper e) {
229  }
230 
231  @Override
232  protected Object doPollsCtrl(IssueWrapper e) {
233  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
234  }
235 
236  @Override
237  protected String getItemLink(IssueWrapper e) {
238  return getReadAllLink() + "?item=" + e.getIssue().getId();
239  }
240 
241  @Override
242  protected String getReadAllLink() {
243  if(Strings.isBlank(getContextPath())) {
244  return getRestrictedLink();
245  }
246  return getContextPath();
247  }
248 
249  @Override
250  protected String getRestrictedLink() {
251  return "/user/kbase";
252  }
253 
254 }
void renderItem(ElephantMarker marker, IssueWrapper e, int page)
KnowledgeBaseContentIterator(IConstructor constructor, Writer writer, IContact contact, boolean mail, String pubPath)
void renderSummary(ElephantMarker marker, IssueWrapper e, int page)
static String getObjectPath(Object object)
Definition: DossierPU.java:66
void setResolutions(Set< IssueResolution > resolutions)
void setStatus(Set< IssueStatus > status)
static boolean hasImage(String url)
static IElephantEntity getController(String path)
Definition: Entities.java:78
Repository getPublishableRepository(IConstructor constructor)
Definition: FileAttach.java:47
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
Object configureCtrl(Object ctrl, IContact contact)