View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 2.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/ecl2.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  
17  package org.kuali.ole.select.lookup;
18  
19  import org.apache.commons.lang3.StringUtils;
20  import org.kuali.ole.select.OleSelectConstant;
21  import org.kuali.ole.select.bo.OLEInvoiceSearchDocument;
22  import org.kuali.ole.select.businessobject.OleInvoiceItem;
23  import org.kuali.ole.select.document.OleInvoiceDocument;
24  import org.kuali.ole.select.service.OLEInvoiceSearchService;
25  import org.kuali.rice.krad.lookup.LookupableImpl;
26  import org.kuali.rice.krad.service.KRADServiceLocator;
27  import org.kuali.rice.krad.web.form.LookupForm;
28  
29  import java.text.DateFormat;
30  import java.text.ParseException;
31  import java.text.SimpleDateFormat;
32  import java.util.*;
33  
34  public class OLEInvoiceSearchDocumentLookupableImpl extends LookupableImpl {
35      @Override
36      public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) {
37          List<OLEInvoiceSearchDocument> oleInvoiceSearchDocuments=new ArrayList<OLEInvoiceSearchDocument>();
38          List<OLEInvoiceSearchDocument> oleInvoiceDocuments=new ArrayList<OLEInvoiceSearchDocument>();
39          List<OLEInvoiceSearchDocument> oleInvoiceDocumentsForTitle=new ArrayList<OLEInvoiceSearchDocument>();
40          Map<String, String> searchDocumentMap = new HashMap<String, String>();
41          Map<String, String> fieldConversion=form.getFieldConversions();
42          boolean isAddTitleScreen=false;
43          if (fieldConversion.containsKey("invoiceNbr")) {
44              isAddTitleScreen=true;
45              for (Map.Entry<String, String> mapEntry : searchCriteria.entrySet()) {
46                  if (StringUtils.isNotEmpty(mapEntry.getValue())) {
47                      if (mapEntry.getKey().equalsIgnoreCase("invoiceNbr")) {
48                          searchDocumentMap.put(OleSelectConstant.InvoiceSearch.INV_NUMBER, mapEntry.getValue());
49                      } else {
50                          searchDocumentMap.put(mapEntry.getKey(), mapEntry.getValue());
51                      }
52                  }
53              }
54          } else {
55              for (Map.Entry<String, String> mapEntry : searchCriteria.entrySet()) {
56                  if (StringUtils.isNotEmpty(mapEntry.getValue())) {
57                      searchDocumentMap.put(mapEntry.getKey(), mapEntry.getValue());
58                  }
59              }
60          }
61          OLEInvoiceSearchService oleInvoiceSearchService=new OLEInvoiceSearchService();
62          try {
63              oleInvoiceDocuments= oleInvoiceSearchService.searchResults(searchDocumentMap);
64          } catch (Exception e) {
65              e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
66          }
67          if(isAddTitleScreen){
68              for(OLEInvoiceSearchDocument oleInvoiceSearchDocument:oleInvoiceDocuments){
69                   if(oleInvoiceSearchDocument.getDocumentStatus().equalsIgnoreCase("Initiated")){
70                       oleInvoiceDocumentsForTitle.add(oleInvoiceSearchDocument);
71                   }
72              }
73              return oleInvoiceDocumentsForTitle;
74          }
75          return oleInvoiceDocuments;
76      }
77  }