1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.businessobject.lookup;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.vnd.VendorConstants;
20 import org.kuali.ole.vnd.VendorKeyConstants;
21 import org.kuali.ole.vnd.VendorPropertyConstants;
22 import org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl;
23 import org.kuali.rice.krad.bo.BusinessObject;
24 import org.kuali.rice.krad.lookup.LookupUtils;
25 import org.kuali.rice.krad.util.BeanPropertyComparator;
26 import org.kuali.rice.krad.util.GlobalVariables;
27 import org.kuali.rice.krad.util.KRADConstants;
28
29 import java.util.Collections;
30 import java.util.List;
31 import java.util.Map;
32
33
34
35
36
37
38
39
40 public class ThresholdLookupableHelperService extends AbstractLookupableHelperServiceImpl {
41
42 public void validateSearchParameters(Map fieldValues) {
43 super.validateSearchParameters(fieldValues);
44
45 validateVendorNumber(fieldValues);
46 }
47
48
49
50
51
52
53
54
55 protected void validateVendorNumber(Map fieldValues) {
56 String vendorNumber = (String) fieldValues.get(VendorPropertyConstants.VENDOR_NUMBER);
57 if (StringUtils.isNotBlank(vendorNumber)) {
58 int dashPos1 = vendorNumber.indexOf(VendorConstants.DASH);
59 if (dashPos1 > -1) {
60 if (vendorNumber.indexOf(VendorConstants.DASH, dashPos1 + 1) > -1) {
61 GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_NUMBER, VendorKeyConstants.ERROR_VENDOR_LOOKUP_VNDR_NUM_TOO_MANY_DASHES);
62 }
63 if (vendorNumber.matches("\\-*")) {
64 GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_NUMBER, VendorKeyConstants.ERROR_VENDOR_LOOKUP_VNDR_NUM_DASHES_ONLY);
65 }
66 }
67 extractVendorNumberToVendorIds(fieldValues, vendorNumber);
68 }
69 }
70
71
72
73
74
75
76
77
78
79
80
81 protected void extractVendorNumberToVendorIds(Map fieldValues, String vendorNumber) {
82 String vendorHeaderGeneratedIdentifier = null;
83 String vendorDetailAssignedIdentifier = null;
84 int indexOfDash = vendorNumber.indexOf(VendorConstants.DASH);
85 if (indexOfDash < 0) {
86 vendorHeaderGeneratedIdentifier = vendorNumber;
87 } else {
88 vendorHeaderGeneratedIdentifier = vendorNumber.substring(0, indexOfDash);
89 vendorDetailAssignedIdentifier = vendorNumber.substring(indexOfDash + 1, vendorNumber.length());
90 }
91 try {
92 if (StringUtils.isNotEmpty(vendorHeaderGeneratedIdentifier)) {
93 Integer.parseInt(vendorHeaderGeneratedIdentifier);
94 }
95 if (StringUtils.isNotEmpty(vendorDetailAssignedIdentifier)) {
96 Integer.parseInt(vendorDetailAssignedIdentifier);
97 }
98 fieldValues.remove(VendorPropertyConstants.VENDOR_NUMBER);
99 fieldValues.put(VendorPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorHeaderGeneratedIdentifier);
100 fieldValues.put(VendorPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, vendorDetailAssignedIdentifier);
101 } catch (NumberFormatException headerExc) {
102 GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_NUMBER, VendorKeyConstants.ERROR_VENDOR_LOOKUP_VNDR_NUM_NUMERIC_DASH_SEPARATED);
103 }
104 }
105
106
107
108
109
110
111
112
113 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
114 return getSearchResultsHelper(LookupUtils.forceUppercase(getBusinessObjectClass(), fieldValues), false);
115 }
116
117
118
119
120
121
122
123
124
125 public List<? extends BusinessObject> getSearchResultsUnbounded(Map<String, String> fieldValues) {
126 return getSearchResultsHelper(LookupUtils.forceUppercase(getBusinessObjectClass(), fieldValues), true);
127 }
128
129
130
131
132
133
134
135
136
137
138
139 @SuppressWarnings("unchecked")
140 protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded) {
141
142
143 boolean searchUsingOnlyPrimaryKeyValues = getLookupService().allPrimaryKeyValuesPresentAndNotWildcard(getBusinessObjectClass(), fieldValues);
144
145 setBackLocation(fieldValues.get(KRADConstants.BACK_LOCATION));
146 setDocFormKey(fieldValues.get(KRADConstants.DOC_FORM_KEY));
147 setReferencesToRefresh(fieldValues.get(KRADConstants.REFERENCES_TO_REFRESH));
148 List searchResults = (List) getLookupService().findCollectionBySearchHelper(getBusinessObjectClass(), fieldValues, unbounded);
149
150 List defaultSortColumns = getDefaultSortColumns();
151 if (defaultSortColumns.size() > 0) {
152 Collections.sort(searchResults, new BeanPropertyComparator(getDefaultSortColumns(), true));
153 }
154 return searchResults;
155 }
156 }
157