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