BrightSide Workbench Full Report + Source Code
IssueCombobox.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.issue;
19 
20 import java.util.LinkedList;
21 import org.turro.string.Strings;
22 import org.turro.dossier.db.DossierPU;
23 import org.turro.dossier.entity.Issue;
24 import org.turro.elephant.context.Application;
25 import org.turro.elephant.db.WhereClause;
26 import org.turro.jpa.Dao;
27 import org.turro.util.Chars;
28 import org.turro.zkoss.input.GenericCombobox;
29 
34 @Deprecated
35 public class IssueCombobox extends GenericCombobox<Issue> {
36 
37  @Override
38  public void populateList(String value, LinkedList list, int nRows) {
39  boolean all = Application.getApplication().isInRole("issue:all");
40  Dao dao = new DossierPU();
41  long id = getIdFromText(value);
42  WhereClause wc = new WhereClause();
43  wc.addClause("select distinct issue from Issue as issue");
44  if(id > 0) {
45  wc.addClause("where issue.id = :id");
46  wc.addNamedValue("id", id);
47  } else {
48  wc.addClause("where 1=1");
49  if(!Strings.isBlank(value)) {
50  wc.addClause("and (");
51  wc.setPrefix("");
52  wc.addLikeFields(new String[] {"issue.description"}, getNameFromText(value));
53  wc.setPrefix("or");
54  wc.addLikeFields(new String[] {"issue.dossier.description"}, getDossierFromText(value));
55  wc.setPrefix(null);
56  wc.addClause(")");
57  }
58  wc.addClause("order by issue.description");
59  }
60  for(Object o : dao.getResultList(wc, nRows)) {
61  if(all || new IssueWrapper((Issue) (o)).isFullParticipant()) {
62  list.add((Issue) o);
63  }
64  }
65  }
66 
67  @Override
68  public String getTextFromObject(Issue value) {
69  return value.getDescription() +
70  (value.getDossier() != null ?
71  Chars.forward().spaced() + value.getDossier().getDescription() :
72  "");
73  }
74 
75  public String getNameFromText(String text) {
76  String[] s = text.split(Chars.forward().regexp().spaced().toString());
77  if(s.length == 2) {
78  // name - dossier
79  return s[0];
80  }
81  return text;
82  }
83 
84  public String getDossierFromText(String text) {
85  String[] s = text.split(Chars.forward().regexp().spaced().toString());
86  if(s.length == 2) {
87  // name - dossier
88  return s[1];
89  }
90  return getNameFromText(text);
91  }
92 
93  public long getIdFromText(String text) {
94  long id = 0;
95  try {
96  id = Long.valueOf(text);
97  } catch(Exception ex) {}
98  return id;
99  }
100 
101 }
102 
void populateList(String value, LinkedList list, int nRows)
void addLikeFields(String[] fields, String value)
void addNamedValue(String name, Object value)