001/*
002 * Copyright 2012 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 */
016package org.kuali.ole.vnd.businessobject.lookup;
017
018import java.util.ArrayList;
019import java.util.List;
020import java.util.Map;
021
022import org.apache.cxf.common.util.StringUtils;
023import org.kuali.ole.vnd.batch.service.VendorExcludeService;
024import org.kuali.ole.vnd.businessobject.VendorAddress;
025import org.kuali.ole.vnd.businessobject.VendorDetail;
026import org.kuali.ole.vnd.document.service.VendorService;
027import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
028import org.kuali.rice.krad.bo.BusinessObject;
029
030public class DebarredVendorUnmatchedLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
031    VendorExcludeService vendorExcludeService;
032    VendorService vendorService;
033
034    @Override
035    public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
036        return getDebarredVendorUnmatchedSearchResults(fieldValues);
037    }
038
039    @Override
040    public List<? extends BusinessObject> getSearchResultsUnbounded(Map<String, String> fieldValues) {
041        return getDebarredVendorUnmatchedSearchResults(fieldValues);
042    }
043
044    protected List<? extends BusinessObject> getDebarredVendorUnmatchedSearchResults(Map<String, String> fieldValues) {
045        List<VendorDetail> vendorResultList = vendorExcludeService.getDebarredVendorsUnmatched();
046        List<VendorDetail> filteredVendorList = new ArrayList<VendorDetail> ();
047        VendorAddress defaultAddress = null;
048        String vendorType = fieldValues.get("vendorTypeCode");
049        for (VendorDetail vendor : vendorResultList) {
050            if (!StringUtils.isEmpty(vendorType) && !vendor.getVendorHeader().getVendorTypeCode().equals(vendorType)) {
051                continue;
052            }
053            if(vendor.getVendorAddresses()!=null && vendor.getVendorHeader()!=null && vendor.getVendorHeader().getVendorType()!=null && vendor.getVendorHeader().getVendorType().getAddressType()!=null && vendor.getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode()!=null){
054                defaultAddress = vendorService.getVendorDefaultAddress(vendor.getVendorAddresses(), vendor.getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode(), "");
055            }
056            if (defaultAddress != null ) {
057                vendor.setDefaultAddressLine1(defaultAddress.getVendorLine1Address());
058                vendor.setDefaultAddressCity(defaultAddress.getVendorCityName());
059                vendor.setDefaultAddressStateCode(defaultAddress.getVendorStateCode());
060                vendor.setDefaultAddressCountryCode(defaultAddress.getVendorCountryCode());
061            }
062            filteredVendorList.add(vendor);
063        }
064        return filteredVendorList;
065    }
066
067    /**
068     * Gets the vendorExcludeService attribute.
069     * @return Returns the vendorExcludeService.
070     */
071    public VendorExcludeService getVendorExcludeService() {
072        return vendorExcludeService;
073    }
074
075    /**
076     * Sets the vendorExcludeService attribute value.
077     * @param vendorExcludeService The vendorExcludeService to set.
078     */
079    public void setVendorExcludeService(VendorExcludeService vendorExcludeService) {
080        this.vendorExcludeService = vendorExcludeService;
081    }
082
083    /**
084     * Gets the vendorService attribute.
085     * @return Returns the vendorService.
086     */
087    public VendorService getVendorService() {
088        return vendorService;
089    }
090
091    /**
092     * Sets the vendorService attribute value.
093     * @param vendorService The vendorService to set.
094     */
095    public void setVendorService(VendorService vendorService) {
096        this.vendorService = vendorService;
097    }
098}