001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.vendor.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.core.bo.PersistableBusinessObject;
024: import org.kuali.core.lookup.AbstractLookupableHelperServiceImpl;
025: import org.kuali.core.util.BeanPropertyComparator;
026: import org.kuali.kfs.KFSConstants;
027: import org.kuali.module.vendor.VendorConstants;
028: import org.kuali.module.vendor.bo.VendorContact;
029: import org.kuali.module.vendor.bo.VendorContactPhoneNumber;
030:
031: public class VendorContactLookupableHelperServiceImpl extends
032: AbstractLookupableHelperServiceImpl {
033:
034: /**
035: * Overrides the getSearchResults in the super class so that we can do some customization in our vendor contact lookup. For
036: * example, we want to be able to display the first phone number, fax number and toll free number in the vendor contact.
037: *
038: * @see org.kuali.core.lookup.Lookupable#getSearchResults(java.util.Map)
039: */
040: @Override
041: public List<PersistableBusinessObject> getSearchResults(
042: Map<String, String> fieldValues) {
043: boolean unbounded = false;
044: super .setBackLocation((String) fieldValues
045: .get(KFSConstants.BACK_LOCATION));
046: super .setDocFormKey((String) fieldValues
047: .get(KFSConstants.DOC_FORM_KEY));
048:
049: List<PersistableBusinessObject> searchResults = (List) getLookupService()
050: .findCollectionBySearchHelper(getBusinessObjectClass(),
051: fieldValues, unbounded);
052:
053: // loop through results
054: for (PersistableBusinessObject object : searchResults) {
055: VendorContact vendorContact = (VendorContact) object;
056:
057: for (VendorContactPhoneNumber phoneNumber : vendorContact
058: .getVendorContactPhoneNumbers()) {
059: String extension = phoneNumber
060: .getVendorPhoneExtensionNumber();
061: if (phoneNumber.getVendorPhoneType()
062: .getVendorPhoneTypeCode().equals(
063: VendorConstants.PhoneTypes.PHONE)
064: && StringUtils.isEmpty(vendorContact
065: .getPhoneNumberForLookup())) {
066: vendorContact
067: .setPhoneNumberForLookup(phoneNumber
068: .getVendorPhoneNumber()
069: + ((StringUtils
070: .isNotEmpty(extension)) ? " x "
071: + extension
072: : null));
073: } else if (phoneNumber.getVendorPhoneType()
074: .getVendorPhoneTypeCode().equals(
075: VendorConstants.PhoneTypes.FAX)
076: && StringUtils.isBlank(vendorContact
077: .getFaxForLookup())) {
078: vendorContact
079: .setFaxForLookup(phoneNumber
080: .getVendorPhoneNumber()
081: + ((StringUtils
082: .isNotEmpty(extension)) ? " x "
083: + extension
084: : KFSConstants.EMPTY_STRING));
085: } else if (phoneNumber.getVendorPhoneType()
086: .getVendorPhoneTypeCode().equals(
087: VendorConstants.PhoneTypes.TOLL_FREE)
088: && StringUtils.isBlank(vendorContact
089: .getTollFreeForLookup())) {
090: vendorContact
091: .setTollFreeForLookup(phoneNumber
092: .getVendorPhoneNumber()
093: + ((StringUtils
094: .isNotEmpty(extension)) ? " x "
095: + extension
096: : KFSConstants.EMPTY_STRING));
097: }
098: }
099: }
100:
101: // sort list if default sort column given
102: List<String> defaultSortColumns = getDefaultSortColumns();
103: if (defaultSortColumns.size() > 0) {
104: Collections.sort(searchResults, new BeanPropertyComparator(
105: getDefaultSortColumns(), true));
106: }
107:
108: return searchResults;
109: }
110:
111: }
|