View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.fp.businessobject.lookup;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.Collections;
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.kuali.ole.fp.businessobject.DisbursementPayee;
27  import org.kuali.ole.fp.document.service.DisbursementVoucherPaymentReasonService;
28  import org.kuali.ole.sys.OLEConstants;
29  import org.kuali.ole.sys.OLEKeyConstants;
30  import org.kuali.ole.sys.OLEPropertyConstants;
31  import org.kuali.ole.vnd.VendorConstants;
32  import org.kuali.rice.kim.impl.KIMPropertyConstants;
33  import org.kuali.rice.kns.util.KNSGlobalVariables;
34  import org.kuali.rice.kns.util.MessageList;
35  import org.kuali.rice.kns.web.struts.form.LookupForm;
36  import org.kuali.rice.kns.web.ui.ResultRow;
37  import org.kuali.rice.krad.bo.BusinessObject;
38  import org.kuali.rice.krad.exception.ValidationException;
39  import org.kuali.rice.krad.lookup.CollectionIncomplete;
40  import org.kuali.rice.krad.util.BeanPropertyComparator;
41  import org.kuali.rice.krad.util.GlobalVariables;
42  
43  public class DisbursementPayeeLookupableHelperServiceImpl extends AbstractPayeeLookupableHelperServiceImpl  {
44      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementPayeeLookupableHelperServiceImpl.class);
45      private static final int NAME_REQUIRED_FILLED_WITH_WILDCARD = 4;
46  
47      protected DisbursementVoucherPaymentReasonService disbursementVoucherPaymentReasonService;
48  
49      /**
50       * Note: This method is not called by validateSearchParameters anymore.
51       * This method checks if the minimum required fields are filled
52       */
53      @Deprecated
54      public boolean checkMinimumFieldsFilled(Map fieldValues) {
55          if(StringUtils.isBlank((String) fieldValues.get(OLEPropertyConstants.VENDOR_NUMBER)) && StringUtils.isBlank((String) fieldValues.get(KIMPropertyConstants.Person.EMPLOYEE_ID)) && StringUtils.isBlank((String)fieldValues.get(KIMPropertyConstants.Person.FIRST_NAME)) &&
56                  StringUtils.isBlank((String)fieldValues.get(KIMPropertyConstants.Person.LAST_NAME)) && StringUtils.isBlank((String)fieldValues.get(OLEPropertyConstants.VENDOR_NAME))) {
57              final String vendorNumberLabel = this.getAttributeLabel(OLEPropertyConstants.VENDOR_NUMBER);
58              final String vendorNameLabel = this.getAttributeLabel(OLEPropertyConstants.VENDOR_NAME);
59              final String firstNameLabel = this.getAttributeLabel(KIMPropertyConstants.Person.FIRST_NAME);
60              final String lastNameLabel = this.getAttributeLabel(KIMPropertyConstants.Person.LAST_NAME);
61              final String employeeIdLabel = this.getAttributeLabel(KIMPropertyConstants.Person.EMPLOYEE_ID);
62  
63              GlobalVariables.getMessageMap().putError(OLEPropertyConstants.VENDOR_NUMBER, OLEKeyConstants.ERROR_DV_LOOKUP_NEEDS_SOME_FIELD, new String[] {vendorNumberLabel, employeeIdLabel, vendorNameLabel, firstNameLabel, lastNameLabel});
64              return false;
65          }
66          return true;
67      }
68  
69      /**
70       * Note: This method is not called by validateSearchParameters anymore.
71       * This method validates the vendor name usage in lookup
72       */
73      @Deprecated
74      public void validateVendorNameUse(Map fieldValues) {
75          final String vendorName = (String) fieldValues.get(OLEPropertyConstants.VENDOR_NAME);
76          final String vendorNumber = (String) fieldValues.get(OLEPropertyConstants.VENDOR_NUMBER);
77          final String employeeId = (String) fieldValues.get(KIMPropertyConstants.Person.EMPLOYEE_ID);
78  
79              final boolean isVendorInfoEntered = StringUtils.isNotBlank(vendorName) || StringUtils.isNotBlank(vendorNumber);
80              if (isVendorInfoEntered && StringUtils.isNotBlank(employeeId)) {
81                  // only can use the vendor name and vendor number fields or the employee id field, but not both.
82                  String messageKey = OLEKeyConstants.ERROR_DV_VENDOR_EMPLOYEE_CONFUSION;
83                  String vendorNameLabel = this.getAttributeLabel(OLEPropertyConstants.VENDOR_NAME);
84                  String vendorNumberLabel = this.getAttributeLabel(OLEPropertyConstants.VENDOR_NUMBER);
85              GlobalVariables.getMessageMap().putError(KIMPropertyConstants.Person.EMPLOYEE_ID, messageKey, this.getAttributeLabel(KIMPropertyConstants.Person.EMPLOYEE_ID), vendorNameLabel, vendorNumberLabel);
86              }
87  
88              if (StringUtils.isBlank(vendorNumber) && !StringUtils.isBlank(vendorName) && !filledEnough(vendorName)) {
89                  final String vendorNameLabel = this.getAttributeLabel(OLEPropertyConstants.VENDOR_NAME);
90                  GlobalVariables.getMessageMap().putError(OLEPropertyConstants.VENDOR_NAME, OLEKeyConstants.ERROR_DV_NAME_NOT_FILLED_ENOUGH, new String[] {vendorNameLabel, Integer.toString(getNameLengthWithWildcardRequirement())});
91              }
92      }
93  
94      /**
95       * Note: This method is not called by validateSearchParameters anymore.
96       * This method validates the tax criteria
97       */
98      @Deprecated
99      public void validateTaxNumberCriteria(Map fieldValues) {
100         final String employeeId = (String) fieldValues.get(KIMPropertyConstants.Person.EMPLOYEE_ID);
101         final String firstName = (String)fieldValues.get(KIMPropertyConstants.Person.FIRST_NAME);
102         final String lastName = (String)fieldValues.get(KIMPropertyConstants.Person.LAST_NAME);
103         final String vendorTaxNumber = (String)fieldValues.get(OLEPropertyConstants.TAX_NUMBER);
104 
105             // we do not use to use Tax Number field for the lookup on the person...
106             if(StringUtils.isNotBlank(vendorTaxNumber) && StringUtils.isNotBlank(firstName)) {
107                 fieldValues.remove(OLEPropertyConstants.TAX_NUMBER);
108                 String messageKey = OLEKeyConstants.ERROR_DV_LOOKUP_TAX_NUMBER_EMPLOYEE_DETAILS_CONFUSION;
109             GlobalVariables.getMessageMap().putError(KIMPropertyConstants.Person.FIRST_NAME, messageKey, this.getAttributeLabel(OLEPropertyConstants.TAX_NUMBER), this.getAttributeLabel(KIMPropertyConstants.Person.FIRST_NAME));
110             }
111             // if tax number and employee last name entered then send an error message...
112             if(StringUtils.isNotBlank(vendorTaxNumber) && StringUtils.isNotBlank(lastName)) {
113                 fieldValues.remove(OLEPropertyConstants.TAX_NUMBER);
114                 String messageKey = OLEKeyConstants.ERROR_DV_LOOKUP_TAX_NUMBER_EMPLOYEE_DETAILS_CONFUSION;
115             GlobalVariables.getMessageMap().putError(KIMPropertyConstants.Person.LAST_NAME, messageKey, this.getAttributeLabel(OLEPropertyConstants.TAX_NUMBER), this.getAttributeLabel(KIMPropertyConstants.Person.LAST_NAME));
116             }
117             // if tax number and employee id entered then send an error message...
118             if(StringUtils.isNotBlank(vendorTaxNumber) && StringUtils.isNotBlank(employeeId)) {
119                 fieldValues.remove(OLEPropertyConstants.TAX_NUMBER);
120                 String messageKey = OLEKeyConstants.ERROR_DV_LOOKUP_TAX_NUMBER_EMPLOYEE_DETAILS_CONFUSION;
121             GlobalVariables.getMessageMap().putError(KIMPropertyConstants.Person.EMPLOYEE_ID, messageKey, this.getAttributeLabel(KIMPropertyConstants.Person.EMPLOYEE_ID), this.getAttributeLabel(OLEPropertyConstants.TAX_NUMBER));
122         }
123             }
124 
125     /**
126      * Note: This method is not called by validateSearchParameters anymore.
127      * This method validates the employee name usage in lookup
128      */
129     @Deprecated
130     public void validateEmployeeNameUse(Map fieldValues) {
131         final String firstName = (String)fieldValues.get(KIMPropertyConstants.Person.FIRST_NAME);
132         final String lastName = (String)fieldValues.get(KIMPropertyConstants.Person.LAST_NAME);
133         final String vendorName = (String) fieldValues.get(OLEPropertyConstants.VENDOR_NAME);
134         final String employeeId = (String) fieldValues.get(KIMPropertyConstants.Person.EMPLOYEE_ID);
135         final boolean isPersonNameEntered = StringUtils.isNotBlank(firstName) || StringUtils.isNotBlank(lastName);
136 
137             if (isPersonNameEntered && StringUtils.isNotBlank(vendorName)) {
138                 // only can use the person first and last name fields or the vendor name field, but not both.
139                 String messageKey = OLEKeyConstants.ERROR_DV_VENDOR_NAME_PERSON_NAME_CONFUSION;
140 
141                 String vendorNameLabel = this.getAttributeLabel(OLEPropertyConstants.VENDOR_NAME);
142                 String firstNameLabel = this.getAttributeLabel(KIMPropertyConstants.Person.FIRST_NAME);
143                 String lastNameLabel = this.getAttributeLabel(KIMPropertyConstants.Person.LAST_NAME);
144                 GlobalVariables.getMessageMap().putError(OLEPropertyConstants.VENDOR_NAME, messageKey, vendorNameLabel, firstNameLabel, lastNameLabel);
145             }
146             if (StringUtils.isBlank(employeeId)) {
147                 if (StringUtils.isBlank(firstName) && !StringUtils.isBlank(lastName) && !filledEnough(lastName)) {
148                     final String label = getAttributeLabel(KIMPropertyConstants.Person.LAST_NAME);
149                     GlobalVariables.getMessageMap().putError(KIMPropertyConstants.Person.LAST_NAME, OLEKeyConstants.ERROR_DV_NAME_NOT_FILLED_ENOUGH, new String[] { label, Integer.toString(getNameLengthWithWildcardRequirement() ) } );
150                 } else if (StringUtils.isBlank(lastName) && !StringUtils.isBlank(firstName) && !filledEnough(firstName)) {
151                     final String label = getAttributeLabel(KIMPropertyConstants.Person.FIRST_NAME);
152                     GlobalVariables.getMessageMap().putError(KIMPropertyConstants.Person.FIRST_NAME, OLEKeyConstants.ERROR_DV_NAME_NOT_FILLED_ENOUGH, new String[] { label, Integer.toString(getNameLengthWithWildcardRequirement() ) } );
153                 }
154             }
155         }
156 
157     /**
158      * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#validateSearchParameters(java.util.Map)
159      */
160     @Override
161     public void validateSearchParameters(Map fieldValues) {
162         super.validateSearchParameters(fieldValues);
163 
164         String vendorNumberLabel = getAttributeLabel(OLEPropertyConstants.VENDOR_NUMBER);
165         String taxNumberLabel = getAttributeLabel(OLEPropertyConstants.TAX_NUMBER);
166         String employeeIdLabel = getAttributeLabel(OLEPropertyConstants.EMPLOYEE_ID);
167         String payeeNameLabel = getAttributeLabel(OLEPropertyConstants.PAYEE_NAME);
168         String lastNameLabel = getAttributeLabel(OLEPropertyConstants.PERSON_LAST_NAME);
169         String firstNameLabel = getAttributeLabel(OLEPropertyConstants.PERSON_FIRST_NAME);
170 
171         String vendorNumber = (String)fieldValues.get(OLEPropertyConstants.VENDOR_NUMBER);
172         String taxNumber = (String)fieldValues.get(OLEPropertyConstants.TAX_NUMBER);
173         String employeeId = (String)fieldValues.get(OLEPropertyConstants.EMPLOYEE_ID);
174         String payeeName = (String)fieldValues.get(OLEPropertyConstants.PAYEE_NAME);
175 
176         boolean vendorNumberBlank = StringUtils.isBlank(vendorNumber);
177         boolean taxNumberBlank = StringUtils.isBlank(taxNumber);
178         boolean employeeIdBlank = StringUtils.isBlank(employeeId);
179         boolean payeeNameBlank = StringUtils.isBlank(payeeName);
180         boolean vendorInfoBlank = vendorNumberBlank && taxNumberBlank;
181 
182         // must at least enter one of the following searching criteria: vendorNumber, taxNumber, employeeId, payeeName
183         if (vendorNumberBlank && taxNumberBlank && employeeIdBlank && payeeNameBlank) {
184             GlobalVariables.getMessageMap().putError(OLEPropertyConstants.PAYEE_NAME, OLEKeyConstants.ERROR_DV_LOOKUP_NEEDS_SOME_FIELD, new String[]{vendorNumberLabel, taxNumberLabel, employeeIdLabel, payeeNameLabel});
185         }
186         // can't enter both vendor info (vendorNumber/taxNumber) and employee info (employeeId)
187         else if (!(vendorNumberBlank && taxNumberBlank) && !employeeIdBlank) {
188             GlobalVariables.getMessageMap().putError(OLEPropertyConstants.EMPLOYEE_ID, OLEKeyConstants.ERROR_DV_VENDOR_EMPLOYEE_CONFUSION, new String[]{employeeIdLabel, vendorNumberLabel, taxNumberLabel});
189         }
190         // if vendorNumber is entered, then taxNumber and/or payeeName will be ignored in searching for vendor payee
191         else if (!vendorNumberBlank && !(taxNumberBlank && payeeNameBlank)) {
192             GlobalVariables.getMessageMap().putWarning(OLEPropertyConstants.VENDOR_NUMBER, OLEKeyConstants.WARNING_DV_PAYEE_ID_UNIQUE, new String[]{vendorNumberLabel, "Vendor"});
193         }
194         // if employeeId is entered, then payeeName will be ignored in searching for person payee
195         else if (!employeeIdBlank && !payeeNameBlank) {
196             GlobalVariables.getMessageMap().putWarning(OLEPropertyConstants.EMPLOYEE_ID, OLEKeyConstants.WARNING_DV_PAYEE_ID_UNIQUE, new String[]{employeeIdLabel, "Employee"});
197         }
198         // if payeeName is entered, check its filled level
199         else if (!payeeNameBlank) {
200             String minlen = Integer.toString(getNameLengthWithWildcardRequirement());
201 
202             if (!canSplit(payeeName)) {
203                 // check whether non-splitable payeeName is filled enough if wildcard is used
204                 if (!filledEnough(payeeName)) {
205                     GlobalVariables.getMessageMap().putError(OLEPropertyConstants.PAYEE_NAME, OLEKeyConstants.ERROR_DV_NAME_NOT_FILLED_ENOUGH, new String[]{payeeNameLabel, minlen});
206                 }
207             }
208             else {
209                 String lastName = splitLastName(payeeName);
210                 String firstName = splitFirstName(payeeName);
211 
212                 // check at least one side of "lastName, firstName" is filled
213                 if (StringUtils.isBlank(lastName) && StringUtils.isBlank(firstName)) {
214                     GlobalVariables.getMessageMap().putError(OLEPropertyConstants.PAYEE_NAME, OLEKeyConstants.ERROR_DV_LAST_FIRST_NAME_NOT_FILLED, new String[]{payeeNameLabel, minlen});
215                 }
216 
217                 // check whether lastName is filled enough if wildcard is used
218                 if (!filledEnough(lastName)) {
219                     GlobalVariables.getMessageMap().putError(OLEPropertyConstants.PAYEE_NAME, OLEKeyConstants.ERROR_DV_NAME_NOT_FILLED_ENOUGH, new String[]{lastNameLabel, minlen});
220                 }
221 
222                 // check whether firstName is filled enough if wildcard is used
223                 if (!filledEnough(firstName)) {
224                     GlobalVariables.getMessageMap().putError(OLEPropertyConstants.PAYEE_NAME, OLEKeyConstants.ERROR_DV_NAME_NOT_FILLED_ENOUGH, new String[]{firstNameLabel, minlen});
225                 }
226             }
227         }
228 
229         if (GlobalVariables.getMessageMap().hasErrors()) {
230             throw new ValidationException("errors in search criteria");
231         }
232     }
233 
234      /**
235      * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#performLookup(org.kuali.rice.kns.web.struts.form.LookupForm,
236      *      java.util.Collection, boolean)
237      */
238     @Override
239     public Collection performLookup(LookupForm lookupForm, Collection resultTable, boolean bounded) {
240         Map<String, String> fieldValues = lookupForm.getFieldsForLookup();
241         String paymentReasonCode = fieldValues.get(OLEPropertyConstants.PAYMENT_REASON_CODE);
242 
243         List<DisbursementPayee> displayList = (List<DisbursementPayee>) super.performLookup(lookupForm, resultTable, bounded);
244         this.filterReturnUrl((List<ResultRow>) resultTable, displayList, paymentReasonCode);
245 
246         MessageList messageList = KNSGlobalVariables.getMessageList();
247         disbursementVoucherPaymentReasonService.postPaymentReasonCodeUsage(paymentReasonCode, messageList);
248 
249         return displayList;
250     }
251 
252     /**
253      * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResults(java.util.Map)
254      */
255     @Override
256     public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
257         List<DisbursementPayee> searchResults = new ArrayList<DisbursementPayee>();
258 
259         if (StringUtils.isNotBlank(fieldValues.get(OLEPropertyConstants.VENDOR_NUMBER)) || StringUtils.isNotBlank(fieldValues.get(OLEPropertyConstants.TAX_NUMBER))) {
260             searchResults.addAll(this.getVendorsAsPayees(fieldValues));
261         }
262         else if (StringUtils.isNotBlank(fieldValues.get(OLEPropertyConstants.EMPLOYEE_ID))) {
263             searchResults.addAll(this.getPersonAsPayees(fieldValues));
264         }
265         else {
266             searchResults.addAll(this.getVendorsAsPayees(fieldValues));
267             searchResults.addAll(this.getPersonAsPayees(fieldValues));
268         }
269 
270         return sortSearchResults(searchResults);
271     }
272 
273     /**
274      * Sorts search results.
275      */
276     protected List<? extends BusinessObject> sortSearchResults(List<DisbursementPayee> searchResults) {
277         CollectionIncomplete results = new CollectionIncomplete(searchResults, Long.valueOf(searchResults.size()));
278 
279         // sort list if default sort column given
280         List<String> defaultSortColumns = getDefaultSortColumns();
281         if (defaultSortColumns.size() > 0) {
282             Collections.sort(results, new BeanPropertyComparator(getDefaultSortColumns(), true));
283         }
284 
285         return results;
286     }
287 
288     /**
289      * Decides if the specified payeeName can be split into lastName and firstName, i.e. whether it contains a comma.
290      */
291     protected boolean canSplit(String payeeName) {
292         return StringUtils.contains(payeeName, OLEConstants.COMMA);
293     }
294 
295     /**
296      * Splits the last name from the specified payeeName, which is in the format of "lastName,firstName".
297      * If comma doesn't exist in the name, then the whole string is returned;
298      */
299     protected String splitLastName(String payeeName) {
300         return StringUtils.strip(StringUtils.substringBefore(payeeName, OLEConstants.COMMA));
301     }
302 
303     /**
304      * Splits the first name from the specified payeeName, which is in the format of "lastName,firstName".
305      * If comma doesn't exist in the name, then an empty string is returned.
306      */
307     protected String splitFirstName(String payeeName) {
308         return StringUtils.strip(StringUtils.substringAfter(payeeName, OLEConstants.COMMA));
309     }
310 
311 
312     /**
313      * Determines if a String is "filled enough" - ie, is not null, has a length greater than zero and if a wildcard is present, has a length greater than 4 (3 characters, plus a wildcard)
314      * @param s the String to test
315      * @return true if the given String is "filled" by the definition above, false otherwise
316      */
317     protected boolean filledEnough(String s) {
318         return !containsLookupWildcard(s) || StringUtils.length(s) >= getNameLengthWithWildcardRequirement();
319     }
320 
321     /**
322      * @return the number of characters a name field must be filled in for the search to be valid
323      */
324     protected int getNameLengthWithWildcardRequirement() {
325         return NAME_REQUIRED_FILLED_WITH_WILDCARD;
326     }
327 
328     /**
329      * Determines if the given String contains a lookup wildcard
330      * @param s the String to test
331      * @return true if a lookup wildcard is in the String, false otherwise
332      */
333     protected boolean containsLookupWildcard(String s) {
334         return StringUtils.contains(s, "*") || StringUtils.contains(s, "%");
335     }
336 
337     /**
338      * Gets the search criteria valid for vendor lookup, from the specified field value map.
339      */
340     @Override
341     protected Map<String, String> getVendorFieldValues(Map<String, String> fieldValues) {
342         String vendorNumber = fieldValues.get(OLEPropertyConstants.VENDOR_NUMBER);
343         String taxNumber = fieldValues.get(OLEPropertyConstants.TAX_NUMBER);
344         String payeeName = fieldValues.get(OLEPropertyConstants.PAYEE_NAME);
345         boolean vendorNumberBlank = StringUtils.isBlank(vendorNumber);
346         boolean taxNumberBlank = StringUtils.isBlank(taxNumber);
347         boolean payeeNameBlank = StringUtils.isBlank(payeeName);
348 
349         Map<String, String> vendorFieldValues = new HashMap<String, String>();
350         vendorFieldValues.put(OLEPropertyConstants.ACTIVE, fieldValues.get(OLEPropertyConstants.ACTIVE));
351 
352         if (!vendorNumberBlank) {
353             // if vendorNumber is entered, then taxNumber and/or payeeName will be ignored in searching for vendor payee
354             vendorFieldValues.put(OLEPropertyConstants.VENDOR_NUMBER, vendorNumber);
355         }
356         else {
357             if (!taxNumberBlank) {
358                 vendorFieldValues.put(OLEPropertyConstants.TAX_NUMBER, taxNumber);
359             }
360             if (!payeeNameBlank) {
361                 vendorFieldValues.put(OLEPropertyConstants.PAYEE_NAME, getVendorName(payeeName));
362             }
363         }
364 
365         Map<String, String> fieldConversionMap = disbursementVoucherPayeeService.getFieldConversionBetweenPayeeAndVendor();
366         replaceFieldKeys(vendorFieldValues, fieldConversionMap);
367         return vendorFieldValues;
368     }
369 
370     /**
371      * Gets the proper vendor name based on the given payee name.
372      */
373     protected String getVendorName(String payeeName) {
374         String vendorName = "";
375 
376         // if payee name can't be split into "lastName,firstName", then treat it as a whole vendor name
377         if (!canSplit(payeeName)) {
378             vendorName = payeeName;
379         }
380         // otherwise at least one side of "lastName,firstName" shall not be empty
381         else {
382             // replace empty last name with wildcard
383             String lastName = splitLastName(payeeName);
384             if (StringUtils.isBlank(lastName)) {
385                 lastName = "*";
386             }
387             // replace empty first name with wildcard
388             String firstName = splitFirstName(payeeName);
389             if (StringUtils.isBlank(firstName)) {
390                 firstName = "*";
391             }
392             // concat into "lastName, firstName"
393             vendorName = lastName + VendorConstants.NAME_DELIM + firstName;
394         }
395 
396         return vendorName;
397     }
398 
399     /**
400      * Gets the search criteria valid for vendor lookup, from the specified field value map.
401      */
402     @Override
403     protected Map<String, String> getPersonFieldValues(Map<String, String> fieldValues) {
404         String employeeId = fieldValues.get(OLEPropertyConstants.EMPLOYEE_ID);
405         String payeeName = fieldValues.get(OLEPropertyConstants.PAYEE_NAME);
406         boolean employeeIdBlank = StringUtils.isBlank(employeeId);
407         boolean payeeNameBlank = StringUtils.isBlank(payeeName);
408 
409         Map<String, String> personFieldValues = new HashMap<String, String>();
410         personFieldValues.put(OLEPropertyConstants.ACTIVE, fieldValues.get(OLEPropertyConstants.ACTIVE));
411 
412         // if employeeId is entered, then payeeName will be ignored in searching for employee payee
413         if (!employeeIdBlank) {
414             personFieldValues.put(OLEPropertyConstants.EMPLOYEE_ID, employeeId);
415         }
416         // otherwise at least one side of "lastName,firstName" shall not be empty; if "'" doesn't exist in the name string, treat the whole string as last name
417         else if (!payeeNameBlank) {
418             // add lastName as search criteria if not empty
419             String lastName = splitLastName(payeeName);
420             if (StringUtils.isNotBlank(lastName)) {
421                 personFieldValues.put(OLEPropertyConstants.PERSON_LAST_NAME, getVendorName(lastName));
422             }
423             // add firstName as search criteria if not empty
424             String firstName = splitFirstName(payeeName);
425             if (StringUtils.isNotBlank(firstName)) {
426                 personFieldValues.put(OLEPropertyConstants.PERSON_FIRST_NAME, getVendorName(firstName));
427             }
428         }
429 
430         Map<String, String> fieldConversionMap = disbursementVoucherPayeeService.getFieldConversionBetweenPayeeAndPerson();
431         this.replaceFieldKeys(personFieldValues, fieldConversionMap);
432         return personFieldValues;
433     }
434 
435     /**
436      * Removes its return URLs if a row is not qualified for returning.
437      *
438      * @param resultRowList
439      * @param payeeList
440      * @param paymentReasonCode
441      */
442     protected void filterReturnUrl(List<ResultRow> resultRowList, List<DisbursementPayee> payeeList, String paymentReasonCode) {
443         Collection<String> payeeTypeCodes = disbursementVoucherPaymentReasonService.getPayeeTypesByPaymentReason(paymentReasonCode);
444         if (payeeTypeCodes == null || payeeTypeCodes.isEmpty()) {
445             return;
446         }
447 
448         for (int index = 0; index < payeeList.size(); index++) {
449             DisbursementPayee payee = payeeList.get(index);
450 
451             boolean isQualified = disbursementVoucherPaymentReasonService.isPayeeQualifiedForPayment(payee, paymentReasonCode, payeeTypeCodes);
452             if (!isQualified) {
453                 resultRowList.get(index).setReturnUrl(StringUtils.EMPTY);
454             }
455         }
456     }
457 
458     /**
459      * Sets the disbursementVoucherPaymentReasonService attribute value.
460      *
461      * @param disbursementVoucherPaymentReasonService The disbursementVoucherPaymentReasonService to set.
462      */
463     public void setDisbursementVoucherPaymentReasonService(DisbursementVoucherPaymentReasonService disbursementVoucherPaymentReasonService) {
464         this.disbursementVoucherPaymentReasonService = disbursementVoucherPaymentReasonService;
465     }
466 
467 }