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.kuali.kfs.sys.KFSConstants;
023    import org.kuali.rice.kns.bo.BusinessObject;
024    import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
025    import org.kuali.rice.kns.util.BeanPropertyComparator;
026    
027    
028    public class VendorAddressLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
029        private boolean searchUsingOnlyPrimaryKeyValues = false;
030    
031        /**
032         * Overrides the default behavior because we need to restrict the search results to the vendor ids that we are sending in as
033         * criteria, but since they are set as hidden in the DD the default behavior is to remove them from the criteria.
034         * 
035         * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResultsHelper(java.util.Map, boolean)
036         */
037        @SuppressWarnings("unchecked")
038        @Override
039        protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded) {
040            searchUsingOnlyPrimaryKeyValues = getLookupService().allPrimaryKeyValuesPresentAndNotWildcard(getBusinessObjectClass(), fieldValues);
041    
042            setBackLocation(fieldValues.get(KFSConstants.BACK_LOCATION));
043            setDocFormKey(fieldValues.get(KFSConstants.DOC_FORM_KEY));
044            setReferencesToRefresh(fieldValues.get(KFSConstants.REFERENCES_TO_REFRESH));
045            List searchResults = (List) getLookupService().findCollectionBySearchHelper(getBusinessObjectClass(), fieldValues, unbounded);
046            // sort list if default sort column given
047            List defaultSortColumns = getDefaultSortColumns();
048            if (defaultSortColumns.size() > 0) {
049                Collections.sort(searchResults, new BeanPropertyComparator(getDefaultSortColumns(), true));
050            }
051    
052            return searchResults;
053        }
054    
055        /**
056         * @see LookupableHelperService#isSearchUsingOnlyPrimaryKeyValues()
057         */
058        @Override
059        public boolean isSearchUsingOnlyPrimaryKeyValues() {
060    
061            return searchUsingOnlyPrimaryKeyValues;
062        }
063    }
064