View Javadoc
1   /*
2    * Copyright 2012 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.apache.cxf.common.util.StringUtils;
23  import org.kuali.ole.vnd.batch.service.VendorExcludeService;
24  import org.kuali.ole.vnd.businessobject.VendorAddress;
25  import org.kuali.ole.vnd.businessobject.VendorDetail;
26  import org.kuali.ole.vnd.document.service.VendorService;
27  import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
28  import org.kuali.rice.krad.bo.BusinessObject;
29  
30  public class DebarredVendorUnmatchedLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
31      VendorExcludeService vendorExcludeService;
32      VendorService vendorService;
33  
34      @Override
35      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
36          return getDebarredVendorUnmatchedSearchResults(fieldValues);
37      }
38  
39      @Override
40      public List<? extends BusinessObject> getSearchResultsUnbounded(Map<String, String> fieldValues) {
41          return getDebarredVendorUnmatchedSearchResults(fieldValues);
42      }
43  
44      protected List<? extends BusinessObject> getDebarredVendorUnmatchedSearchResults(Map<String, String> fieldValues) {
45          List<VendorDetail> vendorResultList = vendorExcludeService.getDebarredVendorsUnmatched();
46          List<VendorDetail> filteredVendorList = new ArrayList<VendorDetail> ();
47          VendorAddress defaultAddress = null;
48          String vendorType = fieldValues.get("vendorTypeCode");
49          for (VendorDetail vendor : vendorResultList) {
50              if (!StringUtils.isEmpty(vendorType) && !vendor.getVendorHeader().getVendorTypeCode().equals(vendorType)) {
51                  continue;
52              }
53              if(vendor.getVendorAddresses()!=null && vendor.getVendorHeader()!=null && vendor.getVendorHeader().getVendorType()!=null && vendor.getVendorHeader().getVendorType().getAddressType()!=null && vendor.getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode()!=null){
54                  defaultAddress = vendorService.getVendorDefaultAddress(vendor.getVendorAddresses(), vendor.getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode(), "");
55              }
56              if (defaultAddress != null ) {
57                  vendor.setDefaultAddressLine1(defaultAddress.getVendorLine1Address());
58                  vendor.setDefaultAddressCity(defaultAddress.getVendorCityName());
59                  vendor.setDefaultAddressStateCode(defaultAddress.getVendorStateCode());
60                  vendor.setDefaultAddressCountryCode(defaultAddress.getVendorCountryCode());
61              }
62              filteredVendorList.add(vendor);
63          }
64          return filteredVendorList;
65      }
66  
67      /**
68       * Gets the vendorExcludeService attribute.
69       * @return Returns the vendorExcludeService.
70       */
71      public VendorExcludeService getVendorExcludeService() {
72          return vendorExcludeService;
73      }
74  
75      /**
76       * Sets the vendorExcludeService attribute value.
77       * @param vendorExcludeService The vendorExcludeService to set.
78       */
79      public void setVendorExcludeService(VendorExcludeService vendorExcludeService) {
80          this.vendorExcludeService = vendorExcludeService;
81      }
82  
83      /**
84       * Gets the vendorService attribute.
85       * @return Returns the vendorService.
86       */
87      public VendorService getVendorService() {
88          return vendorService;
89      }
90  
91      /**
92       * Sets the vendorService attribute value.
93       * @param vendorService The vendorService to set.
94       */
95      public void setVendorService(VendorService vendorService) {
96          this.vendorService = vendorService;
97      }
98  }