BrightSide Workbench Full Report + Source Code
DossierContactSet.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.Collection;
22 import java.util.List;
23 import org.turro.string.Strings;
24 import org.turro.action.IMyContact;
25 import org.turro.annotation.MyContact;
26 import org.turro.auth.Authentication;
27 import org.turro.contacts.util.DefaultContact;
28 import org.turro.dossier.db.DossierPU;
29 import org.turro.elephant.context.IConstructor;
30 import org.turro.elephant.db.WhereClause;
31 import org.turro.i18n.I_;
32 import org.turro.jpa.Dao;
33 import org.turro.plugin.contacts.ContactSortedSet;
34 import org.turro.plugin.contacts.IContact;
35 
40 @MyContact
41 public class DossierContactSet implements IMyContact {
42 
43  @Override
44  public Collection<IContact> getMyContacts(IConstructor constructor, String search) {
45  ContactSortedSet css = new ContactSortedSet(I_.api().used());
46  if(!Strings.isBlank(search)) {
48  if(user.isValid()) {
49  Dao dao = new DossierPU();
50  for(String c : (List<String>) dao.getResultList(createCategoryCriteria(user, search))) {
51  DefaultContact dc = new DefaultContact();
52  dc.loadById(c);
53  if(dc.isValid()) {
54  css.add(dc);
55  }
56  }
57  for(String c : (List<String>) dao.getResultList(createDossierCriteria(user, search))) {
58  DefaultContact dc = new DefaultContact();
59  dc.loadById(c);
60  if(dc.isValid()) {
61  css.add(dc);
62  }
63  }
64  for(String c : (List<String>) dao.getResultList(createIssueCriteria(user, search))) {
65  DefaultContact dc = new DefaultContact();
66  dc.loadById(c);
67  if(dc.isValid()) {
68  css.add(dc);
69  }
70  }
71  }
72  }
73  return css;
74  }
75 
76  private WhereClause createCategoryCriteria(IContact user, String search) {
77  WhereClause wc = new WhereClause();
78  wc.addClause("select distinct p.idContact from CategoryParticipant as p");
79  wc.addClause("where exists (");
80  wc.addClause("select p2 from CategoryParticipant as p2 where p2.idContact = :idUser and p2.id = p.id and p2.showParticipants = TRUE");
81  wc.addNamedValue("idUser", user.getId());
82  wc.addClause(")");
83  wc.addLikeFields(new String[] { "p.name" }, search);
84  return wc;
85  }
86 
87  private WhereClause createDossierCriteria(IContact user, String search) {
88  WhereClause wc = new WhereClause();
89  wc.addClause("select distinct p.idContact from Participant as p");
90  wc.addClause("where exists (");
91  wc.addClause("select p2 from Participant as p2 where p2.idContact = :idUser and p2.id = p.id and p2.showParticipants = TRUE");
92  wc.addNamedValue("idUser", user.getId());
93  wc.addClause(")");
94  wc.addLikeFields(new String[] { "p.name" }, search);
95  return wc;
96  }
97 
98  private WhereClause createIssueCriteria(IContact user, String search) {
99  WhereClause wc = new WhereClause();
100  wc.addClause("select distinct p.idContact from IssueParticipant as p");
101  wc.addClause("where exists (");
102  wc.addClause("select p2 from IssueParticipant as p2 where p2.idContact = :idUser and p2.id = p.id");
103  wc.addNamedValue("idUser", user.getId());
104  wc.addClause(")");
105  wc.addLikeFields(new String[] { "p.name" }, search);
106  return wc;
107  }
108 
109 }
110 
Collection< IContact > getMyContacts(IConstructor constructor, String search)
void addLikeFields(String[] fields, String value)
void addNamedValue(String name, Object value)
static I18nApiWrapper api()
Definition: I_.java:65