BrightSide Workbench Full Report + Source Code
ProjectGrantCriteria.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.grant;
20 
21 import org.turro.elephant.db.WhereClause;
22 
27 public class ProjectGrantCriteria {
28 
29  private String searchValue;
30  private boolean minimis, nominimis;
31  private boolean subvention, loan, combination;
32  private boolean collaboration, individual;
33  private boolean hiring, idi, investment, startUp;
34  private boolean micro, small, medium, big;
35  private boolean active, ended, recurrent;
36 
37  public String getSearchValue() {
38  return searchValue;
39  }
40 
41  public void setSearchValue(String searchValue) {
42  this.searchValue = searchValue;
43  }
44 
45  public void clearMinimis() {
46  this.minimis = false;
47  this.nominimis = false;
48  }
49 
50  public boolean isMinimis() {
51  return minimis;
52  }
53 
54  public void setMinimis(boolean minimis) {
55  this.minimis = minimis;
56  this.nominimis = false;
57  }
58 
59  public boolean isNominimis() {
60  return nominimis;
61  }
62 
63  public void setNominimis(boolean nominimis) {
64  this.nominimis = nominimis;
65  this.minimis = false;
66  }
67 
68  public void clearGrant() {
69  this.subvention = false;
70  this.loan = false;
71  this.combination = false;
72  }
73 
74  public boolean isSubvention() {
75  return subvention;
76  }
77 
78  public void setSubvention(boolean subvention) {
79  this.subvention = subvention;
80  this.loan = false;
81  this.combination = false;
82  }
83 
84  public boolean isLoan() {
85  return loan;
86  }
87 
88  public void setLoan(boolean loan) {
89  this.loan = loan;
90  this.subvention = false;
91  this.combination = false;
92  }
93 
94  public boolean isCombination() {
95  return combination;
96  }
97 
98  public void setCombination(boolean combination) {
99  this.combination = combination;
100  this.subvention = false;
101  this.loan = false;
102  }
103 
104  public void clearCollaboration() {
105  this.collaboration = false;
106  this.individual = false;
107  }
108 
109  public boolean isCollaboration() {
110  return collaboration;
111  }
112 
113  public void setCollaboration(boolean collaboration) {
114  this.collaboration = collaboration;
115  this.individual = false;
116  }
117 
118  public boolean isIndividual() {
119  return individual;
120  }
121 
122  public void setIndividual(boolean individual) {
123  this.individual = individual;
124  this.collaboration = false;
125  }
126 
127  public void clearType() {
128  this.hiring = false;
129  this.idi = false;
130  this.investment = false;
131  this.startUp = false;
132  }
133 
134  public boolean isHiring() {
135  return hiring;
136  }
137 
138  public void setHiring(boolean hiring) {
139  this.hiring = hiring;
140  }
141 
142  public boolean isIdi() {
143  return idi;
144  }
145 
146  public void setIdi(boolean idi) {
147  this.idi = idi;
148  }
149 
150  public boolean isInvestment() {
151  return investment;
152  }
153 
154  public void setInvestment(boolean investment) {
155  this.investment = investment;
156  }
157 
158  public boolean isStartUp() {
159  return startUp;
160  }
161 
162  public void setStartUp(boolean startUp) {
163  this.startUp = startUp;
164  }
165 
166  public boolean isMicro() {
167  return micro;
168  }
169 
170  public void setMicro(boolean micro) {
171  this.micro = micro;
172  }
173 
174  public boolean isSmall() {
175  return small;
176  }
177 
178  public void setSmall(boolean small) {
179  this.small = small;
180  }
181 
182  public boolean isMedium() {
183  return medium;
184  }
185 
186  public void setMedium(boolean medium) {
187  this.medium = medium;
188  }
189 
190  public boolean isBig() {
191  return big;
192  }
193 
194  public void setBig(boolean big) {
195  this.big = big;
196  }
197 
198  public void clearDeadline() {
199  this.active = false;
200  this.ended = false;
201  this.recurrent = false;
202  }
203 
204  public boolean isActive() {
205  return active;
206  }
207 
208  public void setActive(boolean active) {
209  this.active = active;
210  this.ended = false;
211  this.recurrent = false;
212  }
213 
214  public boolean isEnded() {
215  return ended;
216  }
217 
218  public void setEnded(boolean ended) {
219  this.ended = ended;
220  this.active = false;
221  this.recurrent = false;
222  }
223 
224  public boolean isRecurrent() {
225  return recurrent;
226  }
227 
228  public void setRecurrent(boolean recurrent) {
229  this.recurrent = recurrent;
230  this.active = false;
231  this.ended = false;
232  }
233 
234  public WhereClause create() {
235  WhereClause wc = new WhereClause();
236  wc.addClause("select distinct g from ProjectGrant g");
237  addCriteria(wc);
238  return wc;
239  }
240 
242  WhereClause wc = new WhereClause();
243  wc.addClause("select count(distinct g) from ProjectGrant g");
244  addCriteria(wc);
245  return wc;
246  }
247 
249  WhereClause wc = new WhereClause();
250  wc.addClause("select distinct g from AxProjectGrant g");
251  addCriteriaAx(wc);
252  return wc;
253  }
254 
256  WhereClause wc = new WhereClause();
257  wc.addClause("select count(distinct g) from AxProjectGrant g");
258  addCriteriaAx(wc);
259  return wc;
260  }
261 
262  private void addCriteria(WhereClause wc) {
263  wc.addClause("where 1=1");
264  wc.addLikeFields(new String[] { "g.title", "g.goal.text", "g.beneficiaries.text",
265  "g.elegible.text", "g.features.text" }, searchValue);
266  if(minimis) {
267  wc.addClause("and g.minimis = TRUE");
268  }
269  if(nominimis) {
270  wc.addClause("and g.minimis = FALSE");
271  }
272  if(combination) {
273  wc.addClause("and subvention = TRUE");
274  wc.addClause("and loan = TRUE");
275  }
276  if(subvention) {
277  wc.addClause("and subvention = TRUE");
278  wc.addClause("and loan = FALSE");
279  }
280  if(loan) {
281  wc.addClause("and loan = TRUE");
282  wc.addClause("and subvention = FALSE");
283  }
284  if(collaboration) {
285  wc.addClause("and g.collaboration = TRUE");
286  }
287  if(individual) {
288  wc.addClause("and g.collaboration = FALSE");
289  }
290  if(hiring) {
291  wc.addClause("and g.matchCriteria.hiring = TRUE");
292  }
293  if(idi) {
294  wc.addClause("and g.matchCriteria.idi = TRUE");
295  }
296  if(investment) {
297  wc.addClause("and g.matchCriteria.investment = TRUE");
298  }
299  if(startUp) {
300  wc.addClause("and g.matchCriteria.startUp = TRUE");
301  }
302  if(micro | small | medium | big) {
303  String sep = "";
304  wc.addClause("and (");
305  if(micro) {
306  wc.addClause(sep + "g.micro = TRUE");
307  sep = "or ";
308  }
309  if(small) {
310  wc.addClause(sep + "g.small = TRUE");
311  sep = "or ";
312  }
313  if(medium) {
314  wc.addClause(sep + "g.medium = TRUE");
315  sep = "or ";
316  }
317  if(big) {
318  wc.addClause(sep + "g.big = TRUE");
319  sep = "or ";
320  }
321  wc.addClause(")");
322  }
323  if(active) {
324  wc.addClause("and (g.endDate is null or g.endDate > now())");
325  }
326  if(ended) {
327  wc.addClause("and g.endDate < now()");
328  }
329  if(recurrent) {
330  wc.addClause("and g.recurrent = TRUE");
331  }
332  }
333 
334  private void addCriteriaAx(WhereClause wc) {
335  wc.addClause("where 1=1");
336  wc.addLikeFields(new String[] { "g.goal.text", "g.beneficiaries.text",
337  "g.elegible.text", "g.features.text" }, searchValue);
338  if(minimis) {
339  wc.addClause("and g.minimis = TRUE");
340  }
341  if(nominimis) {
342  wc.addClause("and g.minimis = FALSE");
343  }
344  if(combination) {
345  wc.addClause("and subvention = TRUE");
346  wc.addClause("and loan = TRUE");
347  }
348  if(subvention) {
349  wc.addClause("and subvention = TRUE");
350  wc.addClause("and loan = FALSE");
351  }
352  if(loan) {
353  wc.addClause("and loan = TRUE");
354  wc.addClause("and subvention = FALSE");
355  }
356  if(collaboration) {
357  wc.addClause("and g.collaboration = TRUE");
358  }
359  if(individual) {
360  wc.addClause("and g.collaboration = FALSE");
361  }
362  if(hiring) {
363  wc.addClause("and g.hiring = TRUE");
364  }
365  if(idi) {
366  wc.addClause("and g.idi = TRUE");
367  }
368  if(investment) {
369  wc.addClause("and g.investment = TRUE");
370  }
371  if(startUp) {
372  wc.addClause("and g.startUp = TRUE");
373  }
374  if(micro | small | medium | big) {
375  String sep = "";
376  wc.addClause("and (");
377  if(micro) {
378  wc.addClause(sep + "g.micro = TRUE");
379  sep = "or ";
380  }
381  if(small) {
382  wc.addClause(sep + "g.small = TRUE");
383  sep = "or ";
384  }
385  if(medium) {
386  wc.addClause(sep + "g.medium = TRUE");
387  sep = "or ";
388  }
389  if(big) {
390  wc.addClause(sep + "g.big = TRUE");
391  sep = "or ";
392  }
393  wc.addClause(")");
394  }
395  if(active) {
396  wc.addClause("and (g.endDate is null or g.endDate > now())");
397  }
398  if(ended) {
399  wc.addClause("and g.endDate < now()");
400  }
401  if(recurrent) {
402  wc.addClause("and g.recurrent = TRUE");
403  }
404  }
405 
406 }
void addLikeFields(String[] fields, String value)