BrightSide Workbench Full Report + Source Code
DossierDashboard.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.dossier.www;
19 
20 import java.io.IOException;
21 import java.io.PrintWriter;
22 import java.util.List;
23 import javax.servlet.ServletException;
24 import org.turro.string.Strings;
25 import org.turro.auth.Authentication;
26 import org.turro.dashboard.AbstractDaoDashboard;
27 import org.turro.dossier.dossier.DossierCounter;
28 import org.turro.dossier.entity.Category;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.elephant.web.ElContext;
31 import org.turro.indicator.Indicators;
32 import org.turro.jpa.iterator.DaoHtmlIterator;
33 import org.turro.jpa.search.DaoHtmlSearch;
34 import org.turro.jpa.search.DaoSearchKey;
35 import org.turro.phase.PhaseDefinitions;
36 
41 public class DossierDashboard extends AbstractDaoDashboard {
42 
43  protected String categoryTemplate, orderBy, allowedCategories, issuePath, phaseTemplate;
44  protected List<String> issueTypes, issueStatus, dossierTypes, dossierStatus, projectPhases;
45  protected long categoryId, dossierId;
46  protected Category lastCategory = null;
47  protected boolean showSubject, onlyDossiers;
48  protected DossierIterator di;
49  protected IssueIterator ii;
50  protected CategoriesTree pi;
51 
52  @Override
54  categoryId = getAttributes().getAttributeIntegerValue("attrib:categoryId", 0);
55  dossierId = getAttributes().getAttributeIntegerValue("attrib:dossierId", 0);
56  // TYPE_DOSSIER,TYPE_PROPOSAL,TYPE_SECRET_PROPOSAL,TYPE_ELECTION,TYPE_SECRET_ELECTION,TYPE_PROJECT
57  dossierTypes = getAttributes().getAttributeListValue("attrib:dossierTypes", null);
58  // DOSSIER_OPENED,DOSSIER_CLOSED,DOSSIER_FROZEN
59  dossierStatus = getAttributes().getAttributeListValue("attrib:dossierStatus", null);
60  // PROJECT_IDEA,PROJECT_INCUBATOR,PROJECT_VOTING,PROJECT_DECIDING,PROJECT_OPPOSITING,PROJECT_VALIDATED,PROJECT_RESOLUTION;
61  projectPhases = getAttributes().getAttributeListValue("attrib:projectPhases", null);
62  // TYPE_DEFECT,TYPE_ENHANCEMENT,TYPE_FEATURE,TYPE_NONCONFORMITY,TYPE_PREVENTION,TYPE_TASK,TYPE_PATCH,TYPE_QUESTION,TYPE_DOCUMENT,TYPE_BESTPRACTICE
63  issueTypes = getAttributes().getAttributeListValue("attrib:issueTypes", "");
64  // STATUS_NEW,STATUS_STARTED,STATUS_INCOMPLETE,STATUS_REOPENED,STATUS_REUNION,STATUS_FROZEN,STATUS_RESOLVED,STATUS_VERIFIED,STATUS_CLOSED
65  issueStatus = getAttributes().getAttributeListValue("attrib:issueStatus", "");
66  allowedCategories = getAttributes().getAttributeValue("attrib:allowedCategories", "");
67  showSubject = getAttributes().getAttributeBooleanValue("attrib:showSubject", true);
68  onlyDossiers = getAttributes().getAttributeBooleanValue("attrib:onlyDossiers", false);
69  categoryTemplate = getAttributes().getAttributeValue("attrib:categoryTemplate", "");
70  phaseTemplate = getAttributes().getAttributeValue("attrib:phaseTemplate", "");
71  orderBy = getAttributes().getAttributeValue("attrib:orderBy", "ORDER_BY_CATEGORY_DOSSIER_ISSUE");
72  issuePath = getAttributes().getAttributeValue("attrib:issuePath", "");
73 
74  if(onlyDossiers) {
75  if(!Strings.isBlank(allowedCategories)) {
77  allowedCategories,
78  dossierTypes == null ? null : dossierTypes.toArray(new String[0]),
79  dossierStatus == null ? null : dossierStatus.toArray(new String[0]));
80  if(!Strings.isBlank(categoryTemplate)) {
82  }
84  pi.setAllowForum(true);
85  pi.fillTree("");
86  }
87  di = new DossierIterator(getConstructor(), getContext().getFullPath(), getId());
89  di.setDossierId(dossierId);
90  di.setDossierTypes(dossierTypes);
91  di.setDossierStatus(dossierStatus);
92  di.setProjectPhases(projectPhases);
93  di.setAllowedCategories(allowedCategories);
94  di.setIssuePath(issuePath);
95  return di;
96  } else {
97  ii = new IssueIterator(getConstructor(), getContext().getFullPath(), getId());
99  ii.setDossierId(dossierId);
100  ii.setDossierStatus(dossierStatus);
101  ii.setIssueStatus(issueStatus);
103  ii.setOrderBy(IssueOrdering.valueOf(orderBy));
104  return ii;
105  }
106  }
107 
108  @Override
109  protected void initSearchEngine() {
110  if(onlyDossiers) {
112  if(dhs != null) {
113  dhs.setTagRoot("dossier");
115  dhs.setAttribute(getConstructor(), "dossierCounter", new DossierCounter(allowedCategories, dossierTypes, dossierStatus, isRestricted()));
116  DaoSearchKey dsk = dhs.get("point-of-view");
117  if(dsk != null && Strings.isBlank(dsk.getValue())) {
118  dsk = new DaoSearchKey("point-of-view", "text");
119  dsk.setValue(isDoMatching() ? "1" : "0");
120  dhs.put("point-of-view", dsk);
121  }
122  if(dsk != null) {
123  if("1".equals(dsk.getValue())) {
124  dhs.setAttribute(getConstructor(), "variables", Indicators.getMatchingVariablesFinal("dossier"));
125  } else {
126  dhs.setAttribute(getConstructor(), "variables", Indicators.getRankingVariablesFinal("dossier"));
127  }
128  }
129  }
130  }
131  }
132 
133  @Override
134  public void startConstruction() throws ServletException, IOException {
135  PrintWriter out = getConstructor().getOut();
136  out.print(getStart());
137  out.print(getStartBody());
138 
139  if(onlyDossiers) {
140  if(pi != null) {
141  if(!di.isItem()) {
148  }
150  }
151  if(!di.isItem()) {
153  if(dhs != null) {
154  di.setSearchEngine(dhs);
155  }
156  if(!Strings.isBlank(phaseTemplate)) {
158  phf.setTemplate(phaseTemplate);
159  phf.setAllowedCategories(allowedCategories);
160  phf.setTypes(dossierTypes == null ? null : dossierTypes.toArray(new String[0]));
161  phf.setStatus(dossierStatus == null ? null : dossierStatus.toArray(new String[0]));
162  di.setPhaseFilter(phf);
163  }
164  }
165  di.render();
166  } else {
168  if(dhs != null) {
169  ii.setSearchEngine(dhs);
170  }
171  ii.render();
172  }
173 
174  out.print(getEndBody());
175  out.print(getEnd());
176  }
177 
178  @Override
179  public void setRootCategories(ElContext root) {
180  // TYPE_DOSSIER,TYPE_PROPOSAL,TYPE_SECRET_PROPOSAL,TYPE_ELECTION,TYPE_SECRET_ELECTION,TYPE_PROJECT
181  dossierTypes = getAttributes().getAttributeListValue("attrib:dossierTypes", null);
182  // DOSSIER_OPENED,DOSSIER_CLOSED,DOSSIER_FROZEN
183  dossierStatus = getAttributes().getAttributeListValue("attrib:dossierStatus", null);
184  allowedCategories = getAttributes().getAttributeValue("attrib:allowedCategories", "");
185  onlyDossiers = getAttributes().getAttributeBooleanValue("attrib:onlyDossiers", false);
186  if(onlyDossiers) {
187  if(!Strings.isBlank(allowedCategories)) {
188  CategoriesTree catTree = new CategoriesTree(getConstructor(), root.getPath(), null,
189  allowedCategories,
190  dossierTypes == null ? null : dossierTypes.toArray(new String[0]),
191  dossierStatus == null ? null : dossierStatus.toArray(new String[0]));
192  catTree.setRestricted(isRestricted());
193  catTree.fillTree("");
194  root.generateCategoriesChildren(catTree, (t) -> {
195  return "?" + CategoriesTree.getSelectionLink(t.getPath());
196  });
197  }
198  }
199  }
200 
201 }
void setAllowedCategories(String allowedCategories)
void setPhaseFilter(PhaseHtmlFilter phaseFilter)
void setProjectPhases(List< String > projectPhases)
void setDossierStatus(List< String > dossierStatus)
void setIssueStatus(List< String > issueStatus)
void setDossierStatus(List< String > dossierStatus)
void setOrderBy(IssueOrdering orderBy)
void setCategoryId(long categoryId)
void setIssueTypes(List< String > issueTypes)
static String getContextVariable(IConstructor constructor)
void generateCategoriesChildren(Tree tree, Function< Item, String > onParam)
Definition: ElContext.java:491
static List< IndicatorVariable > getMatchingVariablesFinal(String root)
Definition: Indicators.java:58
static List< IndicatorVariable > getRankingVariablesFinal(String root)
Definition: Indicators.java:52
void setAllowDescriptions(boolean allowDescriptions)
void setNavigationTree(DaoHtmlTree navigationTree)
void setSearchEngine(DaoHtmlSearch searchEngine)
void setFullTemplate(String fullTemplate)
void fillTree(String path)
Definition: DaoTree.java:45
void setAttribute(IConstructor constructor, String attribute, Object value)
static PhaseDefinitions instance()