BrightSide Workbench Full Report + Source Code
DossierContentProvider.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 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.content;
20 
21 import java.io.StringWriter;
22 import java.io.Writer;
23 import java.util.Arrays;
24 import org.turro.action.content.AbstractContentProvider;
25 import org.turro.action.content.ContentRenderer;
26 import org.turro.action.content.IContentIterator;
27 import org.turro.annotation.ContentProvider;
28 import org.turro.command.MacroCommand;
29 import org.turro.dossier.www.IssueOrdering;
30 import org.turro.elephant.context.HeadlessApplication;
31 import org.turro.plugin.contacts.IContact;
32 
37 @ContentProvider
39 
41  addCommands();
42  }
43 
44  private void addCommands() {
45  // dossiers
46  MacroCommand mc = new MacroCommand("dossiers");
47  mc.addParameter("status", "onwork", true)
48  .setPossibleValuesString("onwork|closed|all");
49  mc.addParameter("context", "", true);
50  mc.addParameter("categoryIds", "", true);
51  mc.addParameter("dossierId", Long.valueOf(0), true);
52  mc.addParameter("count", Integer.valueOf(10), true);
53  mc.addParameter("restricted", Boolean.FALSE, true);
54  mc.addParameter("direct", Boolean.FALSE, true);
55  mc.addParameter("related", Boolean.FALSE, true);
56  mc.addParameter("template", "summary", true);
57  commands.add(mc);
58 
59  // projects
60  mc = new MacroCommand("projects");
61  mc.addParameter("status", "onwork", false)
62  .setPossibleValuesString("onwork|closed|all");
63  mc.addParameter("context", "", false);
64  mc.addParameter("categoryIds", "", true);
65  mc.addParameter("dossierId", Long.valueOf(0), true);
66  mc.addParameter("count", Integer.valueOf(10), true);
67  mc.addParameter("restricted", Boolean.FALSE, true);
68  mc.addParameter("direct", Boolean.FALSE, true);
69  mc.addParameter("related", Boolean.FALSE, true);
70  mc.addParameter("template", "summary", true);
71  commands.add(mc);
72 
73  // issues
74  mc = new MacroCommand("issues");
75  mc.addParameter("status", "onwork", false)
76  .setPossibleValuesString("onwork|closed|all");
77  mc.addParameter("context", "", false);
78  mc.addParameter("categoryId", Long.valueOf(0), true);
79  mc.addParameter("dossierId", Long.valueOf(0), true);
80  mc.addParameter("count", Integer.valueOf(10), true);
81  mc.addParameter("restricted", Boolean.FALSE, true);
82  mc.addParameter("template", "summary", true);
83  commands.add(mc);
84 
85  // workload
86  mc = new MacroCommand("workload");
87  mc.addParameter("context", "", false);
88  mc.addParameter("count", Integer.valueOf(10), true);
89  mc.addParameter("template", "summary", true);
90  commands.add(mc);
91 
92  // knowledge base
93  mc = new MacroCommand("kb");
94  mc.addParameter("context", "", false);
95  mc.addParameter("count", Integer.valueOf(10), true);
96  mc.addParameter("template", "summary", true);
97  commands.add(mc);
98  }
99 
100  @Override
101  public ContentRenderer loadCommand(MacroCommand macroCommand, IContact contact, String idContext) {
102  if(macroCommand.itsMe("dossiers(") || macroCommand.itsMe("projects(")) {
103  StringWriter sw = new StringWriter();
106  sw, contact, true,
107  macroCommand.getParameterValue(String.class, "context"));
108  if(macroCommand.getParameterValue(String.class, "status").equals("onwork")) {
109  di.setDossierStatus(Arrays.asList("DOSSIER_OPENED,DOSSIER_FROZEN".split(",")));
110  } else if(macroCommand.getParameterValue(String.class, "status").equals("closed")) {
111  di.setDossierStatus(Arrays.asList("DOSSIER_CLOSED".split(",")));
112  }
113  if(macroCommand.itsMe("projects(")) {
114  di.setDossierTypes(Arrays.asList("TYPE_PROJECT"));
115  }
116  di.setAllowedCategories(macroCommand.getParameterValue(String.class, "categoryIds"));
117  di.setDossierId(macroCommand.getParameterValue(Long.class, "dossierId"));
118  di.setPage(macroCommand.getParameterValue(Integer.class, "count"));
119  di.setAllowAttachments(true);
120  di.setAllowFiles(true);
121  di.setAllowDescriptions(true);
122  di.setAllowInterest(true);
123  di.setAllowVotes(true);
124  di.setAllowComments(true);
125  di.setAllowPolls(true);
126  di.setSummaryTemplate(macroCommand.getParameterValue(String.class, "template"));
127  di.setRestricted(macroCommand.getParameterValue(Boolean.class, "restricted"));
128  di.setDirect(macroCommand.getParameterValue(Boolean.class, "direct"));
129  if(macroCommand.getParameterValue(Boolean.class, "related")) {
130  di.setRelated(contact.getCoworkers());
131  }
132  di.setNavigatorTop(false);
133  di.setNavigatorBottom(false);
134  di.load();
135  return new ContentRenderer(macroCommand, di, sw, (IContentIterator iterator, Writer writer) -> {
136  iterator.render();
137  return writer.toString();
138  });
139  } else if(macroCommand.itsMe("issues(")) {
140  StringWriter sw = new StringWriter();
143  sw, contact, true,
144  macroCommand.getParameterValue(String.class, "context"));
145  if(macroCommand.getParameterValue(String.class, "status").equals("onwork")) {
146  ii.setIssueStatus(Arrays.asList("STATUS_NEW,STATUS_STARTED,STATUS_INCOMPLETE,STATUS_REOPENED,STATUS_REUNION,STATUS_FROZEN,STATUS_RESOLVED,STATUS_VERIFIED".split(",")));
147  } else if(macroCommand.getParameterValue(String.class, "status").equals("closed")) {
148  ii.setIssueStatus(Arrays.asList("STATUS_CLOSED".split(",")));
149  }
150  ii.setCategoryId(macroCommand.getParameterValue(Long.class, "categoryId"));
151  ii.setDossierId(macroCommand.getParameterValue(Long.class, "dossierId"));
152  ii.setPage(macroCommand.getParameterValue(Integer.class, "count"));
153  ii.setAllowAttachments(true);
154  ii.setAllowFiles(true);
155  ii.setAllowDescriptions(true);
156  ii.setAllowInterest(true);
157  ii.setAllowVotes(true);
158  ii.setAllowComments(true);
159  ii.setAllowPolls(false);
160  ii.setRestricted(macroCommand.getParameterValue(Boolean.class, "restricted"));
161  ii.setSummaryTemplate(macroCommand.getParameterValue(String.class, "template"));
162  if(macroCommand.getParameterValue(Boolean.class, "restricted")) {
164  }
165  ii.setNavigatorTop(false);
166  ii.setNavigatorBottom(false);
167  ii.load();
168  return new ContentRenderer(macroCommand, ii, sw, (IContentIterator iterator, Writer writer) -> {
169  iterator.render();
170  return writer.toString();
171  });
172  } else if(macroCommand.itsMe("workload(")) {
173  StringWriter sw = new StringWriter();
176  sw, contact, true,
177  macroCommand.getParameterValue(String.class, "context"));
178  wi.setPage(macroCommand.getParameterValue(Integer.class, "count"));
179  wi.setAllowAttachments(true);
180  wi.setAllowDescriptions(true);
181  wi.setAllowInterest(true);
182  wi.setAllowVotes(true);
183  wi.setAllowComments(true);
184  wi.setAllowPolls(false);
185  wi.setSummaryTemplate(macroCommand.getParameterValue(String.class, "template"));
186  wi.setNavigatorTop(false);
187  wi.setNavigatorBottom(false);
188  wi.load();
189  return new ContentRenderer(macroCommand, wi, sw, (IContentIterator iterator, Writer writer) -> {
190  iterator.render();
191  return writer.toString();
192  });
193  } else if(macroCommand.itsMe("kb(")) {
194  StringWriter sw = new StringWriter();
197  sw, contact, true,
198  macroCommand.getParameterValue(String.class, "context"));
199  wi.setPage(macroCommand.getParameterValue(Integer.class, "count"));
200  wi.setAllowAttachments(true);
201  wi.setAllowDescriptions(true);
202  wi.setAllowInterest(true);
203  wi.setAllowVotes(true);
204  wi.setAllowComments(true);
205  wi.setAllowPolls(false);
206  wi.setSummaryTemplate(macroCommand.getParameterValue(String.class, "template"));
207  wi.setNavigatorTop(false);
208  wi.setNavigatorBottom(false);
209  wi.load();
210  return new ContentRenderer(macroCommand, wi, sw, (IContentIterator iterator, Writer writer) -> {
211  iterator.render();
212  return writer.toString();
213  });
214  }
215  return null;
216  }
217 
218 }
ContentRenderer loadCommand(MacroCommand macroCommand, IContact contact, String idContext)
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)