BrightSide Workbench Full Report + Source Code
PendingRevisionQuery.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.kb;
20 
21 import java.util.List;
22 import org.turro.auth.Authentication;
23 import org.turro.dossier.db.DossierPU;
24 import org.turro.elephant.db.WhereClause;
25 import org.turro.jpa.Dao;
26 import org.turro.plugin.contacts.IContact;
27 
32 public class PendingRevisionQuery {
33 
34  private IContact byParticipant = Authentication.getIContact();
35 
37  return byParticipant;
38  }
39 
40  public List getResultList() {
41  Dao dao = new DossierPU();
42  WhereClause wc = createCriteria(false);
43  return dao.getResultList(wc);
44  }
45 
46  public Long getCount() {
47  Dao dao = new DossierPU();
48  WhereClause wc = createCriteria(true);
49  return (Long) dao.getSingleResultOrNull(wc);
50  }
51 
52  private WhereClause createCriteria(boolean count) {
53  WhereClause wc = new WhereClause();
54  if(count) {
55  wc.addClause("select count(ip) from IssueParticipant as ip");
56  } else {
57  wc.addClause("select ip from IssueParticipant as ip");
58  }
59  wc.addClause("where ip.pendingRevision = true");
60 
61  if(byParticipant != null && byParticipant.isValid()) {
62  wc.addClause("and ip.idContact = :idContact");
63  wc.addNamedValue("idContact", byParticipant.getId());
64  } else {
65  wc.addClause("and 1=2");
66  }
67 
68  wc.addClause("order by ip.issue.modification desc");
69 
70  return wc;
71  }
72 
73  public void archive(long archive) {
74  WhereClause wc = new WhereClause();
75  wc.addClause("update IssueParticipant as ip");
76  wc.addClause("set ip.pendingRevision = false");
77  if(byParticipant != null && byParticipant.isValid()) {
78  wc.addClause("where ip.idContact = :idContact");
79  wc.addNamedValue("idContact", byParticipant.getId());
80  wc.addClause("and ip.id = :id");
81  wc.addNamedValue("id", archive);
82  Dao dao = new DossierPU();
83  dao.executeUpdate(wc);
84  }
85  }
86 
87 }
void addNamedValue(String name, Object value)
int executeUpdate(String query)
Definition: Dao.java:463
Object getSingleResultOrNull(SqlClause sc)
Definition: Dao.java:419