BrightSide Workbench Full Report + Source Code
PendingRevisionDashboard.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2016 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 java.util.List;
24 import javax.servlet.ServletException;
25 import org.turro.string.Strings;
26 import org.turro.dossier.db.DossierPU;
27 import org.turro.dossier.entity.Dossier;
28 import org.turro.dossier.entity.Issue;
29 import org.turro.dossier.entity.IssueParticipant;
30 import org.turro.dossier.entity.IssueResolution;
31 import org.turro.dossier.entity.IssueStatus;
32 import org.turro.dossier.entity.IssueType;
33 import org.turro.dossier.issue.IssueWrapper;
34 import org.turro.dossier.kb.PendingRevisionQuery;
35 import org.turro.elephant.context.ElephantContext;
36 import org.turro.elephant.context.IElement;
37 import org.turro.elephant.impl.abstracts.AbstractElement;
38 import org.turro.elephant.impl.context.AttributeItem;
39 import org.turro.elephant.layout.IManageable;
40 import org.turro.elephant.layout.IRenderable;
41 import org.turro.elephant.security.IDefendable;
42 import org.turro.file.util.FileAttach;
43 import org.turro.marker.ElephantMarker;
44 import org.turro.plugin.contacts.ContactList;
45 import org.turro.www.describeit.DescribeItCtrl;
46 import org.turro.www.starit.StarItCtrl;
47 import org.turro.www.voteit.VoteItCtrl;
48 
54 
55  protected String sclass, fullTemplate, summaryTemplate, issuePath;
56  protected boolean allowInterest, allowComments, allowVotes, showDescriptions;
58 
59  @Override
60  public void loadData() throws ServletException, IOException {
61  sclass = getAttributes().getAttributeValue("attrib:sclass", "");
62  allowInterest = getAttributes().getAttributeBooleanValue("attrib:allowInterest", true);
63  allowComments = getAttributes().getAttributeBooleanValue("attrib:allowComments", true);
64  allowVotes = getAttributes().getAttributeBooleanValue("attrib:allowVotes", true);
65  showDescriptions = getAttributes().getAttributeBooleanValue("attrib:showDescriptions", true);
66  fullTemplate = getAttributes().getAttributeValue("attrib:fullTemplate", "");
67  summaryTemplate = getAttributes().getAttributeValue("attrib:summaryTemplate", "");
68  issuePath = getAttributes().getAttributeValue("attrib:issuePath", "");
69 
70  prq = new PendingRevisionQuery();
71 
72  long archive = AttributeItem.getFromParameter(getConstructor(), "archive", "").getLongValue(0L);
73 
74  if(archive > 0) {
75  prq.archive(archive);
76  }
77  }
78 
79  @Override
80  public void startConstruction() throws ServletException, IOException {
81  PrintWriter out = getConstructor().getOut();
82  out.print(getStart());
83  out.print(getStartBody());
84 
85  List<IssueParticipant> list = prq.getResultList();
86 
88  if(list.isEmpty()) {
89  marker.put("divider", false);
90  marker.put("header", true);
91  marker.put("footer", true);
92  marker.put("empty", true);
93  marker.process("issue", getSummaryTemplate());
94  } else {
95  int index = 0;
96  marker.put("empty", false);
97  for(IssueParticipant ip : list) {
98  marker.put("divider", index > 0);
99  marker.put("header", index == 0);
100  marker.put("footer", index == list.size() - 1);
101  prepareValues(marker, ip, 0);
102  marker.put("ip", ip);
103  marker.process("issue", getSummaryTemplate());
104  index++;
105  }
106  }
107 
108  out.print(getEndBody());
109  out.print(getEnd());
110  }
111 
112  @Override
113  public String getStart() {
114  return "<div class='" + sclass + "dossier-web'>";
115  }
116 
117  @Override
118  public String getEnd() {
119  return "</div>";
120  }
121 
122  private void prepareValues(ElephantMarker marker, IssueParticipant ip, int page) {
123 
124  Issue issue = ip.getIssue();
125 
126  marker.put("issue", issue);
127  marker.put("wrapper", new IssueWrapper(issue, prq.getByParticipant()));
128  marker.put("name", issue.getDescription());
129 
130  String link = getItemLink(issue, page);
131  if(link != null) {
132  marker.put("path", link);
133  marker.put("all", getPageLink(page));
134  }
135  marker.put("readall", getItemLink(issue, page));
136  marker.put("issueClass", getIssueClass(issue));
137 
138  if(allowVotes) {
139  Dossier dossier = issue.getDossier();
140  if(dossier.getType().isVotes()) {
141  VoteItCtrl vic = new VoteItCtrl(getConstructor());
142  vic.setEntityPath(DossierPU.getObjectPath(issue));
143  vic.setForbiden(issue.getStatus().isFinished());
144  if(dossier.getType().isSecret()) {
145  vic.setForbid(true);
146  vic.setAllowed((ContactList) dossier.getFullParticipants().getVoteIParticipants());
147  }
148  marker.put("vic", vic);
149  }
150  }
151  if(allowInterest) {
152  StarItCtrl sic = new StarItCtrl(getConstructor());
153  sic.setEntityPath(DossierPU.getObjectPath(issue));
154  marker.put("sic", sic);
155  }
156  if(showDescriptions) {
157  DescribeItCtrl dic = new DescribeItCtrl(getConstructor());
158  dic.setEntityPath(DossierPU.getObjectPath(issue));
159  marker.put("dic", dic);
160  }
161 
162  marker.put("files", new FileAttach(DossierPU.getObjectPath(issue)));
163  }
164 
165  private String getItemLink(Issue issue, int page) {
166  return ElephantContext.getRootWebPath() + KnowledgeBaseDashboard.createLink(issue);
167  }
168 
169  private String getPageLink(int page) {
170  return getContext().getFullPath() + "?page=" + page;
171  }
172 
173  private String getIssueClass(Issue issue) {
174  return"issue" +
175  (issue.getStatus().equals(IssueStatus.STATUS_NEW) ? " new" : "") +
176  (issue.getStatus().equals(IssueStatus.STATUS_STARTED) ? " started" : "") +
177  (issue.getStatus().equals(IssueStatus.STATUS_INCOMPLETE) ? " incomplete" : "") +
178  (issue.getStatus().equals(IssueStatus.STATUS_REOPENED) ? " reopened" : "") +
179  (issue.getStatus().equals(IssueStatus.STATUS_REUNION) ? " reunion" : "") +
180  (issue.getStatus().equals(IssueStatus.STATUS_FROZEN) ? " frozen" : "") +
181  (issue.getStatus().equals(IssueStatus.STATUS_RESOLVED) ? " resolved" : "") +
182  (issue.getStatus().equals(IssueStatus.STATUS_VERIFIED) ? " verified" : "") +
183  (issue.getStatus().equals(IssueStatus.STATUS_CLOSED) ? " closed" : "") +
184 
185  (issue.getType().equals(IssueType.TYPE_DEFECT) ? " defect" : "") +
186  (issue.getType().equals(IssueType.TYPE_ENHANCEMENT) ? " enhancement" : "") +
187  (issue.getType().equals(IssueType.TYPE_FEATURE) ? " feature" : "") +
188  (issue.getType().equals(IssueType.TYPE_NONCONFORMITY) ? " nonconformity" : "") +
189  (issue.getType().equals(IssueType.TYPE_PATCH) ? " patch" : "") +
190  (issue.getType().equals(IssueType.TYPE_PREVENTION) ? " prevention" : "") +
191  (issue.getType().equals(IssueType.TYPE_QUESTION) ? " question" : "") +
192  (issue.getType().equals(IssueType.TYPE_TASK) ? " task" : "") +
193  (issue.getType().equals(IssueType.TYPE_DOCUMENT) ? " document" : "") +
194  (issue.getType().equals(IssueType.TYPE_BESTPRACTICE) ? " bestpractice" : "") +
195  (issue.getType().equals(IssueType.TYPE_PROCESS) ? " process" : "") +
196  (issue.getType().equals(IssueType.TYPE_PROPOSITION) ? " proposition" : "") +
197 
198  (issue.getResolution().equals(IssueResolution.RESOLUTION_DUPLICATED) ? " duplicated" : "") +
199  (issue.getResolution().equals(IssueResolution.RESOLUTION_FIXED) ? " fixed" : "") +
200  (issue.getResolution().equals(IssueResolution.RESOLUTION_INVALID) ? " invalid" : "") +
201  (issue.getResolution().equals(IssueResolution.RESOLUTION_MOVED) ? " moved" : "") +
202  (issue.getResolution().equals(IssueResolution.RESOLUTION_NONE) ? " none" : "") +
203  (issue.getResolution().equals(IssueResolution.RESOLUTION_WONTFIX) ? " wontfix" : "") +
204  (issue.getResolution().equals(IssueResolution.RESOLUTION_WORKSFORME) ? " worksforme" : "");
205  }
206 
207  private String getSummaryTemplate() {
208  return Strings.isBlank(summaryTemplate) ? "prSummary" : summaryTemplate;
209  }
210 
211  private String getFullTemplate() {
212  return Strings.isBlank(fullTemplate) ? "prFull" : fullTemplate;
213  }
214 
215 }
static AttributeItem getFromParameter(IConstructor constructor, String name, String defaultValue)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)