BrightSide Workbench Full Report + Source Code
IssueStatusModel.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.zul.dossier;
19 
20 import java.util.List;
21 import org.turro.dossier.db.DossierPU;
22 import org.turro.dossier.entity.Dossier;
23 import org.turro.dossier.entity.IssueParticipantRole;
24 import org.turro.dossier.entity.IssueStatus;
25 import org.turro.elephant.db.WhereClause;
26 import org.turro.i18n.I_;
27 import org.turro.jpa.Dao;
28 import org.zkoss.zul.SimplePieModel;
29 
34 public class IssueStatusModel extends SimplePieModel {
35 
36  private Dossier dossier;
37  private String issueParticipant;
38 
39  public IssueStatusModel() {
40  }
41 
42  public IssueStatusModel(Dossier dossier) {
43  setDossier(dossier);
44  }
45 
46  public IssueStatusModel(Dossier dossier, String issueParticipant) {
47  this.issueParticipant = issueParticipant;
48  setDossier(dossier);
49  }
50 
51  public void setDossier(Dossier dossier) {
52  this.dossier = dossier;
53  readValues();
54  }
55 
56  private void readValues() {
57  Dao dao = new DossierPU();
58  WhereClause wc = new WhereClause();
59  wc.addClause("select issue.status, count(distinct issue.id)");
60  wc.addClause("from Issue as issue");
61  wc.addClause("left outer join issue.participants participant");
62  wc.addClause("where issue.dossier = :dossier");
63  if(issueParticipant != null) {
64  wc.addClause("and participant.idContact = :idContact");
65  wc.addClause("and participant.role = :role");
66  wc.addNamedValue("idContact", issueParticipant);
68  }
69  wc.addClause("group by issue.status");
70  wc.addNamedValue("dossier", dossier);
71  List<Object[]> l = dao.getResultList(wc);
72  for(Object[] result : l) {
73  setValue(I_.byKey(((IssueStatus) result[0]).toString()),
74  (Number) result[1]);
75  }
76  }
77 
78 }
IssueStatusModel(Dossier dossier, String issueParticipant)
void addNamedValue(String name, Object value)