001 /* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.kfs.vnd.businessobject.lookup; 017 018 import java.util.Collections; 019 import java.util.List; 020 import java.util.Map; 021 022 import org.apache.commons.lang.StringUtils; 023 import org.kuali.kfs.sys.KFSConstants; 024 import org.kuali.kfs.vnd.VendorConstants; 025 import org.kuali.kfs.vnd.businessobject.VendorContact; 026 import org.kuali.kfs.vnd.businessobject.VendorContactPhoneNumber; 027 import org.kuali.rice.kns.bo.PersistableBusinessObject; 028 import org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl; 029 import org.kuali.rice.kns.util.BeanPropertyComparator; 030 031 public class VendorContactLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl { 032 033 /** 034 * Overrides the getSearchResults in the super class so that we can do some customization in our vendor contact lookup. For 035 * example, we want to be able to display the first phone number, fax number and toll free number in the vendor contact. 036 * 037 * @see org.kuali.rice.kns.lookup.Lookupable#getSearchResults(java.util.Map) 038 */ 039 @Override 040 public List<PersistableBusinessObject> getSearchResults(Map<String, String> fieldValues) { 041 boolean unbounded = false; 042 super.setBackLocation((String) fieldValues.get(KFSConstants.BACK_LOCATION)); 043 super.setDocFormKey((String) fieldValues.get(KFSConstants.DOC_FORM_KEY)); 044 045 List<PersistableBusinessObject> searchResults = (List) getLookupService().findCollectionBySearchHelper(getBusinessObjectClass(), fieldValues, unbounded); 046 047 // loop through results 048 for (PersistableBusinessObject object : searchResults) { 049 VendorContact vendorContact = (VendorContact) object; 050 051 for (VendorContactPhoneNumber phoneNumber : vendorContact.getVendorContactPhoneNumbers()) { 052 String extension = phoneNumber.getVendorPhoneExtensionNumber(); 053 if (phoneNumber.getVendorPhoneType().getVendorPhoneTypeCode().equals(VendorConstants.PhoneTypes.PHONE) && StringUtils.isEmpty(vendorContact.getPhoneNumberForLookup())) { 054 vendorContact.setPhoneNumberForLookup(phoneNumber.getVendorPhoneNumber() + ((StringUtils.isNotEmpty(extension)) ? " x " + extension : null)); 055 } 056 else if (phoneNumber.getVendorPhoneType().getVendorPhoneTypeCode().equals(VendorConstants.PhoneTypes.FAX) && StringUtils.isBlank(vendorContact.getFaxForLookup())) { 057 vendorContact.setFaxForLookup(phoneNumber.getVendorPhoneNumber() + ((StringUtils.isNotEmpty(extension)) ? " x " + extension : KFSConstants.EMPTY_STRING)); 058 } 059 else if (phoneNumber.getVendorPhoneType().getVendorPhoneTypeCode().equals(VendorConstants.PhoneTypes.TOLL_FREE) && StringUtils.isBlank(vendorContact.getTollFreeForLookup())) { 060 vendorContact.setTollFreeForLookup(phoneNumber.getVendorPhoneNumber() + ((StringUtils.isNotEmpty(extension)) ? " x " + extension : KFSConstants.EMPTY_STRING)); 061 } 062 } 063 } 064 065 // sort list if default sort column given 066 List<String> defaultSortColumns = getDefaultSortColumns(); 067 if (defaultSortColumns.size() > 0) { 068 Collections.sort(searchResults, new BeanPropertyComparator(getDefaultSortColumns(), true)); 069 } 070 071 return searchResults; 072 } 073 074 }