BrightSide Workbench Full Report + Source Code
DossierParser.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2014 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.parser;
20 
21 import java.io.IOException;
22 import java.util.Arrays;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.turro.string.ObjectString;
26 import org.turro.string.Strings;
27 import org.turro.annotation.ExternalParser;
28 import org.turro.auth.Authentication;
29 import org.turro.dossier.entity.IssueType;
30 import org.turro.dossier.www.AddInformationCtrl;
31 import org.turro.dossier.www.CategoriesTree;
32 import org.turro.dossier.www.CreateIssueCtrl;
33 import org.turro.dossier.www.DossierIterator;
34 import org.turro.dossier.www.EditDossierCtrl;
35 import org.turro.dossier.www.IssueIterator;
36 import org.turro.dossier.www.IssueOrdering;
37 import org.turro.dossier.www.QuestionCtrl;
38 import org.turro.elephant.context.ElephantContext;
39 import org.turro.elephant.context.IConstructor;
40 import org.turro.path.Path;
41 import org.turro.util.IdGenerator;
42 
47 @ExternalParser
48 public class DossierParser extends AbstractParser {
49 
50  @Override
51  public String getParserName() {
52  return "Dossier";
53  }
54 
55  @Override
56  protected boolean doExecute() {
57  boolean done = false;
58  if("issues".equals(getMacroName()) || "issue-summary".equals(getMacroName()) ||
59  "myissues".equals(getMacroName()) || "myissue-summary".equals(getMacroName()) ||
60  "assisted-issues".equals(getMacroName()) || "assisted-issue-summary".equals(getMacroName())) {
62  Strings.isBlank(getToken(2)) ? null : ElephantContext.getRootWebPath() + getToken(2),
63  IdGenerator.generate());
64  if("onwork".equals(getToken(1))) {
65  ii.setIssueStatus(Arrays.asList("STATUS_NEW,STATUS_STARTED,STATUS_INCOMPLETE,STATUS_REOPENED,STATUS_REUNION,STATUS_FROZEN,STATUS_RESOLVED,STATUS_VERIFIED".split(",")));
66  } else if("closed".equals(getToken(1))) {
67  ii.setIssueStatus(Arrays.asList("STATUS_CLOSED".split(",")));
68  }
69  ii.setCategoryId((Integer) ObjectString.parseNativeString(getToken(3), Integer.class, true));
70  ii.setDossierId((Integer) ObjectString.parseNativeString(getToken(4), Integer.class, true));
71  ii.setPage((Integer) ObjectString.parseNativeString(getToken(5), Integer.class, true));
72  ii.setAllowAttachments(true);
73  ii.setAllowDescriptions(true);
74  ii.setAllowInterest(true);
75  ii.setAllowVotes(true);
76  ii.setAllowComments(true);
77  ii.setRestricted(false);
79  if(getMacroName().contains("summary")) {
81  ii.setNavigatorTop(false);
82  ii.setNavigatorBottom(false);
83  }
84  if(getMacroName().contains("myissue")) {
85  ii.setRestricted(true);
86  }
87  if(getMacroName().contains("assisted")) {
88  ii.setRestricted(true);
89  ii.setOnlyAssists(true);
90  }
91  ii.load();
92  ii.render();
93  done = true;
94  } else if("dossiers".equals(getMacroName()) || "dossier-summary".equals(getMacroName()) ||
95  "mydossiers".equals(getMacroName()) || "mydossier-summary".equals(getMacroName())) {
96  //{@dossiers:onwork|closed|all:context:categoryIds:dossierId:count[:summary]}
98  Strings.isBlank(getToken(2)) ? null : ElephantContext.getRootWebPath() + getToken(2),
99  IdGenerator.generate());
100  if("onwork".equals(getToken(1))) {
101  di.setDossierStatus(Arrays.asList("DOSSIER_OPENED,DOSSIER_FROZEN".split(",")));
102  } else if("closed".equals(getToken(1))) {
103  di.setDossierStatus(Arrays.asList("DOSSIER_CLOSED".split(",")));
104  } else if("not-frozen".equals(getToken(1))) {
105  di.setDossierStatus(Arrays.asList("DOSSIER_OPENED,DOSSIER_CLOSED".split(",")));
106  } else if("frozen".equals(getToken(1))) {
107  di.setDossierStatus(Arrays.asList("DOSSIER_FROZEN".split(",")));
108  }
110  di.setDossierId((Integer) ObjectString.parseNativeString(getToken(4), Integer.class, true));
111  di.setPage((Integer) ObjectString.parseNativeString(getToken(5), Integer.class, true));
112  di.setAllowAttachments(true);
113  di.setAllowDescriptions(true);
114  di.setAllowInterest(true);
115  di.setAllowVotes(true);
116  di.setAllowComments(true);
117  di.setRestricted(false);
119  if(getMacroName().contains("summary")) {
120  di.setNavigatorTop(false);
121  di.setNavigatorBottom(false);
122  }
123  if(getMacroName().contains("mydossiers")) {
124  di.setRestricted(true);
125  }
126  di.load();
127  di.render();
128  done = true;
129  } else if("direct-dossiers".equals(getMacroName()) || "direct-dossier-summary".equals(getMacroName()) ||
130  "related-dossiers".equals(getMacroName()) || "related-dossier-summary".equals(getMacroName())) {
132  Strings.isBlank(getToken(2)) ? null : ElephantContext.getRootWebPath() + getToken(2),
133  IdGenerator.generate());
134  if("onwork".equals(getToken(1))) {
135  di.setDossierStatus(Arrays.asList("DOSSIER_OPENED,DOSSIER_FROZEN".split(",")));
136  } else if("closed".equals(getToken(1))) {
137  di.setDossierStatus(Arrays.asList("DOSSIER_CLOSED".split(",")));
138  } else if("not-frozen".equals(getToken(1))) {
139  di.setDossierStatus(Arrays.asList("DOSSIER_OPENED,DOSSIER_CLOSED".split(",")));
140  } else if("frozen".equals(getToken(1))) {
141  di.setDossierStatus(Arrays.asList("DOSSIER_FROZEN".split(",")));
142  }
144  di.setPage((Integer) ObjectString.parseNativeString(getToken(4), Integer.class, true));
145  di.setAllowAttachments(true);
146  di.setAllowDescriptions(true);
147  di.setAllowInterest(true);
148  di.setAllowVotes(true);
149  di.setAllowComments(true);
150  if(getMacroName().contains("direct")) {
151  di.setRestricted(true);
152  di.setDirect(true);
153  }
154  if(getMacroName().contains("related")) {
155  di.setRestricted(false);
157  }
159  if(getMacroName().contains("summary")) {
160  di.setNavigatorTop(false);
161  di.setNavigatorBottom(false);
162  }
163  di.load();
164  di.render();
165  done = true;
166  } else if("pending-vote".equals(getMacroName())) {
168  Strings.isBlank(getToken(1)) ? null : ElephantContext.getRootWebPath() + getToken(1),
169  IdGenerator.generate());
170  di.setProjectPhases(Arrays.asList(new String[] { getToken(2) }));
172  di.setPage((Integer) ObjectString.parseNativeString(getToken(5), Integer.class, true));
173  di.setAllowAttachments(true);
174  di.setAllowDescriptions(true);
175  di.setAllowInterest(true);
176  di.setAllowVotes(true);
177  di.setAllowComments(true);
178  di.setRestricted(false);
179  di.setPendingWorths(getToken(3));
181  di.setNavigatorTop(false);
182  di.setNavigatorBottom(false);
183  di.load();
184  di.render();
185  done = true;
186  } else if("categories".equals(getMacroName())) {
188  null,
189  null,
190  getToken(1),
191  getToken(2)));
192  done = true;
193  } else if("web-path".equals(getMacroName())) {
194  if(getToken(1).startsWith("/dossier/")) {
195  Path path = new Path(getToken(1));
196  out.write("/user/mydossiers/?item=" + path.getLastNode());
197  done = true;
198  } else if(getToken(1).startsWith("/issue/")) {
199  Path path = new Path(getToken(1));
200  out.write("/user/myissues/?item=" + path.getLastNode());
201  done = true;
202  }
203  } else if("edit-dossier".equals(getMacroName())) {
205  done = true;
206  } else if("create-issue".equals(getMacroName())) {
208  done = true;
209  } else if("edit-question".equals(getMacroName())) {
210  out.write(QuestionCtrl.editQuestion(getToken(1), getToken(2), IssueType.valueOf(getToken(3)), getToken(4)));
211  done = true;
212  } else if("issue-add-info".equals(getMacroName())) {
214  done = true;
215  }
216  return done;
217  }
218 
219  @Override
220  protected void explainMacros(ParserMacroSet macros) {
221  macros.addMacro("issues")
222  .addParameter("status", false)
223  .addPossibleValue("onwork")
224  .addPossibleValue("closed")
225  .addPossibleValue("all")
226  .addParameter("context", true)
227  .addParameter("categoryId", true, "0")
228  .addParameter("dossierId", true, "0")
229  .addParameter("count", true, "10")
230  .addParameter("template", true, "summary")
231  .addPossibleValue("mySummary")
232  .addPossibleValue("kbSummary")
233  .addPossibleValue("questions")
234  .addPossibleValue("proposals")
235  .addPossibleValue("motions");
236  macros.addMacro("issue-summary")
237  .copyParametersFrom("issues", macros);
238  macros.addMacro("myissues")
239  .copyParametersFrom("issues", macros);
240  macros.addMacro("myissues-summary")
241  .copyParametersFrom("issues", macros);
242  macros.addMacro("assisted-issues")
243  .copyParametersFrom("issues", macros);
244  macros.addMacro("assisted-issue-summary")
245  .copyParametersFrom("issues", macros);
246  macros.addMacro("dossiers")
247  .addParameter("status", false)
248  .addPossibleValue("onwork")
249  .addPossibleValue("closed")
250  .addPossibleValue("not-frozen")
251  .addPossibleValue("frozen")
252  .addPossibleValue("all")
253  .addParameter("context", true)
254  .addParameter("categoryIds", true, null, true)
255  .addParameter("dossierId", true)
256  .addParameter("count", true, "10")
257  .addParameter("template", true, "summary")
258  .addPossibleValue("projects")
259  .addPossibleValue("dossiers");
260  macros.addMacro("dossier-summary")
261  .copyParametersFrom("dossiers", macros);
262  macros.addMacro("mydossiers")
263  .copyParametersFrom("dossiers", macros);
264  macros.addMacro("mydossier-summary")
265  .copyParametersFrom("dossiers", macros);
266  macros.addMacro("direct-dossiers")
267  .addParameter("status", false)
268  .addPossibleValue("onwork")
269  .addPossibleValue("closed")
270  .addPossibleValue("not-frozen")
271  .addPossibleValue("frozen")
272  .addPossibleValue("all")
273  .addParameter("context", true)
274  .addParameter("categoryIds", true, null, true)
275  .addParameter("count", true, "10")
276  .addParameter("template", true, "summary")
277  .addPossibleValue("projects")
278  .addPossibleValue("dossiers");
279  macros.addMacro("direct-dossier-summary")
280  .copyParametersFrom("direct-dossiers", macros);
281  macros.addMacro("related-dossiers")
282  .copyParametersFrom("dossiers", macros);
283  macros.addMacro("related-dossier-summary")
284  .copyParametersFrom("dossiers", macros);
285  macros.addMacro("pending-vote")
286  .addParameter("context", false)
287  .addParameter("phase", false)
288  .addParameter("worths", false, null, true)
289  .addParameter("categoryIds", true, null, true)
290  .addParameter("count", true, "10")
291  .addParameter("template", true, "summary")
292  .addPossibleValue("projects")
293  .addPossibleValue("dossiers");
294  macros.addMacro("categories")
295  .addParameter("status", false)
296  .addPossibleValue("onwork")
297  .addPossibleValue("closed")
298  .addPossibleValue("not-frozen")
299  .addPossibleValue("frozen")
300  .addPossibleValue("all")
301  .addParameter("context", true)
302  .addParameter("categoryIds", true, null, true)
303  .addParameter("template", true, "full");
304  macros.addMacro("web-path")
305  .addParameter("path", false);
306  macros.addMacro("edit-dossier")
307  .addParameter("id", false)
308  .addParameter("template", true, "editDossier");
309  macros.addMacro("create-issue")
310  .addParameter("redirect", false)
311  .addParameter("dossierId", true)
312  .addParameter("template", true, "create");
313  macros.addMacro("edit-question")
314  .addParameter("id", false)
315  .addParameter("redirect", false)
316  .addParameter("type", true, "TYPE_QUESTION")
317  .addParameter("template", true, "editQuestion");
318  macros.addMacro("issue-add-info")
319  .addParameter("id", false)
320  .addParameter("template", true, "addinfo")
321  .addParameter("redirect", true);
322  }
323 
324  public String getCategories(IConstructor constructor, String summaryTemplate, String fullTemplate, String context, String categories) {
325  try {
327  CategoriesTree pi = new CategoriesTree(constructor, context, Authentication.getIContact(), categories, null, null);
328  pi.fillTree("");
329  pi.render();
330  constructor.setOut(null);
331  return constructor.getOutputString();
332  } catch (IOException ex) {
333  Logger.getLogger(ContactsParser.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
334  }
335  return null;
336  }
337 
338 }
static String addInformation(String issueId, String link, String template)
static String createIssue(String link, String dossierId, String template)
void setAllowedCategories(String allowedCategories)
void setProjectPhases(List< String > projectPhases)
void setRelated(Collection< IContact > related)
void setPendingWorths(String pendingWorths)
void setDossierStatus(List< String > dossierStatus)
static String editDossier(String dossierId, String link, String template)
void setIssueStatus(List< String > issueStatus)
void setOnlyAssists(boolean onlyAssists)
void setOrderBy(IssueOrdering orderBy)
void setCategoryId(long categoryId)
static String editQuestion(String issueId, String link, IssueType type, String template)
void setAllowAttachments(boolean allowAttachments)
void setAllowInterest(boolean allowInterest)
void setAllowDescriptions(boolean allowDescriptions)
void setAllowComments(boolean allowComments)
void setNavigatorBottom(boolean navigatorBottom)
void setSummaryTemplate(String summaryTemplate)
void setNavigatorTop(boolean navigatorTop)
void fillTree(String path)
Definition: DaoTree.java:45
void explainMacros(ParserMacroSet macros)
String getCategories(IConstructor constructor, String summaryTemplate, String fullTemplate, String context, String categories)
ParserMacro addMacro(String macroName)
ParserMacro addPossibleValue(String value)
void copyParametersFrom(String macroName, ParserMacroSet macros)
ParserMacro addParameter(String name, boolean optional)