View Javadoc
1   /*
2    * Copyright 2007 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.vnd.businessobject.lookup;
17  
18  import java.util.Collections;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.ole.sys.OLEConstants;
24  import org.kuali.ole.vnd.VendorConstants;
25  import org.kuali.ole.vnd.businessobject.VendorContact;
26  import org.kuali.ole.vnd.businessobject.VendorContactPhoneNumber;
27  import org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl;
28  import org.kuali.rice.krad.bo.PersistableBusinessObject;
29  import org.kuali.rice.krad.util.BeanPropertyComparator;
30  
31  public class VendorContactLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl {
32  
33      /**
34       * Overrides the getSearchResults in the super class so that we can do some customization in our vendor contact lookup. For
35       * example, we want to be able to display the first phone number, fax number and toll free number in the vendor contact.
36       * 
37       * @see org.kuali.rice.kns.lookup.Lookupable#getSearchResults(java.util.Map)
38       */
39      @Override
40      public List<PersistableBusinessObject> getSearchResults(Map<String, String> fieldValues) {
41          boolean unbounded = false;
42          super.setBackLocation((String) fieldValues.get(OLEConstants.BACK_LOCATION));
43          super.setDocFormKey((String) fieldValues.get(OLEConstants.DOC_FORM_KEY));
44  
45          List<PersistableBusinessObject> searchResults = (List) getLookupService().findCollectionBySearchHelper(getBusinessObjectClass(), fieldValues, unbounded);
46  
47          // loop through results
48          for (PersistableBusinessObject object : searchResults) {
49              VendorContact vendorContact = (VendorContact) object;
50  
51              for (VendorContactPhoneNumber phoneNumber : vendorContact.getVendorContactPhoneNumbers()) {
52                  String extension = phoneNumber.getVendorPhoneExtensionNumber();
53                  if (phoneNumber.getVendorPhoneType().getVendorPhoneTypeCode().equals(VendorConstants.PhoneTypes.PHONE) && StringUtils.isEmpty(vendorContact.getPhoneNumberForLookup())) {
54                      vendorContact.setPhoneNumberForLookup(phoneNumber.getVendorPhoneNumber() + ((StringUtils.isNotEmpty(extension)) ? " x " + extension : null));
55                  }
56                  else if (phoneNumber.getVendorPhoneType().getVendorPhoneTypeCode().equals(VendorConstants.PhoneTypes.FAX) && StringUtils.isBlank(vendorContact.getFaxForLookup())) {
57                      vendorContact.setFaxForLookup(phoneNumber.getVendorPhoneNumber() + ((StringUtils.isNotEmpty(extension)) ? " x " + extension : OLEConstants.EMPTY_STRING));
58                  }
59                  else if (phoneNumber.getVendorPhoneType().getVendorPhoneTypeCode().equals(VendorConstants.PhoneTypes.TOLL_FREE) && StringUtils.isBlank(vendorContact.getTollFreeForLookup())) {
60                      vendorContact.setTollFreeForLookup(phoneNumber.getVendorPhoneNumber() + ((StringUtils.isNotEmpty(extension)) ? " x " + extension : OLEConstants.EMPTY_STRING));
61                  }
62              }
63          }
64  
65          // sort list if default sort column given
66          List<String> defaultSortColumns = getDefaultSortColumns();
67          if (defaultSortColumns.size() > 0) {
68              Collections.sort(searchResults, new BeanPropertyComparator(getDefaultSortColumns(), true));
69          }
70  
71          return searchResults;
72      }
73  
74  }