BrightSide Workbench Full Report + Source Code
MyIssuesDashboard.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 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.www;
20 
21 import java.io.IOException;
22 import java.io.PrintWriter;
23 import javax.servlet.ServletException;
24 import org.turro.string.ObjectString;
25 import org.turro.string.Strings;
26 import org.turro.auth.Authentication;
27 import org.turro.collections.KeyValueMap;
28 import org.turro.dossier.db.DossierPU;
29 import org.turro.dossier.entity.Dossier;
30 import org.turro.dossier.entity.Issue;
31 import org.turro.dossier.entity.IssueResolution;
32 import org.turro.dossier.entity.IssueStatus;
33 import org.turro.dossier.entity.IssueType;
34 import org.turro.dossier.issue.IssueWrapper;
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.Application;
40 import org.turro.elephant.context.ElephantContext;
41 import org.turro.elephant.context.IElement;
42 import org.turro.elephant.impl.abstracts.AbstractElement;
43 import org.turro.elephant.layout.IManageable;
44 import org.turro.elephant.layout.IRenderable;
45 import org.turro.elephant.security.IDefendable;
46 import org.turro.entities.Entities;
47 import org.turro.file.util.FileAttach;
48 import org.turro.i18n.I_;
49 import org.turro.jpa.search.DaoHtmlSearch;
50 import org.turro.jpa.search.DaoSearchKey;
51 import org.turro.marker.ElephantMarker;
52 import org.turro.marker.MarkerHelper;
53 import org.turro.plugin.contacts.ContactList;
54 import org.turro.plugin.contacts.IContact;
55 import org.turro.www.describeit.DescribeItCtrl;
56 import org.turro.www.starit.StarItCtrl;
57 import org.turro.www.voteit.VoteItCtrl;
58 
64 
65  protected String sclass, fullTemplate, summaryTemplate, dossierPath;
66  protected int count;
67  protected boolean allowInterest, allowComments, allowVotes, showDescriptions, showSubject, showAttachments, showFiles;
68  protected Long item;
69  protected Issue issue;
70  protected IContact contact;
71 
72  @Override
73  public void loadData() throws ServletException, IOException {
74  sclass = getAttributes().getAttributeValue("attrib:sclass", "");
75  count = getAttributes().getAttributeIntegerValue("attrib:count", 10);
76  allowInterest = getAttributes().getAttributeBooleanValue("attrib:allowInterest", true);
77  allowVotes = getAttributes().getAttributeBooleanValue("attrib:allowVotes", true);
78  showDescriptions = getAttributes().getAttributeBooleanValue("attrib:showDescriptions", true);
79  showFiles = getAttributes().getAttributeBooleanValue("attrib:showFiles", true);
80  showSubject = getAttributes().getAttributeBooleanValue("attrib:showSubject", true);
81  fullTemplate = getAttributes().getAttributeValue("attrib:fullTemplate", "");
82  summaryTemplate = getAttributes().getAttributeValue("attrib:summaryTemplate", "");
83  dossierPath = getAttributes().getAttributeValue("attrib:dossierPath", null);
84 
85  KeyValueMap kvm = MarkerHelper.getObfuscatedParameters();
86  if(kvm != null && !kvm.isEmpty() && kvm.containsKey("item")) {
87  item = kvm.get(Long.class, "item");
88  } else {
89  item = (Long) ObjectString.parseString(getConstructor().getParameter("item"), Long.class, true);
90  }
91 
92  if(item > 0) {
93  issue = new DossierPU().find(Issue.class, item);
94  }
95 
96  if(issue != null) {
98  } else {
99  item = 0L;
100  }
101 
103  }
104 
105  @Override
106  public void startConstruction() throws ServletException, IOException {
107  PrintWriter out = getConstructor().getOut();
108  out.print(getStart());
109  out.print(getStartBody());
110 
112  if(!Strings.isBlank(dossierPath)) {
113  marker.put("dossierPath", ElephantContext.getRootWebPath() + dossierPath);
114  }
115  if(item > 0) {
116  prepareValues(marker, issue, 0);
117  IssueWrapper iw = new IssueWrapper(issue);
118  if(Application.getApplication().isInRole("issue:edit") || iw.isFullParticipant()) {
119  IssueStage stage = getStage(iw);
120  marker.put("stage", I_.byKey(stage.toString()));
121  marker.put("wrapper", iw);
122  marker.put("issue", issue);
123  marker.put("addInfo", AddInformationCtrl.addInformation(iw, getItemLink(issue, 0)));
124  marker.process("issue", getFullTemplate());
125  }
126  } else {
127  /*
128  List<IssueWrapper> iws = null;
129  */
130 
132  String searchValue = null;
133  if(dhs != null) {
134  out.print(dhs.render(getConstructor()));
135  DaoSearchKey dsk = dhs.get("search-value");
136  if(dsk != null) {
137  searchValue = dsk.getValue();
138  }
139  }
141  wq.setSearchValue(Strings.isBlank(searchValue) ? "*" : searchValue);
142  WorkloadSet ws = wq.getResults();
143  IssueStage stage = null;
144  int index = 0;
145  for(WorkloadItem wi : ws) {
146  IssueWrapper iw = wi.getWrapper();
147  marker.put("divider", index > 0);
148  marker.put("header", index == 0);
149  marker.put("footer", index == ws.size() - 1);
150  IssueStage current = WorkloadSet.getStage(wi);
151  if(!(current.equals(stage))) {
152  stage = current;
153  marker.put("newStage", true);
154  } else {
155  marker.put("newStage", false);
156  }
157  prepareValues(marker, iw.getIssue(), 0);
158  marker.put("stage", I_.byKey(current.toString()));
159  marker.put("wrapper", iw);
160  marker.put("issue", iw.getIssue());
161  marker.process("issue", getSummaryTemplate());
162  index++;
163  }
164  /*
165  if(iws == null || iws.isEmpty()) {
166  IssueResults ir = new IssueResults();
167  ir.setByParticipant(contact);
168  ir.setApplication(Application.getApplication());
169  if(!Strings.isBlank(searchValue)) {
170  ir.setIssueValue(searchValue);
171  }
172  iws = ir.getIssueList();
173  } else {
174  iws.addAll(WorksheetUtil.getNotIn(contact, iws));
175  }
176  IssueStage stage = null;
177  for(int i = 0; i < iws.size(); i++) {
178  IssueWrapper iw = iws.get(i);
179  marker.put("divider", i > 0);
180  marker.put("header", i == 0);
181  marker.put("footer", i == iws.size() - 1);
182  IssueStage current = getStage(iw);
183  if(!(current.equals(stage))) {
184  stage = current;
185  marker.put("newStage", true);
186  } else {
187  marker.put("newStage", false);
188  }
189  prepareValues(marker, iw.getIssue(), 0);
190  marker.put("stage", getConstructor().getString(current.toString()));
191  marker.put("wrapper", iw);
192  marker.put("issue", iw.getIssue());
193  marker.process("issue", getSummaryTemplate());
194  }
195  if(iws.isEmpty()) {
196  out.write("<h3>" + I_.get("Empty list") + "</h3>");
197  }
198  */
199  if(ws.isEmpty()) {
200  out.write("<h3>" + I_.get("Empty list") + "</h3>");
201  }
202  }
203 
204  out.print(getEndBody());
205  out.print(getEnd());
206  }
207 
208  @Override
209  public String getStart() {
210  return "<div class='" + sclass + "dossier-web'>";
211  }
212 
213  @Override
214  public String getEnd() {
215  return "</div>";
216  }
217 
218  private void prepareValues(ElephantMarker marker, Issue issue, int page) {
219  marker.put("iee", Entities.getController(issue));
220 
221  marker.put("name", issue.getDescription());
222 
223  String link = getItemLink(issue, page);
224  if(link != null) {
225  marker.put("path", link);
226  marker.put("all", getPageLink(page));
227  }
228  marker.put("readall", getItemLink(issue, page));
229  marker.put("issueClass", getIssueClass(issue));
230 
231  if(allowVotes) {
232  Dossier dossier = issue.getDossier();
233  if(dossier.getType().isVotes()) {
234  VoteItCtrl vic = new VoteItCtrl(getConstructor());
235  vic.setEntityPath(DossierPU.getObjectPath(issue));
236  vic.setForbiden(issue.getStatus().isFinished());
237  if(dossier.getType().isSecret()) {
238  vic.setForbid(true);
239  vic.setAllowed((ContactList) dossier.getFullParticipants().getVoteIParticipants());
240  }
241  marker.put("vic", vic);
242  }
243  }
244  if(allowInterest) {
245  StarItCtrl sic = new StarItCtrl(getConstructor());
246  sic.setEntityPath(DossierPU.getObjectPath(issue));
247  marker.put("sic", sic);
248  }
249  if(showDescriptions) {
250  DescribeItCtrl dic = new DescribeItCtrl(getConstructor());
251  dic.setEntityPath(DossierPU.getObjectPath(issue));
252  marker.put("dic", dic);
253  }
254 
255  if(showFiles) {
256  marker.put("files", new FileAttach(DossierPU.getObjectPath(issue)));
257  }
258  }
259 
260  private String getItemLink(Issue issue, int page) {
261  return getContext().getFullPath() + "?" + MarkerHelper.setObfuscatedPars("item=" + issue.getId() + ";page=" + page);
262  }
263 
264  private String getPageLink(int page) {
265  return getContext().getFullPath() + "?page=" + page;
266  }
267 
268  private String getIssueClass(Issue issue) {
269  return"issue" +
270  (issue.getStatus().equals(IssueStatus.STATUS_NEW) ? " new" : "") +
271  (issue.getStatus().equals(IssueStatus.STATUS_STARTED) ? " started" : "") +
272  (issue.getStatus().equals(IssueStatus.STATUS_INCOMPLETE) ? " incomplete" : "") +
273  (issue.getStatus().equals(IssueStatus.STATUS_REOPENED) ? " reopened" : "") +
274  (issue.getStatus().equals(IssueStatus.STATUS_REUNION) ? " reunion" : "") +
275  (issue.getStatus().equals(IssueStatus.STATUS_FROZEN) ? " frozen" : "") +
276  (issue.getStatus().equals(IssueStatus.STATUS_RESOLVED) ? " resolved" : "") +
277  (issue.getStatus().equals(IssueStatus.STATUS_VERIFIED) ? " verified" : "") +
278  (issue.getStatus().equals(IssueStatus.STATUS_CLOSED) ? " closed" : "") +
279 
280  (issue.getType().equals(IssueType.TYPE_DEFECT) ? " defect" : "") +
281  (issue.getType().equals(IssueType.TYPE_ENHANCEMENT) ? " enhancement" : "") +
282  (issue.getType().equals(IssueType.TYPE_FEATURE) ? " feature" : "") +
283  (issue.getType().equals(IssueType.TYPE_NONCONFORMITY) ? " nonconformity" : "") +
284  (issue.getType().equals(IssueType.TYPE_PATCH) ? " patch" : "") +
285  (issue.getType().equals(IssueType.TYPE_PREVENTION) ? " prevention" : "") +
286  (issue.getType().equals(IssueType.TYPE_QUESTION) ? " question" : "") +
287  (issue.getType().equals(IssueType.TYPE_TASK) ? " task" : "") +
288  (issue.getType().equals(IssueType.TYPE_DOCUMENT) ? " document" : "") +
289  (issue.getType().equals(IssueType.TYPE_BESTPRACTICE) ? " bestpractice" : "") +
290  (issue.getType().equals(IssueType.TYPE_PROCESS) ? " process" : "") +
291  (issue.getType().equals(IssueType.TYPE_PROPOSITION) ? " proposition" : "") +
292 
293  (issue.getResolution().equals(IssueResolution.RESOLUTION_DUPLICATED) ? " duplicated" : "") +
294  (issue.getResolution().equals(IssueResolution.RESOLUTION_FIXED) ? " fixed" : "") +
295  (issue.getResolution().equals(IssueResolution.RESOLUTION_INVALID) ? " invalid" : "") +
296  (issue.getResolution().equals(IssueResolution.RESOLUTION_MOVED) ? " moved" : "") +
297  (issue.getResolution().equals(IssueResolution.RESOLUTION_NONE) ? " none" : "") +
298  (issue.getResolution().equals(IssueResolution.RESOLUTION_WONTFIX) ? " wontfix" : "") +
299  (issue.getResolution().equals(IssueResolution.RESOLUTION_WORKSFORME) ? " worksforme" : "");
300  }
301 
302  private String getSummaryTemplate() {
303  return Strings.isBlank(summaryTemplate) ? "mySummary" : summaryTemplate;
304  }
305 
306  private String getFullTemplate() {
307  return Strings.isBlank(fullTemplate) ? "myFull" : fullTemplate;
308  }
309 
310  private IssueStage getStage(IssueWrapper wissue) {
311 
312  if(wissue.isUnrelated()) {
313  return IssueStage.ISSUE_STAGE_UNRELATED;
314  }
315 
316  if(wissue.hasPassedNow()) {
317  return IssueStage.ISSUE_STAGE_DATE_SURPASSED;
318  }
319 
320  if(!wissue.hasPassedStartDate() || !wissue.canStartBySources()) {
321  return IssueStage.ISSUE_STAGE_TO_COME;
322  }
323 
324  int stage = wissue.getRelevanceOrderByContact();
325 
326  switch(stage) {
327  case 1: return IssueStage.ISSUE_STAGE_TO_DO;
328  case 2: return IssueStage.ISSUE_STAGE_REUNION;
329  case 5: return IssueStage.ISSUE_STAGE_FROZEN;
330  }
331 
332  return IssueStage.ISSUE_STAGE_TO_MONITOR;
333  }
334 
335 }
336 
IssueResolution getResolution()
Definition: Issue.java:226
static String addInformation(String issueId, String link, String template)
static String getContextVariable(IConstructor constructor)
static IElephantEntity getController(String path)
Definition: Entities.java:78
static String byKey(String key)
Definition: I_.java:83
static String get(String msg)
Definition: I_.java:41
String render(IConstructor constructor)
static DaoHtmlSearch getInstance(IConstructor constructor, String context)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
static KeyValueMap getObfuscatedParameters()