1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.vnd.businessobject.lookup;
17
18 import java.sql.Date;
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.vnd.VendorConstants;
27 import org.kuali.ole.vnd.VendorKeyConstants;
28 import org.kuali.ole.vnd.VendorPropertyConstants;
29 import org.kuali.ole.vnd.businessobject.VendorContract;
30 import org.kuali.rice.core.api.datetime.DateTimeService;
31 import org.kuali.rice.core.api.search.SearchOperator;
32 import org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl;
33 import org.kuali.rice.krad.bo.PersistableBusinessObject;
34 import org.kuali.rice.krad.dao.LookupDao;
35 import org.kuali.rice.krad.exception.ValidationException;
36 import org.kuali.rice.krad.util.BeanPropertyComparator;
37 import org.kuali.rice.krad.util.GlobalVariables;
38
39 public class VendorContractLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl {
40 private LookupDao lookupDao;
41 private DateTimeService dateTimeService;
42
43 public void setLookupDao(LookupDao lookupDao) {
44 this.lookupDao = lookupDao;
45 }
46
47 public void setDateTimeService(DateTimeService dateTimeService) {
48 this.dateTimeService = dateTimeService;
49 }
50
51
52
53
54
55
56 @Override
57 public List<PersistableBusinessObject> getSearchResults(Map<String, String> fieldValues) {
58
59 boolean unbounded = false;
60 super.setBackLocation((String) fieldValues.get(OLEConstants.BACK_LOCATION));
61 super.setDocFormKey((String) fieldValues.get(OLEConstants.DOC_FORM_KEY));
62
63 Date now = dateTimeService.getCurrentSqlDate();
64 String nowString = dateTimeService.toDateString(now);
65
66
67 boolean usePrimaryKeyValuesOnly = getLookupService().allPrimaryKeyValuesPresentAndNotWildcard(getBusinessObjectClass(), fieldValues);
68 List<PersistableBusinessObject> searchResults = (List) lookupDao.findCollectionBySearchHelper(getBusinessObjectClass(), fieldValues, unbounded, usePrimaryKeyValuesOnly);
69
70 List<PersistableBusinessObject> finalSearchResults = new ArrayList();
71
72 for (PersistableBusinessObject object : searchResults) {
73 VendorContract vendorContract = (VendorContract) object;
74 if (!vendorContract.getVendorDetail().isVendorDebarred()) {
75 finalSearchResults.add(vendorContract);
76 }
77 }
78
79
80 List<String> defaultSortColumns = getDefaultSortColumns();
81 if (defaultSortColumns.size() > 0) {
82 Collections.sort(finalSearchResults, new BeanPropertyComparator(getDefaultSortColumns(), true));
83 }
84
85 return finalSearchResults;
86 }
87
88
89
90
91
92
93
94
95
96
97 @Override
98 public void validateSearchParameters(Map fieldValues) {
99 super.validateSearchParameters(fieldValues);
100
101 validateVendorNumber(fieldValues);
102
103 if (GlobalVariables.getMessageMap().hasErrors()) {
104 throw new ValidationException("Error(s) in search criteria");
105 }
106 }
107
108
109
110
111
112
113
114
115 private void validateVendorNumber(Map fieldValues) {
116 String vendorNumber = (String) fieldValues.get(VendorPropertyConstants.VENDOR_NUMBER);
117 if (StringUtils.isNotBlank(vendorNumber)) {
118 int dashPos1 = vendorNumber.indexOf(VendorConstants.DASH);
119 if (dashPos1 > -1) {
120 if (vendorNumber.indexOf(VendorConstants.DASH, dashPos1 + 1) > -1) {
121 GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_NUMBER, VendorKeyConstants.ERROR_VENDOR_LOOKUP_VNDR_NUM_TOO_MANY_DASHES);
122 }
123 if (vendorNumber.matches("\\-*")) {
124 GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_NUMBER, VendorKeyConstants.ERROR_VENDOR_LOOKUP_VNDR_NUM_DASHES_ONLY);
125 }
126 }
127 extractVendorNumberToVendorIds(fieldValues, vendorNumber);
128 }
129 }
130
131
132
133
134
135
136
137
138
139
140
141 private void extractVendorNumberToVendorIds(Map fieldValues, String vendorNumber) {
142 String vendorHeaderGeneratedIdentifier = null;
143 String vendorDetailAssignedIdentifier = null;
144 int indexOfDash = vendorNumber.indexOf(VendorConstants.DASH);
145 if (indexOfDash < 0) {
146 vendorHeaderGeneratedIdentifier = vendorNumber;
147 }
148 else {
149 vendorHeaderGeneratedIdentifier = vendorNumber.substring(0, indexOfDash);
150 vendorDetailAssignedIdentifier = vendorNumber.substring(indexOfDash + 1, vendorNumber.length());
151 }
152 try {
153 if (StringUtils.isNotEmpty(vendorHeaderGeneratedIdentifier)) {
154 Integer.parseInt(vendorHeaderGeneratedIdentifier);
155 }
156 if (StringUtils.isNotEmpty(vendorDetailAssignedIdentifier)) {
157 Integer.parseInt(vendorDetailAssignedIdentifier);
158 }
159 fieldValues.remove(VendorPropertyConstants.VENDOR_NUMBER);
160 fieldValues.put(VendorPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorHeaderGeneratedIdentifier);
161 fieldValues.put(VendorPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, vendorDetailAssignedIdentifier);
162 }
163 catch (NumberFormatException headerExc) {
164 GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_NUMBER, VendorKeyConstants.ERROR_VENDOR_LOOKUP_VNDR_NUM_NUMERIC_DASH_SEPARATED);
165 }
166 }
167
168 }