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