BrightSide Workbench Full Report + Source Code
DossierIterator.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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.util.ArrayList;
22 import java.util.Collection;
23 import java.util.EnumSet;
24 import java.util.List;
25 import java.util.Set;
26 import org.turro.string.ObjectString;
27 import org.turro.string.Strings;
28 import org.turro.action.IEntityCtrl;
29 import org.turro.action.Plugins;
30 import org.turro.attach.www.AttachCtrl;
31 import org.turro.auth.Authentication;
32 import org.turro.charts.Data;
33 import org.turro.collections.ItemOf;
34 import org.turro.collections.SetOf;
35 import org.turro.dossier.command.DossierAction;
36 import org.turro.dossier.db.DossierPU;
37 import org.turro.dossier.dossier.DossierWrapper;
38 import org.turro.dossier.dossier.ProjectContext;
39 import org.turro.dossier.dw.DWIssueModel;
40 import org.turro.dossier.dw.DWWebChart;
41 import org.turro.dossier.entity.Category;
42 import org.turro.dossier.entity.Dossier;
43 import org.turro.dossier.entity.DossierStatus;
44 import org.turro.dossier.entity.DossierType;
45 import org.turro.dossier.entity.Issue;
46 import org.turro.dossier.entity.IssueResolution;
47 import org.turro.dossier.entity.IssueStatus;
48 import org.turro.dossier.entity.IssueType;
49 import org.turro.dossier.entity.ParticipantRole;
50 import org.turro.dossier.issue.IssueWrapper;
51 import org.turro.dossier.search.CategoryResults;
52 import org.turro.elephant.context.Application;
53 import org.turro.elephant.context.ElephantContext;
54 import org.turro.elephant.context.IConstructor;
55 import org.turro.elephant.db.WhereClause;
56 import org.turro.elephant.impl.repository.Repository;
57 import org.turro.elephant.impl.repository.RepositoryFile;
58 import org.turro.elephant.web.SocialImageMap;
59 import org.turro.elephant.web.SocialNet;
60 import org.turro.entities.Entities;
61 import org.turro.file.util.FileAttach;
62 import org.turro.i18n.I_;
63 import org.turro.indicator.Statistics;
64 import org.turro.jpa.entity.EntityWebUrls;
65 import org.turro.jpa.iterator.DaoHtmlIterator;
66 import org.turro.jpa.search.DaoHtmlSearch;
67 import org.turro.jpa.search.DaoSearchKey;
68 import org.turro.mail.recipients.MailContact;
69 import org.turro.marker.ElephantMarker;
70 import org.turro.marker.MarkerHelper;
71 import org.turro.math.Numbers;
72 import org.turro.participation.ParticipationReason;
73 import org.turro.phase.PhaseDefinitions;
74 import org.turro.plugin.contacts.ContactList;
75 import org.turro.plugin.contacts.IContact;
76 import org.turro.polls.PollsCtrl;
77 import org.turro.tags.TagCloud;
78 import org.turro.util.Arrays;
79 import org.turro.visual.DossierVisualElements;
80 import org.turro.visual.VisualElements;
81 import org.turro.www.commentit.CommentItCtrl;
82 import org.turro.www.describeit.DescribeItCtrl;
83 import org.turro.www.starit.StarItCtrl;
84 import org.turro.www.voteit.VoteItCtrl;
85 
90 public class DossierIterator extends DaoHtmlIterator<Dossier, Long> {
91 
92  private final String pubPath, uniqueId;
93  private String actualParameters, allowedCategories, issuePath, pendingWorths;
94  private long categoryId, dossierId, lastCategoryId = -1;
95  private List<String> dossierTypes, dossierStatus, projectPhases;
96  private boolean showSubject;
97  private boolean all, direct;
98  private Collection<IContact> related;
99  private PhaseHtmlFilter phaseFilter;
100 
101  public DossierIterator(IConstructor constructor, String pubPath, String uniqueId) {
102  this(constructor, false, pubPath, uniqueId);
103  }
104 
105  public DossierIterator(IConstructor constructor, boolean mail, String pubPath, String uniqueId) {
106  super(new DossierPU(), new ElephantMarker(constructor, mail));
107  this.pubPath = pubPath;
108  this.uniqueId = uniqueId;
109  this.all = Application.getApplication().isInRole("dossier:all");
110  }
111 
112  public void setCategoryId(long categoryId) {
113  this.categoryId = categoryId;
114  }
115 
116  public void setDossierId(long dossierId) {
117  this.dossierId = dossierId;
118  }
119 
120  void setDossierTypes(List<String> dossierTypes) {
121  this.dossierTypes = dossierTypes;
122  }
123 
124  public void setDossierStatus(List<String> dossierStatus) {
125  this.dossierStatus = dossierStatus;
126  }
127 
128  public List<String> getProjectPhases() {
129  return projectPhases;
130  }
131 
132  public void setProjectPhases(List<String> projectPhases) {
133  this.projectPhases = projectPhases;
134  }
135 
136  public boolean isShowSubject() {
137  return showSubject;
138  }
139 
140  public void setShowSubject(boolean showSubject) {
141  this.showSubject = showSubject;
142  }
143 
144  public void setAllowedCategories(String allowedCategories) {
145  this.allowedCategories = allowedCategories;
146  }
147 
148  public boolean isDirect() {
149  return direct;
150  }
151 
152  public void setDirect(boolean direct) {
153  this.direct = direct;
154  }
155 
156  public void setRelated(Collection<IContact> related) {
157  this.related = related;
158  }
159 
160  public String getPendingWorths() {
161  return pendingWorths;
162  }
163 
164  public void setPendingWorths(String pendingWorths) {
165  this.pendingWorths = pendingWorths;
166  }
167 
168  public String getIssuePath() {
169  return issuePath;
170  }
171 
172  public void setIssuePath(String issuePath) {
173  this.issuePath = issuePath;
174  }
175 
177  return phaseFilter;
178  }
179 
180  public void setPhaseFilter(PhaseHtmlFilter phaseFilter) {
181  this.phaseFilter = phaseFilter;
182  }
183 
184  @Override
186  WhereClause wc = new WhereClause();
187  wc.addClause("select distinct dossier from Dossier as dossier");
188  wc.addClause("left outer join dossier.participants participant");
189  wc.addClause("left outer join dossier.project project");
190  return Statistics.load(constructor, "DossierRanking", "DossierContactMatching", wc)
191  .allowMatching(isAllowMatching())
192  .allowRanking(isAllowRanking())
193  .doMatching(isDoMatching())
194  .setContact(Authentication.getIContact())
195  .setEntityFields("dossier", "id")
196  .setDefaultSorting("dossier.description")
197  .onCriteria(w -> addCriteria(w, true))
198  .getClause();
199  }
200 
201  @Override
203  WhereClause wc = new WhereClause();
204  wc.addClause("select count(distinct dossier) from Dossier as dossier");
205  wc.addClause("left outer join dossier.participants participant");
206  wc.addClause("left outer join dossier.project project");
207  addCriteria(wc, true);
208  return wc;
209  }
210 
211  public String getActualParameters() {
212  return Strings.isBlank(actualParameters) ? "?a=b" : actualParameters;
213  }
214 
215  public AttachCtrl getAttachments(Object obj) {
216  if(obj instanceof Issue) {
217  Issue issue = (Issue) obj;
221  ac.setPublicOnly(false);
222  } else {
223  ac.setPublicOnly(true);
224  }
225  return ac;
226  } else if(obj instanceof Dossier) {
227  Dossier dossier = (Dossier) obj;
230  IContact contact = Authentication.getIContact();
231  ac.addRestrictedFolders(dossier.getFullParticipants().getParticipationStrings(contact));
232  if(isRestricted() && new DossierWrapper(dossier).getCanShowAllAttachments()) {
233  ac.setPublicOnly(false);
234  } else {
235  ac.setPublicOnly(true);
236  }
237  return ac;
238  }
239  return null;
240  }
241 
242  public String getCreateIssueCtrl(String link, Dossier dossier, String template) {
243  return CreateIssueCtrl.createIssue(link, dossier.getId() + "", template);
244  }
245 
246  public String getAddInformationCtrl(String link, Issue issue, String template) {
247  return AddInformationCtrl.addInformation(new IssueWrapper(issue), link, template);
248  }
249 
250  public Object getParticipationCtrl(Dossier dossier, ParticipationReason reason) {
252  }
253 
254  @Override
255  protected void renderSummary(ElephantMarker marker, Dossier e, int page) {
256  if(e != null) {
257  marker.put("dossier", e);
258  marker.put("newCategory", e.getCategory().getId() != lastCategoryId);
259  lastCategoryId = e.getCategory().getId();
260  prepareValues(e, page, false);
261  marker.put("restricted", isRestricted());
262  }
263  marker.process("dossier", getSummaryTemplate());
264  actualParameters = getPageLink(page);
265  }
266 
267  @Override
268  protected void renderItem(ElephantMarker marker, Dossier e, int page) {
269  Long issueId = (Long) ObjectString.parseString(constructor.getParameter("issueId"), Long.class, false);
270  if(issueId != null) {
271  Issue issue = dao.find(Issue.class, issueId);
272  if(issue != null && issue.getDossier().getId().equals(e.getId())) {
273  marker.put("issue", issue);
274  if(!Strings.isBlank(issue.getFullDescription(showSubject))) {
276  "jQuery('title').html('" + issue.getFullDescription(showSubject).replace("'", "\\'") + "');"
277  );
278  }
279  prepareValues(issue, page, false);
280  marker.put("restricted", isRestricted());
281  marker.process("issue", getFullTemplate());
282  }
283  } else {
284  marker.put("dossier", e);
285 // if(!Strings.isBlank(e.getFullDescription(showSubject))) {
286 // constructor.addOnLoadedJavaScript(
287 // "jQuery('title').html('" + e.getFullDescription(showSubject).replace("'", "\\'") + "');"
288 // );
289 // }
290  prepareValues(e, page, false);
291  marker.put("restricted", isRestricted());
292  marker.process("dossier", getFullTemplate());
293  }
294  actualParameters = getPageLink(page);
295  }
296 
297  @Override
298  protected String entityRoot() {
299  return "dossier";
300  }
301 
302  @Override
303  protected Dossier entity(Long value) {
304  WhereClause wc = new WhereClause();
305  wc.addClause("select distinct dossier from Dossier as dossier");
306  wc.addClause("left outer join dossier.participants participant");
307  wc.addClause("left outer join dossier.project project");
308  addCriteria(wc, true);
309  wc.addClause("and dossier.id = :id");
310  wc.addNamedValue("id", value);
311  return (Dossier) dao.getSingleResultOrNull(wc);
312  }
313 
314  @Override
315  protected Long getIdentifier() {
316  Long identifier = getIDFromURL("/dossier");
317  if(identifier == null) {
318  identifier = super.getIdentifier();
319  }
320  return identifier;
321  }
322 
323  private void addCriteria(WhereClause wc, boolean filterPhase) {
324  addCategories(wc);
325  if(!Strings.isBlank(pubPath) && isSearchOption()) {
327  if(dhs != null) {
328  DaoSearchKey dsk = dhs.get("search-value");
329  if(dsk != null) {
330  dsk.applyToQuery(wc, Arrays.objects("dossier.description"), true);
331  }
332  }
333  if(filterPhase) {
334  PhaseHtmlFilter phf = PhaseHtmlFilter.getInstance(constructor, ElephantContext.getContextVariable(constructor));
335  if(phf != null && !phf.isEmpty()) {
336  int phase = Numbers.from(phf.getPhase(), -1).intValue();
337  if(phase > -1) {
338  String par = "phase" + wc.getUniqueSuffix();
339  wc.addClause("and dossier.project.phase = :" + par);
340  wc.addNamedValue(par, phase);
341  }
342  }
343  }
344  }
345  if(!isRestricted()) {
346  wc.addClause("and dossier.publishable = TRUE");
347  }
348  if(!Strings.isBlank(pendingWorths)) {
349  IContact contact = Authentication.getIContact();
350  wc.addClause("and not exists (");
351  wc.addClause("select v from WorthValue v");
352  wc.addClause("where v.dossier = dossier");
353  wc.addClause("and v.worthDefinition.id in (" + pendingWorths + ")");
354  wc.addClause("and v.idContact = :pendContact");
355  wc.addNamedValue("pendContact", contact.getId());
356  wc.addClause(")");
357  }
358  if(categoryId > 0) {
359  wc.addClause("and dossier.category.id in (" + getCategories(categoryId) + ")");
360  } else if(dossierId > 0) {
361  wc.addClause("and dossier.id = " + dossierId);
362  } else if(!Strings.isBlank(allowedCategories)) {
363  if(!wantItem()) {
364  String selCat = CategoriesTree.getSelectedItem(constructor, ElephantContext.getContextVariable(constructor));
365  if(!Strings.isBlank(selCat)) {
366  wc.addClause("and dossier.category.fullDescription like '" + Category.getPathToFullDescription(selCat + "%'"));
367  }
368  }
369  if(!"all".equals(allowedCategories)) {
370  CategoryResults.addExistsCategoryAffiliance(wc, allowedCategories, "dossier");
371  }
372  }
373  if(dossierTypes != null && dossierTypes.size() > 0) {
374  wc.addClause("and dossier.type in (:types)");
375  wc.addNamedValue("types", Arrays.fromCollection(dossierTypes).map(t -> typeValue((String) t)));
376  }
377  if(dossierStatus != null && dossierStatus.size() > 0) {
378  wc.addClause("and dossier.status in (:status)");
379  wc.addNamedValue("status", Arrays.fromCollection(dossierStatus).map(t -> statusValue((String) t)));
380  }
381  if(filterPhase) {
382  if(projectPhases != null && !projectPhases.isEmpty()) {
383  List<Integer> indexes = PhaseDefinitions.instance().stream()
384  .filter(pd -> pd.anyStringMatch(projectPhases))
385  .map(pd -> pd.getIndex()).toList();
386  wc.addClause("and dossier.project.phase in (:phases)");
387  wc.addNamedValue("phases", indexes);
388  }
389  }
390  if(TagCloud.hasSelected(constructor, "dossier")) {
391  wc.addIn("and", "dossier.id", TagCloud.getIdentifiersAsLong(constructor, "dossier"));
392  }
393  }
394 
395  @Override
396  protected boolean isValid(Dossier e) {
397  if(isRestricted() && e != null) {
398  return all || new DossierWrapper(e).isParticipant();
399  } else {
400  return super.isValid(e);
401  }
402  }
403 
404  @Override
405  protected VisualElements loadVisuals() {
406  return DossierVisualElements.load();
407  }
408 
409  private String getCategories(long categoryId) {
410  String result = null;
411  Category category = dao.find(Category.class, Long.valueOf(categoryId));
412  return addCategory(category, result);
413  }
414 
415  private String addCategory(Category category, String result) {
416  if(category != null) {
417  result = (String) (((result == null) ? "" : result + ",") + category.getId());
418  for(Category c : category.getChildren()) {
419  result = addCategory(c, result);
420  }
421  }
422  return result;
423  }
424 
425  private void prepareValues(final Dossier dossier, int page, boolean asMail) {
426  DossierWrapper dw = new DossierWrapper(dossier);
427  marker.put("wrapper", dw);
428  marker.put("iee", Entities.getController(dossier));
429 
430  if(asMail && pubPath != null) {
431  marker.put("name", MailContact.createLink(dossier.getDescription(), getItemLink(dossier, page), false));
432  } else {
433  marker.put("name", dossier.getDescription());
434  }
435  String link = getItemLink(dossier, page);
436  if(link != null) {
437  marker.put("path", link);
438  marker.put("all", getPageLink(page));
439  }
440  if(!Strings.isBlank(pubPath)) {
441  marker.put("readall", getItemLink(dossier, page));
442  }
443  marker.put("dossierClass", "dossier" +
444  (dossier.getStatus().equals(DossierStatus.DOSSIER_OPENED) ? " openned" : "") +
445  (dossier.getStatus().equals(DossierStatus.DOSSIER_CLOSED) ? " closed" : "") +
446  (dossier.getStatus().equals(DossierStatus.DOSSIER_FROZEN) ? " frozen" : ""));
447  if(!Strings.isBlank(issuePath)) {
448  marker.put("issuePath", ElephantContext.getRootWebPath() + issuePath);
449  } else if(dw.getCanShowAllIssues()) {
450  marker.put("issuePath", ElephantContext.getRootWebPath() + "/user/kbase");
451  }
452 
453  if(isAllowVotes()) {
454  if(dossier.getType().isVotes()) {
455  VoteItCtrl vic = new VoteItCtrl(constructor);
456  vic.setEntityPath(DossierPU.getObjectPath(dossier));
457  vic.setForbiden(!dossier.getStatus().isOpen());
458  if(dossier.getType().isSecret()) {
459  vic.setForbid(true);
460  vic.setAllowed((ContactList) dossier.getFullParticipants().getVoteIParticipants());
461  }
462  marker.put("vic", vic);
463  }
464  }
465  if(isAllowInterest()) {
466  StarItCtrl sic = new StarItCtrl(constructor);
467  sic.setEntityPath(DossierPU.getObjectPath(dossier));
468  marker.put("sic", sic);
469  }
470  if(isAllowComments()) {
471  CommentItCtrl cic = new CommentItCtrl(constructor);
472  cic.setEntityPath(DossierPU.getObjectPath(dossier));
473  marker.put("cic", cic);
474  }
475  if(isAllowAttachments()) {
476  AttachCtrl ac = new AttachCtrl(constructor);
477  ac.setEntityPath(DossierPU.getObjectPath(dossier));
478  ac.setPublicOnly(true);
479  IContact contact = Authentication.getIContact();
480  ac.addRestrictedFolders(dossier.getFullParticipants().getParticipationStrings(contact));
481  marker.put("ac", ac);
482  }
483  if(isAllowDescriptions()) {
484  DescribeItCtrl dic = new DescribeItCtrl(constructor);
485  dic.setEntityPath(DossierPU.getObjectPath(dossier));
486  marker.put("dic", dic);
487  }
488  PollsCtrl pollc = new PollsCtrl(constructor);
489  pollc.setEntityPath(DossierPU.getObjectPath(dossier));
490  marker.put("pollc", pollc);
491 
492  final DWIssueModel issueModel = new DWIssueModel();
493  issueModel.setDossierId(dossier.getId());
494  marker.put("issueModel", issueModel);
495  DWWebChart type = new DWWebChart(constructor) {
496  @Override
497  protected void onCreate(Data data, Object[] pars) {
498  data.setLink(ElephantContext.getRootWebPath() + KnowledgeBaseDashboard.createLink("*", false,
499  (Set<IssueType>) EnumSet.of((IssueType) pars[0]), null, null, dossier.getId()));
500  }
501  @Override
502  protected void loadData() {
503  setData(I_.get("Type"), issueModel.getByType());
504  }
505  };
506  marker.put("typeChart", type);
507  DWWebChart status = new DWWebChart(constructor) {
508  @Override
509  protected void onCreate(Data data, Object[] pars) {
510  data.setLink(ElephantContext.getRootWebPath() + KnowledgeBaseDashboard.createLink("*", false, null,
511  (Set<IssueStatus>) EnumSet.of((IssueStatus) pars[0]), null, dossier.getId()));
512  }
513  @Override
514  protected void loadData() {
515  setData(I_.get("Status"), issueModel.getByStatus());
516  }
517  };
518  marker.put("statusChart", status);
519  DWWebChart resolution = new DWWebChart(constructor) {
520  @Override
521  protected void onCreate(Data data, Object[] pars) {
522  data.setLink(ElephantContext.getRootWebPath() + KnowledgeBaseDashboard.createLink("*", false, null, null,
523  (Set<IssueResolution>) EnumSet.of((IssueResolution) pars[0]), dossier.getId()));
524  }
525  @Override
526  protected void loadData() {
527  setData(I_.get("Resolution"), issueModel.getByResolution());
528  }
529  };
530  marker.put("resolutionChart", resolution);
531 
532  marker.put("actions", new DossierAction());
533 
534  marker.put("files", new FileAttach(DossierPU.getObjectPath(dossier)));
535  marker.put("projectContext", new ProjectContext());
536  marker.put("dve", DossierVisualElements.load());
537 
538  /* Students */
539  IEntityCtrl ec = Plugins.loadImplementation(IEntityCtrl.class, "students-ctrl");
540  if(ec != null) {
541  ec.setConstructor(constructor);
542  ec.setEntityPath(DossierPU.getObjectPath(dossier));
543  marker.put("students", ec);
544  }
545 
546  /* Forum */
547  IEntityCtrl ecf = Plugins.loadImplementation(IEntityCtrl.class, "forum-ctrl");
548  if(ecf != null) {
549  ecf.setConstructor(constructor);
550  ecf.setEntityPath(DossierPU.getObjectPath(dossier));
551  ecf.setTemplate("related");
552  marker.put("forum", ecf);
553  }
554 
555  marker.put("follow", getParticipationCtrl(dossier, ParticipationReason.REASON_FOLLOW));
556 
557  if(dw.getCanShowAllIssues()) {
558  marker.put("createIssue", CreateIssueCtrl.linkToCreateIssue(link, dossier.getId() + "", null));
559  }
560  }
561 
562  private void prepareValues(Issue issue, int page, boolean asMail) {
563  marker.put("wrapper", new IssueWrapper(issue));
564  marker.put("iee", Entities.getController(issue));
565 
566  if(isAllowVotes()) {
567  Dossier dossier = issue.getDossier();
568  if(dossier.getType().isVotes()) {
569  VoteItCtrl vic = new VoteItCtrl(constructor);
570  vic.setEntityPath(DossierPU.getObjectPath(issue));
571  vic.setForbiden(issue.getStatus().isFinished());
572  if(dossier.getType().isSecret()) {
573  vic.setForbid(true);
574  vic.setAllowed((ContactList) dossier.getFullParticipants().getVoteIParticipants());
575  }
576  marker.put("vic", vic);
577  }
578  }
579  if(isAllowInterest()) {
580  StarItCtrl sic = new StarItCtrl(constructor);
581  sic.setEntityPath(DossierPU.getObjectPath(issue));
582  marker.put("sic", sic);
583  }
584  if(isAllowComments()) {
585  CommentItCtrl cic = new CommentItCtrl(constructor);
586  cic.setEntityPath(DossierPU.getObjectPath(issue));
587  marker.put("cic", cic);
588  }
589  if(isAllowAttachments()) {
590  AttachCtrl ac = new AttachCtrl(constructor);
591  ac.setEntityPath(DossierPU.getObjectPath(issue));
592  ac.setPublicOnly(true);
593  IContact contact = Authentication.getIContact();
594  ac.addRestrictedFolders(issue.getDossier().getFullParticipants().getParticipationStrings(contact));
595  marker.put("ac", ac);
596  }
597  if(isAllowDescriptions()) {
598  DescribeItCtrl dic = new DescribeItCtrl(constructor);
599  dic.setEntityPath(DossierPU.getObjectPath(issue));
600  marker.put("dic", dic);
601  }
602  marker.put("files", new FileAttach(DossierPU.getObjectPath(issue)));
603  }
604 
605  private String getItemLink(Dossier dossier, int page) {
606  if(pubPath == null) {
607  String link = dossier.getDossierURL();
608  if(link == null) {
609  return null;
610  } else {
611  return ElephantContext.getRootWebPath() + link;
612  }
613  } else {
614  String ewu = EntityWebUrls.getUrlFromEntity(dossier);
615  if(ewu != null) {
616  return pubPath + ewu;
617  } else {
618  return pubPath + "?" + MarkerHelper.setObfuscatedPars("item=" + dossier.getId());
619  }
620  }
621  }
622 
623  private String getPageLink(int page) {
624  return pubPath + "?page=" + page;
625  }
626 
627  @Override
628  protected String title(Dossier e) {
629  if(!Strings.isBlank(e.getFullDescription(showSubject))) {
630  return e.getFullDescription(showSubject);
631  }
632  return null;
633  }
634 
635  @Override
636  protected Collection<String> metas(Dossier e) {
637  ArrayList<RepositoryFile> files = new ArrayList<>();
638  String path = getItemLink(e, 0);
639  if(!SocialImageMap.hasImage(path)) {
642  files.addAll(repository.getRepositoryFiles("*_social.png,*_social.jpg"));
643  files.addAll(repository.getRepositoryFiles("*.png,*.jpg"));
644  }
645  SocialNet sn;
646  if(e.getProject() != null) {
647  sn = new SocialNet(path, e.getDescription(), e.getProject().getGoal(), files);
648  } else {
649  sn = new SocialNet(path, e.getDescription(), e.getFullDescription(), files);
650  }
651  return sn.getMetas();
652  }
653 
654  private void addCategories(WhereClause wc) {
655  if(direct) {
656  IContact contact = Authentication.getIContact();
657  if(contact == null || !contact.isValid()) {
658  wc.addClause("where 1=2");
659  } else {
660  wc.addClause("where (");
661  wc.addClause("participant.idContact = :idContact");
662  wc.addNamedValue("idContact", contact.getId());
663  wc.addClause("and (participant.role = :cpdrole1 or participant.role = :cpdrole2)");
664  wc.addNamedValue("cpdrole1", ParticipantRole.PARTICIPANT_OWNER);
665  wc.addNamedValue("cpdrole2", ParticipantRole.PARTICIPANT_ASSISTANT);
666  wc.addClause(")");
667  }
668  } else if(related != null) {
669  if(related.isEmpty()) {
670  wc.addClause("where 1=2");
671  } else {
672  wc.addClause("where (");
673  wc.addClause("participant.idContact in (:idContact)");
674  wc.addNamedValue("idContact", new SetOf<IContact, String>(related, new ItemOf<IContact, String>() {
675  @Override
676  public String getFrom(IContact e) {
677  return e.getId();
678  }
679  }));
680  wc.addClause("and (participant.role = :cpdrole1 or participant.role = :cpdrole2)");
681  wc.addNamedValue("cpdrole1", ParticipantRole.PARTICIPANT_OWNER);
682  wc.addNamedValue("cpdrole2", ParticipantRole.PARTICIPANT_ASSISTANT);
683  wc.addClause(")");
684  }
685  } else if(isRestricted() && !Application.getApplication().isInRole("dossier:all")) {
686  IContact contact = Authentication.getIContact();
687  if(contact == null || !contact.isValid()) {
688  wc.addClause("where 1=2");
689  } else {
690  wc.addClause("where ((");
691  wc.addClause("participant.idContact = :idContact");
692  wc.addNamedValue("idContact", contact.getId());
693  wc.addClause("and (participant.role = :cpdrole1 or participant.role = :cpdrole2)");
694  wc.addNamedValue("cpdrole1", ParticipantRole.PARTICIPANT_OWNER);
695  wc.addNamedValue("cpdrole2", ParticipantRole.PARTICIPANT_ASSISTANT);
696  wc.addClause(")");
697  CategoryResults.addParticipantAffiliance(wc, "or", contact.getId(), "dossier");
698  wc.addClause(")");
699  }
700  } else {
701  wc.addClause("where 1=1");
702  }
703  }
704 
705  private DossierType typeValue(String name) {
706  return DossierType.valueOf(name);
707  }
708 
709  private DossierStatus statusValue(String name) {
710  return DossierStatus.valueOf(name);
711  }
712 
713 }
void addRestrictedFolders(HashSet< String > restrictedFolders)
Definition: AttachCtrl.java:67
void setPublicOnly(boolean publicOnly)
Definition: AttachCtrl.java:77
void setEntityPath(String entityPath)
Definition: AttachCtrl.java:45
static String getObjectPath(Object object)
Definition: DossierPU.java:66
ParticipantSet< IDossierParticipant > getFullParticipants()
Definition: Dossier.java:399
static String addInformation(String issueId, String link, String template)
static String createIssue(String link, String dossierId, String template)
DossierIterator(IConstructor constructor, String pubPath, String uniqueId)
void setAllowedCategories(String allowedCategories)
Collection< String > metas(Dossier e)
DossierIterator(IConstructor constructor, boolean mail, String pubPath, String uniqueId)
void setPhaseFilter(PhaseHtmlFilter phaseFilter)
void setProjectPhases(List< String > projectPhases)
void renderSummary(ElephantMarker marker, Dossier e, int page)
void renderItem(ElephantMarker marker, Dossier e, int page)
Object getParticipationCtrl(Dossier dossier, ParticipationReason reason)
void setShowSubject(boolean showSubject)
void setRelated(Collection< IContact > related)
String getCreateIssueCtrl(String link, Dossier dossier, String template)
String getAddInformationCtrl(String link, Issue issue, String template)
void setPendingWorths(String pendingWorths)
void setDossierStatus(List< String > dossierStatus)
static String getContextVariable(IConstructor constructor)
void addIn(String operator, String field, List values)
void addNamedValue(String name, Object value)
static boolean hasImage(String url)
static IElephantEntity getController(String path)
Definition: Entities.java:78
Repository getPublishableRepository(IConstructor constructor)
Definition: FileAttach.java:47
static Statistics load(IConstructor constructor, String rankingInstance, String matchingInstance, WhereClause wc)
Object getSingleResultOrNull(SqlClause sc)
Definition: Dao.java:419
static DaoHtmlSearch getInstance(IConstructor constructor, String context)
boolean applyToQuery(WhereClause wc, List< String > fields, boolean withSynonyms)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
void addOnLoadedJavaScript(String script)
Object getParticipationControl(IConstructor constructor, ParticipationReason reason)