BrightSide Workbench Full Report + Source Code
RegistryResults.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.search;
19 
20 import java.util.Date;
21 import org.turro.contacts.Contact;
22 import org.turro.dossier.db.DossierPU;
23 import org.turro.dossier.entity.Dossier;
24 import org.turro.dossier.entity.ParticipantRole;
25 import org.turro.elephant.db.WhereClause;
26 import org.turro.jpa.Dao;
27 
32 public class RegistryResults {
33 
34  private boolean ckRegistered = false;
35  private Contact subject;
36  private Dossier dossier;
37  private Date fromDate = new Date(new Date().getTime() - (90L * 24L * 60L * 60L * 1000L));
38 
39  public RegistryResults() {
40  }
41 
42  public java.util.List getRegistryList() {
43  Dao dao = new DossierPU();
44  WhereClause wc = new WhereClause();
45  wc.addClause("select distinct comment from IssueComment as comment");
46  wc.addClause("left join comment.issue.dossier.participants participant");
47  wc.addClause("where (comment.expenses <> 0 or comment.hours <> 0 or comment.price <> 0)");
48  addCriteria(wc);
49  wc.addClause("order by comment.modification");
50  return dao.getResultList(wc);
51  }
52 
53  public void addCriteria(WhereClause wc) {
54  if(subject == null && dossier == null) {
55  wc.addClause("and 1=0");
56  return;
57  }
58 
59  wc.addClause("and comment.processed = :processed");
60  wc.addNamedValue("processed", ckRegistered);
61 
62  if(fromDate != null) {
63  wc.addClause("and comment.modification >= :modification");
64  wc.addNamedValue("modification", fromDate);
65  }
66 
67  if(subject != null) {
68  wc.addClause("and (");
69  wc.addClause("participant.idContact = :idContact");
70  wc.addNamedValue("idContact", subject.getId());
71  wc.addClause("and participant.role = :role");
73  wc.addClause(")");
74  } else if(dossier != null) {
75  wc.addClause("and comment.issue.dossier = :dossier");
76  wc.addNamedValue("dossier", dossier);
77  }
78  }
79 
80  public boolean isCkRegistered() {
81  return ckRegistered;
82  }
83 
84  public void setCkRegistered(boolean ckRegistered) {
85  this.ckRegistered = ckRegistered;
86  }
87 
88  public Dossier getDossier() {
89  return dossier;
90  }
91 
92  public void setDossier(Dossier dossier) {
93  this.dossier = dossier;
94  }
95 
96  public Date getFromDate() {
97  return fromDate;
98  }
99 
100  public void setFromDate(Date fromDate) {
101  this.fromDate = fromDate;
102  }
103 
104  public Contact getSubject() {
105  return subject;
106  }
107 
108  public void setSubject(Contact subject) {
109  this.subject = subject;
110  }
111 
112 }
void setCkRegistered(boolean ckRegistered)
void addNamedValue(String name, Object value)