View Javadoc
1   package org.kuali.ole.select.lookup;
2   
3   import org.kuali.ole.select.bo.OLEInvoiceBo;
4   import org.kuali.ole.select.document.OleInvoiceDocument;
5   import org.kuali.ole.sys.context.SpringContext;
6   import org.kuali.rice.core.api.datetime.DateTimeService;
7   import org.kuali.rice.krad.lookup.LookupableImpl;
8   import org.kuali.rice.krad.service.KRADServiceLocator;
9   import org.kuali.rice.krad.web.form.LookupForm;
10  
11  import java.sql.*;
12  import java.text.DateFormat;
13  import java.text.ParseException;
14  import java.text.SimpleDateFormat;
15  import java.util.*;
16  import java.util.Date;
17  
18  public class OLEInvoiceLookupableImpl extends LookupableImpl {
19      /*@Override
20      protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
21          List<OleInvoiceDocument> oleInvoiceDocuments=new ArrayList<OleInvoiceDocument>();
22          if(searchCriteria.size()==0){
23              oleInvoiceDocuments =(List<OleInvoiceDocument>) KRADServiceLocator.getBusinessObjectService().findAll(OleInvoiceDocument.class);
24          } else{
25              oleInvoiceDocuments=(List<OleInvoiceDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OleInvoiceDocument.class, searchCriteria);
26          }
27          List<OLEInvoiceBo> searchResults=new ArrayList<OLEInvoiceBo>();
28          for(OleInvoiceDocument oleInvoiceDocument:oleInvoiceDocuments){
29             OLEInvoiceBo oleInvoiceBo=new OLEInvoiceBo();
30              oleInvoiceBo.setInvoiceDate(oleInvoiceDocument.getInvoiceDate());
31              oleInvoiceBo.setInvoiceNumber(oleInvoiceDocument.getInvoiceNumber());
32              searchResults.add(oleInvoiceBo);
33          }
34          sortSearchResults(form, searchResults);
35          return searchResults;
36      }*/
37      @Override
38      public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) {
39          Map<String, Object> map = new HashMap<String, Object>();
40  
41          for (Map.Entry<String, String> entry : searchCriteria.entrySet()) {
42              if (!entry.getValue().equals("") && entry.getValue() != null) {
43  
44                  if (entry.getKey().equals("invoiceDate")) {
45                      DateFormat sourceFormat = new SimpleDateFormat("MM/dd/yyyy");
46                      try {
47                          java.util.Date date = sourceFormat.parse(entry.getValue().toString());
48                          Timestamp timestamp = new Timestamp(date.getTime());
49                          map.put(entry.getKey(), timestamp);
50                      } catch (ParseException e) {
51                          e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
52                      }
53                  } else {
54                      map.put(entry.getKey(), entry.getValue());
55                  }
56              }
57  
58          }
59          List<OleInvoiceDocument> oleInvoiceDocuments = new ArrayList<OleInvoiceDocument>();
60          if (map.size() == 0) {
61              oleInvoiceDocuments = (List<OleInvoiceDocument>) KRADServiceLocator.getBusinessObjectService().findAll(OleInvoiceDocument.class);
62          } else {
63              oleInvoiceDocuments = (List<OleInvoiceDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OleInvoiceDocument.class, map);
64          }
65          List<OLEInvoiceBo> searchResults = new ArrayList<OLEInvoiceBo>();
66          for (OleInvoiceDocument oleInvoiceDocument : oleInvoiceDocuments) {
67              if (oleInvoiceDocument.getIsSaved()) {
68                  OLEInvoiceBo oleInvoiceBo = new OLEInvoiceBo();
69                  oleInvoiceBo.setInvoiceDate(oleInvoiceDocument.getInvoiceDate());
70                  oleInvoiceBo.setInvoiceNbr(oleInvoiceDocument.getPurapDocumentIdentifier().toString());
71                  oleInvoiceBo.setInvoiceNumber(oleInvoiceDocument.getInvoiceNumber());
72                  oleInvoiceBo.setDocumentNumber(oleInvoiceDocument.getDocumentNumber());
73                  searchResults.add(oleInvoiceBo);
74              }
75          }
76          sortSearchResults(form, searchResults);
77          return searchResults;
78      }
79  }