1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.demo.uif.lookup;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.util.RiceKeyConstants;
20 import org.kuali.rice.krad.lookup.LookupForm;
21 import org.kuali.rice.krad.lookup.LookupableImpl;
22 import org.kuali.rice.krad.util.GlobalVariables;
23
24 import java.text.NumberFormat;
25 import java.text.ParseException;
26 import java.util.HashSet;
27 import java.util.Map;
28 import java.util.Set;
29
30
31
32
33 public class TravelLookupableImpl extends LookupableImpl {
34
35
36
37
38
39
40 @Override
41 protected boolean validateSearchParameters(LookupForm form, Map<String, String> searchCriteria) {
42 boolean valid = super.validateSearchParameters(form, searchCriteria);
43
44 if (form.getViewPostMetadata() != null && form.getViewPostMetadata().getLookupCriteria() != null) {
45 for (Map.Entry<String, Map<String, Object>> lookupCriteria : form.getViewPostMetadata().getLookupCriteria().entrySet()) {
46 String propertyName = lookupCriteria.getKey();
47
48 validateSearchParameterPositiveValues(form, propertyName, searchCriteria.get(propertyName));
49 }
50 }
51
52 if (GlobalVariables.getMessageMap().hasErrors()) {
53 valid = false;
54 }
55
56 return valid;
57 }
58
59
60
61
62
63
64
65
66 protected void validateSearchParameterPositiveValues(LookupForm form, String propertyName, String searchPropertyValue) {
67 if (StringUtils.isBlank(searchPropertyValue)) {
68 return;
69 }
70
71 NumberFormat format = NumberFormat.getInstance();
72 Number number = null;
73 try {
74 number = format.parse(searchPropertyValue);
75 } catch (ParseException e) {
76 return;
77 }
78
79 if (Math.signum(number.doubleValue()) < 0) {
80 GlobalVariables.getMessageMap().putError(propertyName,
81 RiceKeyConstants.ERROR_NEGATIVES_NOT_ALLOWED_ON_FIELD, getCriteriaLabel(form, propertyName));
82 }
83 }
84 }