BrightSide Workbench Full Report + Source Code
DossierSummary.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2016 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.command;
20 
21 import java.util.EnumSet;
22 import java.util.List;
23 import java.util.Set;
24 import org.turro.action.IUserSummary;
25 import org.turro.action.UserSummaries;
26 import org.turro.annotation.UserSummary;
27 import org.turro.auth.Authentication;
28 import org.turro.charts.Data;
29 import org.turro.dossier.db.DossierPU;
30 import org.turro.dossier.dw.DWDossierModel;
31 import org.turro.dossier.dw.DWIssueModel;
32 import org.turro.dossier.dw.DWWebChart;
33 import org.turro.dossier.entity.IssueResolution;
34 import org.turro.dossier.entity.IssueStatus;
35 import org.turro.dossier.entity.IssueType;
36 import org.turro.dossier.kb.PendingRevisionQuery;
37 import org.turro.dossier.www.KnowledgeBaseDashboard;
38 import org.turro.elephant.context.ElephantContext;
39 import org.turro.elephant.context.IConstructor;
40 import org.turro.i18n.I_;
41 import org.turro.jpa.Dao;
42 import org.turro.marker.ElephantMarker;
43 import org.turro.phase.PhaseDefinitions;
44 import org.turro.plugin.contacts.IContact;
45 import org.turro.util.CompareUtil;
46 
51 @UserSummary
52 public class DossierSummary implements IUserSummary, Comparable<IUserSummary> {
53 
54  @Override
55  public String render(IConstructor constructor) {
56  ElephantMarker marker = new ElephantMarker(constructor);
58 
59  if(UserSummaries.isNotZero("dossierCount") ||
60  UserSummaries.isNotZero("issueCount")) {
61  return marker.parse("dossier", "userSummary");
62  }
63 
64  return "";
65  }
66 
67  @Override
68  public boolean isRequired() {
69  return false;
70  }
71 
72  @Override
73  public void init(IConstructor constructor) {
74 
76 
77  /* Dossiers */
78 
79  DWDossierModel dossierModel = (DWDossierModel) UserSummaries.getAttribute("dossierModel");
80 
81  if(dossierModel == null) {
82 
83  dossierModel = new DWDossierModel();
84 
85  UserSummaries.setAttribute("dossierFullCount", dossierModel.getCount());
86  UserSummaries.setAttribute("projectFullCount", dossierModel.getProjectCount());
87  UserSummaries.setAttribute("dossierParticipantsFullCount", dossierModel.getParticipantsCount());
88 
89  if(!contact.isOutsider()) {
90  dossierModel.setIParticipant(contact);
91 
92  UserSummaries.setAttribute("dossierModel", dossierModel);
93  UserSummaries.setAttribute("dossierCount", dossierModel.getCount());
94  UserSummaries.setAttribute("projectCount", dossierModel.getProjectCount());
95  UserSummaries.setAttribute("dossierParticipantsCount", dossierModel.getParticipantsCount());
96  UserSummaries.setAttribute("acceptCount", (Long) pending());
97  UserSummaries.setAttribute("pendingCount", new PendingRevisionQuery().getCount());
98 
99  UserSummaries.setAttribute("dStatusChart", new DWWebChart(constructor) {
100  @Override
101  protected void onCreate(Data data, Object[] pars) {
102  // create link
103  }
104  @Override
105  protected void loadData() {
106  IContact c = ((DWDossierModel) UserSummaries.getAttribute("dossierModel")).getIParticipant();
107  ((DWDossierModel) UserSummaries.getAttribute("dossierModel")).setIParticipant(null);
108  setData(I_.get("Status"),
109  ((DWDossierModel) UserSummaries.getAttribute("dossierModel")).getByStatus());
110  ((DWDossierModel) UserSummaries.getAttribute("dossierModel")).setIParticipant(c);
111  }
112  });
113 
114  UserSummaries.setAttribute("dPhaseChart", new DWWebChart(constructor) {
115  @Override
116  protected void onCreate(Data data, Object[] pars) {
117  // create link
118  }
119  @Override
120  protected void loadData() {
121  IContact c = ((DWDossierModel) UserSummaries.getAttribute("dossierModel")).getIParticipant();
122  ((DWDossierModel) UserSummaries.getAttribute("dossierModel")).setIParticipant(null);
123  List<Object[]> data = ((DWDossierModel) UserSummaries.getAttribute("dossierModel")).getByPhase();
124  for(Object[] obj : data) {
125  obj[0] = PhaseDefinitions.instance().get((int) obj[0]).getName();
126  }
127  setData(I_.get("Phase"), data);
128  ((DWDossierModel) UserSummaries.getAttribute("dossierModel")).setIParticipant(c);
129  }
130  });
131  }
132  }
133 
134  /* Issues */
135 
136  DWIssueModel issueModel = (DWIssueModel) UserSummaries.getAttribute("issueModel");
137 
138  if(issueModel == null) {
139 
140  issueModel = new DWIssueModel();
141 
142  UserSummaries.setAttribute("issueModel", issueModel);
143 
144  UserSummaries.setAttribute("issueFullCount", issueModel.getCount());
145  UserSummaries.setAttribute("issueParticipantsFullCount", issueModel.getParticipantsCount());
146  UserSummaries.setAttribute("issueCommentFullCount", issueModel.getCommentCount());
147 
148  if(!contact.isOutsider()) {
149  issueModel.setIParticipant(contact);
150 
151  UserSummaries.setAttribute("issueCount", issueModel.getCount());
152  UserSummaries.setAttribute("issueParticipantsCount", issueModel.getParticipantsCount());
153  UserSummaries.setAttribute("issueOpenCount", issueModel.getOpenedCount());
154  UserSummaries.setAttribute("issueCommentCount", issueModel.getCommentCount());
155 
156  UserSummaries.setAttribute("typeChart", new DWWebChart(constructor) {
157  @Override
158  protected void onCreate(Data data, Object[] pars) {
160  (Set<IssueType>) EnumSet.of((IssueType) pars[0]), null, null, 0L));
161  }
162  @Override
163  protected void loadData() {
164  IContact c = ((DWIssueModel) UserSummaries.getAttribute("issueModel")).getIParticipant();
165  ((DWIssueModel) UserSummaries.getAttribute("issueModel")).setIParticipant(null);
166  setData(I_.get("Type"),
167  ((DWIssueModel) UserSummaries.getAttribute("issueModel")).getByType());
168  ((DWIssueModel) UserSummaries.getAttribute("issueModel")).setIParticipant(c);
169  }
170  });
171  UserSummaries.setAttribute("statusChart", new DWWebChart(constructor) {
172  @Override
173  protected void onCreate(Data data, Object[] pars) {
175  (Set<IssueStatus>) EnumSet.of((IssueStatus) pars[0]), null, 0L));
176  }
177  @Override
178  protected void loadData() {
179  IContact c = ((DWIssueModel) UserSummaries.getAttribute("issueModel")).getIParticipant();
180  ((DWIssueModel) UserSummaries.getAttribute("issueModel")).setIParticipant(null);
181  setData(I_.get("Status"),
182  ((DWIssueModel) UserSummaries.getAttribute("issueModel")).getByStatus());
183  ((DWIssueModel) UserSummaries.getAttribute("issueModel")).setIParticipant(c);
184  }
185  });
186  UserSummaries.setAttribute("resolutionChart", new DWWebChart(constructor) {
187  @Override
188  protected void onCreate(Data data, Object[] pars) {
190  (Set<IssueResolution>) EnumSet.of((IssueResolution) pars[0]), 0L));
191  }
192  @Override
193  protected void loadData() {
194  IContact c = ((DWIssueModel) UserSummaries.getAttribute("issueModel")).getIParticipant();
195  ((DWIssueModel) UserSummaries.getAttribute("issueModel")).setIParticipant(null);
196  setData(I_.get("Resolution"),
197  ((DWIssueModel) UserSummaries.getAttribute("issueModel")).getByResolution());
198  ((DWIssueModel) UserSummaries.getAttribute("issueModel")).setIParticipant(c);
199  }
200  });
201  }
202 
203  }
204  }
205 
206  private long pending() {
207  Dao dao = new DossierPU();
208  Long count = (Long) dao.getSingleResultOrNull(
209  "select count(a) from ParticipantRequest as a");
210  count += (Long) dao.getSingleResultOrNull(
211  "select count(a) from CategoryRequest as a");
212  return count;
213  }
214 
215  @Override
216  public int getOrder() {
217  return 0;
218  }
219 
220  @Override
221  public int compareTo(IUserSummary o) {
222  int result = CompareUtil.compare(getOrder(), o.getOrder());
223  if(result == 0) {
224  result = CompareUtil.compare(getClass().getName(), o.getClass().getName());
225  }
226  return result;
227  }
228 
229 }
static boolean isNotZero(String attribute)
static void setAttribute(String attribute, Object value)
static Map< String, Object > getAttributes()
static Object getAttribute(String attribute)
void setLink(String link)
Definition: Data.java:41
String render(IConstructor constructor)
void init(IConstructor constructor)
void setIParticipant(IContact contact)
void setIParticipant(IContact contact)
static String createLink(String searchValue, boolean onlyTitle, Set< IssueType > type, Set< IssueStatus > status, Set< IssueResolution > resolution, Long dossierId)
static String get(String msg)
Definition: I_.java:41
Object getSingleResultOrNull(SqlClause sc)
Definition: Dao.java:419
String parse(String rootTmpl, String tmpl)
static PhaseDefinitions instance()
PhaseDefinition get(int index)