19 package org.turro.dossier.www;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.List;
24 import org.turro.string.ObjectString;
25 import org.turro.string.Strings;
26 import org.turro.action.LinkType;
27 import org.turro.attach.www.AttachCtrl;
28 import org.turro.auth.Authentication;
29 import org.turro.dossier.db.DossierPU;
30 import org.turro.dossier.dossier.DossierWrapper;
31 import org.turro.dossier.entity.Category;
32 import org.turro.dossier.entity.Dossier;
33 import org.turro.dossier.entity.DossierStatus;
34 import org.turro.dossier.entity.Issue;
35 import org.turro.dossier.entity.IssueResolution;
36 import org.turro.dossier.entity.IssueStatus;
37 import org.turro.dossier.entity.IssueType;
38 import org.turro.dossier.issue.IssueWrapper;
39 import org.turro.elephant.context.Application;
40 import org.turro.elephant.context.ElephantContext;
41 import org.turro.elephant.context.IConstructor;
42 import org.turro.elephant.db.WhereClause;
43 import org.turro.elephant.impl.repository.Repository;
44 import org.turro.elephant.impl.repository.RepositoryFile;
45 import org.turro.elephant.web.SocialImageMap;
46 import org.turro.elephant.web.SocialNet;
47 import org.turro.entities.Entities;
48 import org.turro.file.util.FileAttach;
49 import org.turro.jpa.iterator.DaoHtmlIterator;
50 import org.turro.jpa.search.DaoHtmlSearch;
51 import org.turro.jpa.search.DaoSearchKey;
52 import org.turro.mail.recipients.MailContact;
53 import org.turro.marker.ElephantMarker;
54 import org.turro.marker.MarkerHelper;
55 import org.turro.plugin.contacts.ContactList;
56 import org.turro.plugin.contacts.IContact;
57 import org.turro.www.commentit.CommentItCtrl;
58 import org.turro.www.describeit.DescribeItCtrl;
59 import org.turro.www.starit.StarItCtrl;
60 import org.turro.www.voteit.VoteItCtrl;
68 private String pubPath, actualParameters, uniqueId;
69 private long categoryId, dossierId, lastDosierId = -1, lastCategoryId = -1;
70 private List<String> issueTypes, issueStatus, dossierStatus;
71 private boolean showSubject;
72 private boolean all, onlyAssists;
81 this.pubPath = pubPath;
82 this.uniqueId = uniqueId;
87 this.categoryId = categoryId;
91 this.dossierId = dossierId;
95 this.dossierStatus = dossierStatus;
99 this.issueTypes = issueTypes;
103 this.issueStatus = issueStatus;
111 this.showSubject = showSubject;
119 this.orderBy = orderBy;
127 this.onlyAssists = onlyAssists;
133 wc.
addClause(
"select distinct i from Issue as i");
134 wc.
addClause(
"join i.participants as p");
143 wc.
addClause(
"select count(distinct i) from Issue as i");
144 wc.
addClause(
"join i.participants as p");
150 return Strings.isBlank(actualParameters) ?
"?a=b" : actualParameters;
161 prepareValues(e, page,
false);
165 actualParameters = getPageLink(page);
177 "jQuery('title').html('" + dossier.
getFullDescription(showSubject).replace(
"'",
"\\'") +
"');"
180 prepareValues(dossier, page,
false);
191 prepareValues(e, page,
false);
195 actualParameters = getPageLink(page);
206 wc.
addClause(
"select distinct i from Issue as i");
207 wc.
addClause(
"join i.participants as p");
215 wc.
addClause(
"where i.publishable = TRUE");
221 String searchValue = dsk.
getValue();
222 if(!Strings.isBlank(searchValue)) {
223 wc.
addClause(
"and i.description like :search01");
230 wc.
addClause(
"and i.dossier.category.id in (" + getCategories(categoryId) +
")");
231 }
else if(dossierId > 0) {
232 wc.
addClause(
"and i.dossier.id = " + dossierId);
234 if(dossierStatus !=
null && dossierStatus.size() > 0) {
237 for(String s : dossierStatus) {
238 DossierStatus ds = DossierStatus.valueOf(s);
241 wc.
addClause(sep +
"i.dossier.status = :" + par);
248 if(issueStatus !=
null && issueStatus.size() > 0) {
251 for(String s : issueStatus) {
252 IssueStatus is = IssueStatus.valueOf(s);
255 wc.
addClause(sep +
"i.status = :" + par);
262 if(issueTypes !=
null && issueTypes.size() > 0) {
265 for(String s : issueTypes) {
266 IssueType it = IssueType.valueOf(s);
281 return participates(e);
283 return super.isValid(e);
287 private boolean participates(
Issue e) {
291 return all ||
new IssueWrapper(e).isFullParticipant();
295 private String getCategories(
long categoryId) {
296 String result =
null;
297 Category category =
dao.find(Category.class, Long.valueOf(categoryId));
298 return addCategory(category, result);
301 private String addCategory(Category category, String result) {
302 if(category !=
null) {
303 result = (String) (((result ==
null) ?
"" : result +
",") + category.getId());
304 for(Category c : category.getChildren()) {
305 result = addCategory(c, result);
311 private void prepareValues(Issue issue,
int page,
boolean asMail) {
312 marker.
put(
"wrapper",
new IssueWrapper(issue));
313 if(asMail && pubPath !=
null) {
314 marker.
put(
"name", MailContact.createLink(issue.getDescription(), getItemLink(issue, page),
false));
316 marker.
put(
"name", issue.getDescription());
318 String link = getItemLink(issue, page);
323 marker.
put(
"issueClass", getIssueClass(issue));
324 if(!Strings.isBlank(pubPath)) {
325 marker.
put(
"readall", getItemLink(issue, page));
327 Dossier dossier = issue.getDossier();
329 (dossier.getStatus().equals(DossierStatus.DOSSIER_OPENED) ?
" openned" :
"") +
330 (dossier.getStatus().equals(DossierStatus.DOSSIER_CLOSED) ?
" closed" :
"") +
331 (dossier.getStatus().equals(DossierStatus.DOSSIER_FROZEN) ?
" frozen" :
""));
334 if(dossier.getType().isVotes()) {
336 vic.setEntityPath(DossierPU.getObjectPath(issue));
337 vic.setForbiden(issue.getStatus().isFinished());
338 if(dossier.getType().isSecret()) {
340 vic.setAllowed((ContactList) dossier.getFullParticipants().getVoteIParticipants());
347 sic.setEntityPath(DossierPU.getObjectPath(issue));
351 CommentItCtrl cic =
new CommentItCtrl(
constructor);
352 cic.setEntityPath(DossierPU.getObjectPath(issue));
357 ac.setEntityPath(DossierPU.getObjectPath(issue));
358 ac.setPublicOnly(
true);
359 if(issue.getFullParticipants().canShowAllAttachments(Authentication.getIContact())) {
360 ac.setPublicOnly(
false);
365 DescribeItCtrl dic =
new DescribeItCtrl(
constructor);
366 dic.setEntityPath(DossierPU.getObjectPath(issue));
369 marker.
put(
"files",
new FileAttach(DossierPU.getObjectPath(issue)));
371 IContact contact = Authentication.getIContact();
372 if(contact.isWebapp()) {
373 marker.
put(
"linkWebapp", Entities.getController(issue).getAppUrl());
375 if(issue.getFullParticipants().isParticipant(contact)) {
376 marker.
put(
"linkWebint", Entities.getController(issue).getEntityUrl(LinkType.WEB_INTERNAL,
null));
388 private void prepareValues(Dossier dossier,
int page,
boolean asMail) {
389 marker.
put(
"wrapper",
new DossierWrapper(dossier));
391 if(dossier.getType().isVotes()) {
393 vic.setEntityPath(DossierPU.getObjectPath(dossier));
394 vic.setForbiden(!dossier.getStatus().isOpen());
395 if(dossier.getType().isSecret()) {
397 vic.setAllowed((ContactList) dossier.getFullParticipants().getVoteIParticipants());
404 sic.setEntityPath(DossierPU.getObjectPath(dossier));
408 CommentItCtrl cic =
new CommentItCtrl(
constructor);
409 cic.setEntityPath(DossierPU.getObjectPath(dossier));
414 ac.setEntityPath(DossierPU.getObjectPath(dossier));
415 if(
isRestricted() &&
new DossierWrapper(dossier).getCanShowAllAttachments()) {
416 ac.setPublicOnly(
false);
418 ac.setPublicOnly(
true);
423 DescribeItCtrl dic =
new DescribeItCtrl(
constructor);
424 dic.setEntityPath(DossierPU.getObjectPath(dossier));
427 marker.
put(
"files",
new FileAttach(DossierPU.getObjectPath(dossier)));
430 private String getItemLink(Issue issue,
int page) {
431 if(pubPath ==
null) {
432 String link = issue.getIssueURL();
436 return ElephantContext.getRootWebPath() + link;
439 return pubPath +
"?" + MarkerHelper.setObfuscatedPars(
"item=" + issue.getId() +
";page=" + page);
443 private String getPageLink(
int page) {
444 return pubPath +
"?page=" + page;
447 private String getIssueClass(Issue issue) {
449 (issue.getStatus().equals(IssueStatus.STATUS_NEW) ?
" new" :
"") +
450 (issue.getStatus().equals(IssueStatus.STATUS_STARTED) ?
" started" :
"") +
451 (issue.getStatus().equals(IssueStatus.STATUS_INCOMPLETE) ?
" incomplete" :
"") +
452 (issue.getStatus().equals(IssueStatus.STATUS_REOPENED) ?
" reopened" :
"") +
453 (issue.getStatus().equals(IssueStatus.STATUS_REUNION) ?
" reunion" :
"") +
454 (issue.getStatus().equals(IssueStatus.STATUS_FROZEN) ?
" frozen" :
"") +
455 (issue.getStatus().equals(IssueStatus.STATUS_RESOLVED) ?
" resolved" :
"") +
456 (issue.getStatus().equals(IssueStatus.STATUS_VERIFIED) ?
" verified" :
"") +
457 (issue.getStatus().equals(IssueStatus.STATUS_CLOSED) ?
" closed" :
"") +
459 (issue.getType().equals(IssueType.TYPE_DEFECT) ?
" defect" :
"") +
460 (issue.getType().equals(IssueType.TYPE_ENHANCEMENT) ?
" enhancement" :
"") +
461 (issue.getType().equals(IssueType.TYPE_FEATURE) ?
" feature" :
"") +
462 (issue.getType().equals(IssueType.TYPE_NONCONFORMITY) ?
" nonconformity" :
"") +
463 (issue.getType().equals(IssueType.TYPE_PATCH) ?
" patch" :
"") +
464 (issue.getType().equals(IssueType.TYPE_PREVENTION) ?
" prevention" :
"") +
465 (issue.getType().equals(IssueType.TYPE_QUESTION) ?
" question" :
"") +
466 (issue.getType().equals(IssueType.TYPE_TASK) ?
" task" :
"") +
467 (issue.getType().equals(IssueType.TYPE_DOCUMENT) ?
" document" :
"") +
468 (issue.getType().equals(IssueType.TYPE_BESTPRACTICE) ?
" bestpractice" :
"") +
469 (issue.getType().equals(IssueType.TYPE_PROCESS) ?
" process" :
"") +
470 (issue.getType().equals(IssueType.TYPE_PROPOSITION) ?
" proposition" :
"") +
472 (issue.getResolution().equals(IssueResolution.RESOLUTION_DUPLICATED) ?
" duplicated" :
"") +
473 (issue.getResolution().equals(IssueResolution.RESOLUTION_FIXED) ?
" fixed" :
"") +
474 (issue.getResolution().equals(IssueResolution.RESOLUTION_INVALID) ?
" invalid" :
"") +
475 (issue.getResolution().equals(IssueResolution.RESOLUTION_MOVED) ?
" moved" :
"") +
476 (issue.getResolution().equals(IssueResolution.RESOLUTION_NONE) ?
" none" :
"") +
477 (issue.getResolution().equals(IssueResolution.RESOLUTION_WONTFIX) ?
" wontfix" :
"") +
478 (issue.getResolution().equals(IssueResolution.RESOLUTION_WORKSFORME) ?
" worksforme" :
"");
491 ArrayList<RepositoryFile> files =
new ArrayList<>();
492 String path = getItemLink(e, 0);
static String getObjectPath(Object object)
String getFullDescription()
String getFullDescription()
IssueIterator(IConstructor constructor, String pubPath, String uniqueId)
WhereClause getWhereClause()
void setShowSubject(boolean showSubject)
IssueIterator(IConstructor constructor, boolean mail, String pubPath, String uniqueId)
void setIssueStatus(List< String > issueStatus)
String getActualParameters()
void setOnlyAssists(boolean onlyAssists)
void setDossierStatus(List< String > dossierStatus)
void renderSummary(ElephantMarker marker, Issue e, int page)
void setOrderBy(IssueOrdering orderBy)
IssueOrdering getOrderBy()
void setCategoryId(long categoryId)
void setDossierId(long dossierId)
WhereClause getCountClause()
Collection< String > metas(Issue e)
void renderItem(ElephantMarker marker, Issue e, int page)
void setIssueTypes(List< String > issueTypes)
boolean isInRole(String role)
static Application getApplication()
static String getContextVariable(IConstructor constructor)
void addClause(String clause)
void addNamedValue(String name, Object value)
Set< RepositoryFile > getRepositoryFiles(String pattern)
static boolean hasImage(String url)
List< String > getMetas()
Repository getPublishableRepository(IConstructor constructor)
Object getSingleResultOrNull(SqlClause sc)
boolean isAllowAttachments()
String getSummaryTemplate()
boolean isAllowInterest()
boolean isAllowDescriptions()
boolean isAllowComments()
static DaoHtmlSearch getInstance(IConstructor constructor, String context)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
ORDER_BY_CATEGORY_DOSSIER_ISSUE
void addOnLoadedJavaScript(String script)
String getParameter(String param)