1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.jdbc; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.database.platform.DatabasePlatform; |
20 | |
import org.kuali.rice.core.jdbc.criteria.Criteria; |
21 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
22 | |
import org.kuali.rice.core.util.RiceConstants; |
23 | |
import org.kuali.rice.kew.docsearch.SearchableAttribute; |
24 | |
import org.kuali.rice.kns.service.DateTimeService; |
25 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
26 | |
import org.kuali.rice.kns.util.*; |
27 | |
import org.kuali.rice.kns.web.format.BooleanFormatter; |
28 | |
|
29 | |
import java.math.BigDecimal; |
30 | |
import java.sql.Date; |
31 | |
import java.sql.Timestamp; |
32 | |
import java.text.ParseException; |
33 | |
import java.text.SimpleDateFormat; |
34 | |
import java.util.ArrayList; |
35 | |
import java.util.Arrays; |
36 | |
import java.util.List; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class SqlBuilder { |
45 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SqlBuilder.class); |
46 | |
|
47 | |
private DateTimeService dateTimeService; |
48 | |
private DatabasePlatform dbPlatform; |
49 | |
|
50 | |
public Criteria createCriteria(String columnName, String searchValue, String tableName, String tableAlias, Class propertyType) { |
51 | 0 | return createCriteria(columnName, searchValue, tableName, tableAlias, propertyType, false, true); |
52 | |
} |
53 | |
|
54 | |
public Criteria createCriteria(String columnName, String searchValue, String tableName, String tableAlias, Class propertyType, boolean caseInsensitive, boolean allowWildcards) { |
55 | |
|
56 | 0 | if (propertyType == null) { |
57 | 0 | return null; |
58 | |
} |
59 | |
|
60 | 0 | Criteria criteria = new Criteria(tableName, tableAlias); |
61 | 0 | criteria.setDbPlatform(this.getDbPlatform()); |
62 | |
|
63 | |
|
64 | 0 | addCriteria(columnName, searchValue, propertyType, caseInsensitive, allowWildcards, criteria); |
65 | 0 | return criteria; |
66 | |
} |
67 | |
|
68 | |
public void andCriteria(String columnName, String searchValue, String tableName, String tableAlias, Class propertyType, boolean caseInsensitive, boolean allowWildcards, Criteria addToThisCriteria) { |
69 | 0 | Criteria crit = createCriteria(columnName,searchValue, tableName, tableAlias, propertyType, caseInsensitive, allowWildcards); |
70 | |
|
71 | 0 | addToThisCriteria.and(crit); |
72 | 0 | } |
73 | |
public void andCriteria(Criteria addToThisCriteria, Criteria newCriteria) { |
74 | 0 | addToThisCriteria.and(newCriteria); |
75 | 0 | } |
76 | |
public void orCriteria(String columnName, String searchValue, String tableName, String tableAlias, Class propertyType, boolean caseInsensitive, boolean allowWildcards, Criteria addToThisCriteria) { |
77 | 0 | Criteria crit = createCriteria(columnName, searchValue,tableName, tableAlias, propertyType, caseInsensitive, allowWildcards); |
78 | |
|
79 | 0 | addToThisCriteria.or(crit); |
80 | 0 | } |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
public void addCriteria(String propertyName, String propertyValue, Class propertyType, boolean caseInsensitive, boolean allowWildcards, Criteria criteria) { |
129 | |
|
130 | 0 | if(TypeUtils.isJoinClass(propertyType)){ |
131 | 0 | String temp = ObjectUtils.clean(propertyValue); |
132 | 0 | criteria.eq(propertyName, temp, propertyType); |
133 | 0 | return; |
134 | |
} |
135 | |
|
136 | 0 | if (StringUtils.contains(propertyValue, KNSConstants.OR_LOGICAL_OPERATOR)) { |
137 | 0 | addOrCriteria(propertyName, propertyValue, propertyType, caseInsensitive, criteria, allowWildcards); |
138 | 0 | return; |
139 | |
} |
140 | |
|
141 | 0 | if ( StringUtils.contains(propertyValue, KNSConstants.AND_LOGICAL_OPERATOR)) { |
142 | 0 | addAndCriteria(propertyName, propertyValue, propertyType, caseInsensitive, criteria, allowWildcards); |
143 | 0 | return; |
144 | |
} |
145 | |
|
146 | 0 | if (TypeUtils.isStringClass(propertyType)) { |
147 | 0 | if (StringUtils.contains(propertyValue, |
148 | |
KNSConstants.NOT_LOGICAL_OPERATOR)) { |
149 | 0 | addNotCriteria(propertyName, propertyValue, propertyType, |
150 | |
caseInsensitive, criteria, allowWildcards); |
151 | 0 | } else if (propertyValue != null && ( |
152 | |
StringUtils.contains(propertyValue, KNSConstants.BETWEEN_OPERATOR) |
153 | |
|| propertyValue.startsWith(">") |
154 | |
|| propertyValue.startsWith("<") ) ) { |
155 | 0 | addStringRangeCriteria(propertyName, propertyValue, criteria, propertyType, caseInsensitive, allowWildcards); |
156 | |
} else { |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | 0 | if (caseInsensitive) { |
163 | |
|
164 | 0 | propertyName = getDbPlatform().getUpperCaseFunction() + "(__JPA_ALIAS__." + propertyName + ")"; |
165 | |
|
166 | 0 | propertyValue = propertyValue.toUpperCase(); |
167 | |
} |
168 | 0 | criteria.like(propertyName, propertyValue,propertyType, allowWildcards); |
169 | |
} |
170 | 0 | } else if (TypeUtils.isIntegralClass(propertyType) || TypeUtils.isDecimalClass(propertyType)) { |
171 | 0 | addNumericRangeCriteria(propertyName, propertyValue, criteria, propertyType); |
172 | 0 | } else if (TypeUtils.isTemporalClass(propertyType)) { |
173 | 0 | addDateRangeCriteria(propertyName, propertyValue, criteria, propertyType); |
174 | 0 | } else if (TypeUtils.isBooleanClass(propertyType)) { |
175 | 0 | String temp = ObjectUtils.clean(propertyValue); |
176 | 0 | criteria.eq(propertyName, new BooleanFormatter().convertFromPresentationFormat(temp), propertyType); |
177 | 0 | } else { |
178 | 0 | LOG.error("not adding criterion for: " + propertyName + "," + propertyType + "," + propertyValue); |
179 | |
} |
180 | 0 | } |
181 | |
|
182 | |
private void addOrCriteria(String propertyName, String propertyValue, Class propertyType, boolean caseInsensitive, Criteria criteria, boolean allowWildcards) { |
183 | 0 | addLogicalOperatorCriteria(propertyName, propertyValue, propertyType, caseInsensitive, criteria, KNSConstants.OR_LOGICAL_OPERATOR, allowWildcards); |
184 | 0 | } |
185 | |
|
186 | |
private void addAndCriteria(String propertyName, String propertyValue, Class propertyType, boolean caseInsensitive, Criteria criteria, boolean allowWildcards) { |
187 | 0 | addLogicalOperatorCriteria(propertyName, propertyValue, propertyType, caseInsensitive, criteria, KNSConstants.AND_LOGICAL_OPERATOR, allowWildcards); |
188 | 0 | } |
189 | |
|
190 | |
private void addNotCriteria(String propertyName, String propertyValue, Class propertyType, boolean caseInsensitive, Criteria criteria, boolean allowWildcards) { |
191 | 0 | String[] splitPropVal = StringUtils.split(propertyValue, KNSConstants.NOT_LOGICAL_OPERATOR); |
192 | |
|
193 | 0 | int strLength = splitPropVal.length; |
194 | |
|
195 | 0 | if (strLength > 1) { |
196 | 0 | String expandedNot = "!" + StringUtils.join(splitPropVal, KNSConstants.AND_LOGICAL_OPERATOR + KNSConstants.NOT_LOGICAL_OPERATOR); |
197 | |
|
198 | 0 | addCriteria(propertyName, expandedNot, propertyType, caseInsensitive, allowWildcards, criteria); |
199 | 0 | } else { |
200 | |
|
201 | 0 | criteria.notLike(propertyName, splitPropVal[0], propertyType, allowWildcards); |
202 | |
} |
203 | 0 | } |
204 | |
|
205 | |
private void addLogicalOperatorCriteria(String propertyName, String propertyValue, Class propertyType, boolean caseInsensitive, Criteria criteria, String splitValue, boolean allowWildcards) { |
206 | 0 | String[] splitPropVal = StringUtils.split(propertyValue, splitValue); |
207 | |
|
208 | 0 | Criteria subCriteria = new Criteria("N/A"); |
209 | 0 | for (int i = 0; i < splitPropVal.length; i++) { |
210 | 0 | Criteria predicate = new Criteria("N/A", criteria.getAlias()); |
211 | |
|
212 | 0 | addCriteria(propertyName, splitPropVal[i], propertyType, caseInsensitive, allowWildcards, predicate); |
213 | 0 | if (splitValue == KNSConstants.OR_LOGICAL_OPERATOR) { |
214 | 0 | subCriteria.or(predicate); |
215 | |
} |
216 | 0 | if (splitValue == KNSConstants.AND_LOGICAL_OPERATOR) { |
217 | 0 | subCriteria.and(predicate); |
218 | |
} |
219 | |
} |
220 | |
|
221 | 0 | criteria.and(subCriteria); |
222 | 0 | } |
223 | |
|
224 | |
private Timestamp parseDate(String dateString) { |
225 | 0 | dateString = dateString.trim(); |
226 | |
try { |
227 | 0 | Timestamp dt = this.getDateTimeService().convertToSqlTimestamp(dateString); |
228 | 0 | return dt; |
229 | 0 | } catch (ParseException ex) { |
230 | 0 | return null; |
231 | |
} |
232 | |
} |
233 | |
public boolean isValidDate(String dateString){ |
234 | 0 | dateString = dateString.trim(); |
235 | |
try { |
236 | 0 | int oldErrorCount = GlobalVariables.getMessageMap().getErrorCount(); |
237 | 0 | this.createCriteria("date", dateString, "validation", "test", Date.class); |
238 | |
|
239 | 0 | return (GlobalVariables.getMessageMap().getErrorCount() <= oldErrorCount); |
240 | 0 | } catch (Exception ex) { |
241 | 0 | return false; |
242 | |
} |
243 | |
} |
244 | |
|
245 | |
public static String cleanDate(String string) { |
246 | 0 | for (int i = 0; i < KNSConstants.RANGE_CHARACTERS.length; i++) { |
247 | 0 | string = StringUtils.replace(string, KNSConstants.RANGE_CHARACTERS[i], KNSConstants.EMPTY_STRING); |
248 | |
} |
249 | 0 | return string; |
250 | |
} |
251 | |
|
252 | |
public static boolean containsRangeCharacters(String string){ |
253 | 0 | boolean bRet = false; |
254 | 0 | for (int i = 0; i < KNSConstants.RANGE_CHARACTERS.length; i++) { |
255 | 0 | if(StringUtils.contains(string, KNSConstants.RANGE_CHARACTERS[i])){ |
256 | 0 | bRet = true; |
257 | |
} |
258 | |
} |
259 | 0 | return bRet; |
260 | |
} |
261 | |
|
262 | |
private void addDateRangeCriteria(String propertyName, String propertyValue, Criteria criteria, Class propertyType) { |
263 | |
|
264 | 0 | if (StringUtils.contains(propertyValue, KNSConstants.BETWEEN_OPERATOR)) { |
265 | 0 | String[] rangeValues = propertyValue.split("\\.\\."); |
266 | 0 | criteria.between(propertyName, parseDate(cleanDate(rangeValues[0])), parseDate(cleanUpperBound(cleanDate(rangeValues[1]))), propertyType); |
267 | 0 | } else if (propertyValue.startsWith(">=")) { |
268 | 0 | criteria.gte(propertyName, parseDate(cleanDate(propertyValue)), propertyType); |
269 | 0 | } else if (propertyValue.startsWith("<=")) { |
270 | 0 | criteria.lte(propertyName, parseDate(cleanUpperBound(cleanDate(propertyValue))),propertyType); |
271 | 0 | } else if (propertyValue.startsWith(">")) { |
272 | |
|
273 | |
|
274 | 0 | criteria.gt(propertyName, parseDate(cleanUpperBound(cleanDate(propertyValue))), propertyType); |
275 | 0 | } else if (propertyValue.startsWith("<")) { |
276 | 0 | criteria.lt(propertyName, parseDate(cleanDate(propertyValue)), propertyType); |
277 | |
} else { |
278 | 0 | String sDate = convertSimpleDateToDateRange(cleanDate(propertyValue)); |
279 | 0 | if(sDate.contains(KNSConstants.BETWEEN_OPERATOR)){ |
280 | 0 | addDateRangeCriteria(propertyName, sDate, criteria, propertyType); |
281 | |
}else{ |
282 | 0 | criteria.eq(propertyName, parseDate(sDate), propertyType); |
283 | |
} |
284 | |
} |
285 | 0 | } |
286 | |
|
287 | |
public static boolean isValidNumber(String value){ |
288 | |
try{ |
289 | 0 | BigDecimal bd = stringToBigDecimal(value); |
290 | 0 | return true; |
291 | 0 | }catch(Exception ex){ |
292 | 0 | return false; |
293 | |
} |
294 | |
} |
295 | |
|
296 | |
public static String cleanNumericOfValidOperators(String string){ |
297 | 0 | for (int i = 0; i < KNSConstants.RANGE_CHARACTERS.length; i++) { |
298 | 0 | string = StringUtils.replace(string, KNSConstants.RANGE_CHARACTERS[i], KNSConstants.EMPTY_STRING); |
299 | |
} |
300 | 0 | string = StringUtils.replace(string, KNSConstants.OR_LOGICAL_OPERATOR, KNSConstants.EMPTY_STRING); |
301 | 0 | string = StringUtils.replace(string, KNSConstants.AND_LOGICAL_OPERATOR, KNSConstants.EMPTY_STRING); |
302 | 0 | string = StringUtils.replace(string, KNSConstants.NOT_LOGICAL_OPERATOR, KNSConstants.EMPTY_STRING); |
303 | |
|
304 | 0 | return string; |
305 | |
} |
306 | |
|
307 | |
public static String cleanNumeric(String value){ |
308 | 0 | String cleanedValue = value.replaceAll("[^-0-9.]", ""); |
309 | |
|
310 | 0 | if (cleanedValue.lastIndexOf('-') > 0) { |
311 | 0 | if (cleanedValue.charAt(0) == '-') { |
312 | 0 | cleanedValue = "-" + cleanedValue.replaceAll("-", ""); |
313 | |
} else { |
314 | 0 | cleanedValue = cleanedValue.replaceAll("-", ""); |
315 | |
} |
316 | |
} |
317 | |
|
318 | 0 | int decimalLoc = cleanedValue.lastIndexOf('.'); |
319 | 0 | if (cleanedValue.indexOf('.') != decimalLoc) { |
320 | 0 | cleanedValue = cleanedValue.substring(0, decimalLoc).replaceAll("\\.", "") + cleanedValue.substring(decimalLoc); |
321 | |
} |
322 | 0 | return cleanedValue; |
323 | |
} |
324 | |
|
325 | |
public static BigDecimal stringToBigDecimal(String value) { |
326 | |
|
327 | |
|
328 | 0 | return new BigDecimal(cleanNumeric(value)); |
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | |
} |
335 | |
|
336 | |
private void addNumericRangeCriteria(String propertyName, String propertyValue, Criteria criteria, Class propertyType) { |
337 | |
|
338 | 0 | if (StringUtils.contains(propertyValue, KNSConstants.BETWEEN_OPERATOR)) { |
339 | 0 | String[] rangeValues = propertyValue.split("\\.\\."); |
340 | 0 | criteria.between(propertyName, stringToBigDecimal(rangeValues[0]), stringToBigDecimal(rangeValues[1]), propertyType); |
341 | 0 | } else if (propertyValue.startsWith(">=")) { |
342 | 0 | criteria.gte(propertyName, stringToBigDecimal(propertyValue), propertyType); |
343 | 0 | } else if (propertyValue.startsWith("<=")) { |
344 | 0 | criteria.lte(propertyName, stringToBigDecimal(propertyValue), propertyType); |
345 | 0 | } else if (propertyValue.startsWith(">")) { |
346 | 0 | criteria.gt(propertyName, stringToBigDecimal(propertyValue), propertyType); |
347 | 0 | } else if (propertyValue.startsWith("<")) { |
348 | 0 | criteria.lt(propertyName, stringToBigDecimal(propertyValue), propertyType); |
349 | |
} else { |
350 | 0 | criteria.eq(propertyName, stringToBigDecimal(propertyValue), propertyType); |
351 | |
} |
352 | 0 | } |
353 | |
|
354 | |
private void addStringRangeCriteria(String propertyName, String propertyValue, Criteria criteria, Class propertyType, boolean caseInsensitive, boolean allowWildcards) { |
355 | |
|
356 | 0 | if (StringUtils.contains(propertyValue, KNSConstants.BETWEEN_OPERATOR)) { |
357 | 0 | String[] rangeValues = propertyValue.split("\\.\\."); |
358 | 0 | propertyName = this.getCaseAndLiteralPropertyName(propertyName, caseInsensitive); |
359 | 0 | String val1 = this.getCaseAndLiteralPropertyValue(rangeValues[0], caseInsensitive, allowWildcards); |
360 | 0 | String val2 = this.getCaseAndLiteralPropertyValue(rangeValues[1], caseInsensitive, allowWildcards); |
361 | 0 | criteria.between(propertyName, val1, val2, propertyType); |
362 | 0 | } else{ |
363 | 0 | propertyName = this.getCaseAndLiteralPropertyName(propertyName, caseInsensitive); |
364 | 0 | String value = this.getCaseAndLiteralPropertyValue(ObjectUtils.clean(propertyValue), caseInsensitive, allowWildcards); |
365 | |
|
366 | 0 | if (propertyValue.startsWith(">=")) { |
367 | 0 | criteria.gte(propertyName, value, propertyType); |
368 | 0 | } else if (propertyValue.startsWith("<=")) { |
369 | 0 | criteria.lte(propertyName, value, propertyType); |
370 | 0 | } else if (propertyValue.startsWith(">")) { |
371 | 0 | criteria.gt(propertyName, value, propertyType); |
372 | 0 | } else if (propertyValue.startsWith("<")) { |
373 | 0 | criteria.lt(propertyName, value, propertyType); |
374 | |
} |
375 | |
} |
376 | 0 | } |
377 | |
|
378 | |
private String getCaseAndLiteralPropertyName(String propertyName, boolean caseInsensitive){ |
379 | |
|
380 | |
|
381 | 0 | if (caseInsensitive) { |
382 | |
|
383 | 0 | propertyName = getDbPlatform().getUpperCaseFunction() + "(__JPA_ALIAS__." + propertyName + ")"; |
384 | |
|
385 | |
} |
386 | 0 | return propertyName; |
387 | |
} |
388 | |
private String getCaseAndLiteralPropertyValue(String propertyValue, boolean caseInsensitive, boolean allowWildcards){ |
389 | |
|
390 | |
|
391 | |
|
392 | |
|
393 | |
|
394 | 0 | if (caseInsensitive) { |
395 | |
|
396 | 0 | propertyValue = propertyValue.toUpperCase(); |
397 | |
} |
398 | 0 | return propertyValue; |
399 | |
} |
400 | |
|
401 | |
|
402 | |
protected DateTimeService getDateTimeService(){ |
403 | 0 | if (dateTimeService == null) { |
404 | 0 | dateTimeService = KNSServiceLocator.getDateTimeService(); |
405 | |
} |
406 | 0 | return dateTimeService; |
407 | |
} |
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
|
413 | |
public void setDateTimeService(DateTimeService dateTimeService) { |
414 | 0 | this.dateTimeService = dateTimeService; |
415 | 0 | } |
416 | |
|
417 | |
public DatabasePlatform getDbPlatform() { |
418 | 0 | if (dbPlatform == null) { |
419 | 0 | dbPlatform = (DatabasePlatform) GlobalResourceLoader.getService(RiceConstants.DB_PLATFORM); |
420 | |
} |
421 | 0 | return dbPlatform; |
422 | |
} |
423 | |
|
424 | |
public void setDbPlatform(DatabasePlatform dbPlatform){ |
425 | 0 | this.dbPlatform = dbPlatform; |
426 | 0 | } |
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
|
433 | |
private static String cleanUpperBound(String stringDate){ |
434 | |
try{ |
435 | 0 | java.sql.Timestamp dt = KNSServiceLocator.getDateTimeService().convertToSqlTimestamp(stringDate); |
436 | 0 | SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss"); |
437 | |
|
438 | 0 | if("00:00:00".equals(sdfTime.format(dt)) && !StringUtils.contains(stringDate, "00:00:00") && !StringUtils.contains(stringDate, "12:00 AM")){ |
439 | 0 | stringDate = stringDate + " 23:59:59"; |
440 | |
} |
441 | 0 | } catch (Exception ex){ |
442 | 0 | GlobalVariables.getMessageMap().putError(KNSConstants.DOCUMENT_ERRORS, RiceKeyConstants.ERROR_CUSTOM, new String[] { "Invalid Date Input: " + stringDate }); |
443 | 0 | } |
444 | 0 | return stringDate; |
445 | |
} |
446 | |
|
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
private static String convertSimpleDateToDateRange(String stringDate){ |
458 | |
try{ |
459 | 0 | java.sql.Timestamp dt = KNSServiceLocator.getDateTimeService().convertToSqlTimestamp(stringDate); |
460 | 0 | SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss"); |
461 | |
|
462 | 0 | if("00:00:00".equals(sdfTime.format(dt)) && !StringUtils.contains(stringDate, "00:00:00") && !StringUtils.contains(stringDate, "12:00 AM")){ |
463 | 0 | stringDate = stringDate + " .. " + stringDate + " 23:59:59"; |
464 | |
} |
465 | 0 | } catch (Exception ex){ |
466 | 0 | GlobalVariables.getMessageMap().putError(KNSConstants.DOCUMENT_ERRORS, RiceKeyConstants.ERROR_CUSTOM, new String[] { "Invalid Date Input: " + stringDate }); |
467 | 0 | } |
468 | 0 | return stringDate; |
469 | |
} |
470 | |
|
471 | |
|
472 | |
|
473 | |
|
474 | |
|
475 | |
|
476 | |
|
477 | |
|
478 | |
|
479 | |
public static List<String> getCleanedSearchableValues(String valueEntered, String propertyDataType) { |
480 | 0 | List<String> lRet = null; |
481 | 0 | List<String> lTemp = getSearchableValues(valueEntered); |
482 | 0 | if(lTemp != null && !lTemp.isEmpty()){ |
483 | 0 | lRet = new ArrayList<String>(); |
484 | 0 | for(String val: lTemp){ |
485 | |
|
486 | 0 | if (SearchableAttribute.DATA_TYPE_STRING.equals(propertyDataType)) { |
487 | 0 | lRet.add(ObjectUtils.clean(val)); |
488 | 0 | } else if (SearchableAttribute.DATA_TYPE_FLOAT.equals(propertyDataType) || SearchableAttribute.DATA_TYPE_LONG.equals(propertyDataType)) { |
489 | 0 | lRet.add(SqlBuilder.cleanNumericOfValidOperators(val)); |
490 | 0 | } else if (SearchableAttribute.DATA_TYPE_DATE.equals(propertyDataType)) { |
491 | 0 | lRet.add(SqlBuilder.cleanDate(val)); |
492 | |
} else { |
493 | 0 | lRet.add(ObjectUtils.clean(val)); |
494 | |
} |
495 | |
} |
496 | |
} |
497 | 0 | return lRet; |
498 | |
} |
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
|
505 | |
|
506 | |
|
507 | |
public static List<String> getSearchableValues(String valueEntered) { |
508 | 0 | List<String> lRet = new ArrayList<String>(); |
509 | |
|
510 | 0 | getSearchableValueRecursive(valueEntered, lRet); |
511 | |
|
512 | 0 | return lRet; |
513 | |
} |
514 | |
|
515 | |
protected static void getSearchableValueRecursive(String valueEntered, List lRet) { |
516 | 0 | if(valueEntered == null)return; |
517 | |
|
518 | 0 | valueEntered = valueEntered.trim(); |
519 | |
|
520 | 0 | if(lRet == null){ |
521 | 0 | throw new NullPointerException("The list passed in is by reference and should never be null."); |
522 | |
} |
523 | |
|
524 | 0 | if (StringUtils.contains(valueEntered, KNSConstants.BETWEEN_OPERATOR)) { |
525 | 0 | List<String> l = Arrays.asList(valueEntered.split("\\.\\.")); |
526 | 0 | for(String value : l){ |
527 | 0 | getSearchableValueRecursive(value,lRet); |
528 | |
} |
529 | 0 | return; |
530 | |
} |
531 | 0 | if (StringUtils.contains(valueEntered, KNSConstants.OR_LOGICAL_OPERATOR)) { |
532 | 0 | List<String> l = Arrays.asList(StringUtils.split(valueEntered, KNSConstants.OR_LOGICAL_OPERATOR)); |
533 | 0 | for(String value : l){ |
534 | 0 | getSearchableValueRecursive(value,lRet); |
535 | |
} |
536 | 0 | return; |
537 | |
} |
538 | 0 | if (StringUtils.contains(valueEntered, KNSConstants.AND_LOGICAL_OPERATOR)) { |
539 | |
|
540 | 0 | List<String> l = Arrays.asList(StringUtils.split(valueEntered, KNSConstants.AND_LOGICAL_OPERATOR)); |
541 | 0 | for(String value : l){ |
542 | 0 | getSearchableValueRecursive(value,lRet); |
543 | |
} |
544 | 0 | return; |
545 | |
} |
546 | |
|
547 | |
|
548 | 0 | lRet.add(valueEntered); |
549 | 0 | } |
550 | |
|
551 | |
|
552 | |
} |