19 package org.turro.dossier.www;
21 import java.io.IOException;
22 import java.io.PrintWriter;
23 import java.io.UnsupportedEncodingException;
24 import java.net.URLEncoder;
25 import java.util.EnumSet;
26 import java.util.List;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30 import javax.servlet.ServletException;
31 import org.turro.string.ObjectString;
32 import org.turro.string.Strings;
33 import org.turro.auth.Authentication;
34 import org.turro.collections.CollectionUtil;
35 import org.turro.collections.KeyValueMap;
36 import org.turro.dossier.db.DossierPU;
37 import org.turro.dossier.entity.Category;
38 import org.turro.dossier.entity.Dossier;
39 import org.turro.dossier.entity.Issue;
40 import org.turro.dossier.entity.IssueResolution;
41 import org.turro.dossier.entity.IssueStatus;
42 import org.turro.dossier.entity.IssueType;
43 import org.turro.dossier.issue.IssueWrapper;
44 import org.turro.dossier.kb.KnowledgeBaseList;
45 import org.turro.dossier.kb.KnowledgeBaseQuery;
46 import org.turro.elephant.context.Application;
47 import org.turro.elephant.context.ElephantContext;
48 import org.turro.elephant.context.IElement;
49 import org.turro.elephant.impl.abstracts.AbstractElement;
50 import org.turro.elephant.impl.context.AttributeItem;
51 import org.turro.elephant.layout.IManageable;
52 import org.turro.elephant.layout.IRenderable;
53 import org.turro.elephant.security.IDefendable;
54 import org.turro.entities.Entities;
55 import org.turro.file.util.FileAttach;
56 import org.turro.marker.ElephantMarker;
57 import org.turro.marker.MarkerHelper;
58 import org.turro.plugin.contacts.ContactList;
59 import org.turro.plugin.contacts.IContact;
60 import org.turro.www.describeit.DescribeItCtrl;
61 import org.turro.www.starit.StarItCtrl;
62 import org.turro.www.voteit.VoteItCtrl;
70 protected String
sclass, fullTemplate, summaryTemplate, issuePath;
74 protected boolean allowInterest, allowComments, allowVotes, showDescriptions, showFiles;
82 public void loadData() throws ServletException, IOException {
85 dossierId =
getAttributes().getAttributeIntegerValue(
"attrib:dossierId", 0);
89 issueStatus =
getAttributes().getAttributeListValue(
"attrib:issueStatus",
"");
92 allowComments =
getAttributes().getAttributeBooleanValue(
"attrib:allowComments",
true);
93 allowVotes =
getAttributes().getAttributeBooleanValue(
"attrib:allowVotes",
true);
94 showDescriptions =
getAttributes().getAttributeBooleanValue(
"attrib:showDescriptions",
true);
95 showFiles =
getAttributes().getAttributeBooleanValue(
"attrib:showFiles",
true);
96 fullTemplate =
getAttributes().getAttributeValue(
"attrib:fullTemplate",
"");
97 summaryTemplate =
getAttributes().getAttributeValue(
"attrib:summaryTemplate",
"");
98 issuePath =
getAttributes().getAttributeValue(
"attrib:issuePath",
"");
111 if(kvm !=
null && !kvm.isEmpty() && kvm.containsKey(
"item")) {
112 item = kvm.get(Long.class,
"item");
155 marker.
put(
"ntypes", EnumSet.complementOf(EnumSet.copyOf(
kbq.
getTypes())));
156 marker.
put(
"nstatus", EnumSet.complementOf(EnumSet.copyOf(
kbq.
getStatus())));
161 prepareValues(marker, wrapper.
getIssue(), 0);
162 marker.
put(
"wrapper", wrapper);
167 marker.
process(
"issue", getFullTemplate());
168 }
else if(
kbl.isEmpty()) {
169 marker.
put(
"divider",
false);
170 marker.
put(
"header",
true);
171 marker.
put(
"footer",
true);
172 marker.
put(
"empty",
true);
173 marker.
process(
"issue", getSummaryTemplate());
176 marker.
put(
"empty",
false);
178 marker.
put(
"divider", index > 0);
179 marker.
put(
"header", index == 0);
180 marker.
put(
"footer", index ==
kbl.size() - 1);
181 prepareValues(marker, wrapper.getIssue(), 0);
182 marker.
put(
"wrapper", wrapper);
183 marker.
put(
"issue", wrapper.getIssue());
184 marker.
process(
"issue", getSummaryTemplate());
195 return "<div class='" +
sclass +
"dossier-web'>";
208 String link = getItemLink(
issue, page);
210 marker.
put(
"path", link);
211 marker.
put(
"all", getPageLink(page));
213 marker.
put(
"readall", getItemLink(
issue, page));
214 marker.
put(
"issueClass", getIssueClass(
issue));
218 if(dossier.getType().isVotes()) {
220 vic.setEntityPath(DossierPU.getObjectPath(
issue));
222 if(dossier.getType().isSecret()) {
224 vic.setAllowed((ContactList) dossier.getFullParticipants().getVoteIParticipants());
226 marker.
put(
"vic", vic);
231 sic.setEntityPath(DossierPU.getObjectPath(
issue));
232 marker.
put(
"sic", sic);
234 if(showDescriptions) {
236 dic.setEntityPath(DossierPU.getObjectPath(
issue));
237 marker.
put(
"dic", dic);
241 marker.
put(
"files",
new FileAttach(DossierPU.getObjectPath(
issue)));
245 private String getItemLink(Issue
issue,
int page) {
249 private String getPageLink(
int page) {
253 private String getIssueClass(Issue
issue) {
255 (
issue.
getStatus().equals(IssueStatus.STATUS_NEW) ?
" new" :
"") +
256 (
issue.
getStatus().equals(IssueStatus.STATUS_STARTED) ?
" started" :
"") +
257 (
issue.
getStatus().equals(IssueStatus.STATUS_INCOMPLETE) ?
" incomplete" :
"") +
258 (
issue.
getStatus().equals(IssueStatus.STATUS_REOPENED) ?
" reopened" :
"") +
259 (
issue.
getStatus().equals(IssueStatus.STATUS_REUNION) ?
" reunion" :
"") +
260 (
issue.
getStatus().equals(IssueStatus.STATUS_FROZEN) ?
" frozen" :
"") +
261 (
issue.
getStatus().equals(IssueStatus.STATUS_RESOLVED) ?
" resolved" :
"") +
262 (
issue.
getStatus().equals(IssueStatus.STATUS_VERIFIED) ?
" verified" :
"") +
263 (
issue.
getStatus().equals(IssueStatus.STATUS_CLOSED) ?
" closed" :
"") +
265 (
issue.
getType().equals(IssueType.TYPE_DEFECT) ?
" defect" :
"") +
266 (
issue.
getType().equals(IssueType.TYPE_ENHANCEMENT) ?
" enhancement" :
"") +
267 (
issue.
getType().equals(IssueType.TYPE_FEATURE) ?
" feature" :
"") +
268 (
issue.
getType().equals(IssueType.TYPE_NONCONFORMITY) ?
" nonconformity" :
"") +
269 (
issue.
getType().equals(IssueType.TYPE_PATCH) ?
" patch" :
"") +
270 (
issue.
getType().equals(IssueType.TYPE_PREVENTION) ?
" prevention" :
"") +
271 (
issue.
getType().equals(IssueType.TYPE_QUESTION) ?
" question" :
"") +
272 (
issue.
getType().equals(IssueType.TYPE_TASK) ?
" task" :
"") +
273 (
issue.
getType().equals(IssueType.TYPE_DOCUMENT) ?
" document" :
"") +
274 (
issue.
getType().equals(IssueType.TYPE_BESTPRACTICE) ?
" bestpractice" :
"") +
275 (
issue.
getType().equals(IssueType.TYPE_PROCESS) ?
" process" :
"") +
276 (
issue.
getType().equals(IssueType.TYPE_PROPOSITION) ?
" proposition" :
"") +
278 (
issue.
getResolution().equals(IssueResolution.RESOLUTION_DUPLICATED) ?
" duplicated" :
"") +
280 (
issue.
getResolution().equals(IssueResolution.RESOLUTION_INVALID) ?
" invalid" :
"") +
283 (
issue.
getResolution().equals(IssueResolution.RESOLUTION_WONTFIX) ?
" wontfix" :
"") +
284 (
issue.
getResolution().equals(IssueResolution.RESOLUTION_WORKSFORME) ?
" worksforme" :
"");
287 private String getSummaryTemplate() {
288 return Strings.isBlank(summaryTemplate) ?
"kbSummary" : summaryTemplate;
291 private String getFullTemplate() {
292 return Strings.isBlank(fullTemplate) ?
"kbFull" : fullTemplate;
295 private boolean canLink(IssueWrapper iw) {
296 Application app = Application.getApplication();
297 boolean show = app.isInRole(
"issue:show"),
298 all = app.isInRole(
"issue:all");
299 return (iw.getIssue().isKnowledgeBase() || (show && (all || iw.isFullParticipant())));
302 public static String
createLink(String searchValue,
boolean onlyTitle,
303 Set<IssueType> type, Set<IssueStatus> status, Set<IssueResolution> resolution,
305 StringBuilder sb =
new StringBuilder();
307 sb.append(
"/user/kbase");
308 if(!Strings.isBlank(searchValue)) {
309 sb.append(sep); sep =
"&";
311 sb.append(
"search-value=").append(URLEncoder.encode(searchValue,
"UTF-8"));
312 }
catch (UnsupportedEncodingException ex) {
317 sb.append(sep); sep =
"&";
318 sb.append(
"only-title=true");
320 if(dossierId !=
null && dossierId > 0) {
321 sb.append(sep); sep =
"&";
322 sb.append(
"dossier-id=" + dossierId);
324 if(type !=
null && !type.isEmpty()) {
325 sb.append(sep); sep =
"&";
327 sb.append(CollectionUtil.from(type).getCSV(t -> t.toString()));
329 if(status !=
null && !status.isEmpty()) {
330 sb.append(sep); sep =
"&";
331 sb.append(
"status=");
332 sb.append(CollectionUtil.from(status).getCSV(t -> t.toString()));
334 if(resolution !=
null && !resolution.isEmpty()) {
335 sb.append(sep); sep =
"&";
336 sb.append(
"resolution=");
337 sb.append(CollectionUtil.from(resolution).getCSV(t -> t.toString()));
339 return sb.toString();
343 StringBuilder sb =
new StringBuilder();
345 sb.append(
"/user/kbase");
347 sb.append(sep); sep =
"&";
350 return sb.toString();
static IContact getIContact()
IssueResolution getResolution()
boolean isFullParticipant()
void setSearchValue(String searchValue)
void setDossier(Dossier dossier)
void setResolutions(Set< IssueResolution > resolutions)
Set< IssueType > getTypes()
void setByParticipant(IContact byParticipant)
void setTypes(Set< IssueType > types)
void setCategory(Category category)
KnowledgeBaseList getResultList()
void setStatus(Set< IssueStatus > status)
void setDossierId(Long dossierId)
void setOnlyTitle(boolean onlyTitle)
Set< IssueStatus > getStatus()
Set< IssueResolution > getResolutions()
void setMaxResults(int maxResults)
List< String > issueTypes
static String createLink(String searchValue, boolean onlyTitle, Set< IssueType > type, Set< IssueStatus > status, Set< IssueResolution > resolution, Long dossierId)
static String createLink(Issue issue)
boolean isInRole(String role)
static Application getApplication()
static String logMsg(String msg)
AttributeSupport getAttributes()
static AttributeItem getFromParameter(IConstructor constructor, String name, String defaultValue)
static IElephantEntity getController(String path)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
static KeyValueMap getObfuscatedParameters()
static String setObfuscatedPars(String parameters)
String getParameter(String param)
void setTitle(String title)
IConstructor getConstructor()