View Javadoc
1   package org.kuali.ole.deliver.lookup;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.deliver.bo.OlePatronIngestSummaryRecord;
5   import org.kuali.rice.krad.lookup.LookupableImpl;
6   import org.kuali.rice.krad.util.GlobalVariables;
7   import org.kuali.rice.krad.util.KRADConstants;
8   import org.kuali.rice.krad.web.form.LookupForm;
9   
10  import java.sql.Timestamp;
11  import java.text.SimpleDateFormat;
12  import java.util.ArrayList;
13  import java.util.List;
14  import java.util.Map;
15  
16  /**
17   * OlePatronIngestReportsLookupableImpl makes validation  and populate the search criteria and return the search results
18   */
19  public class OlePatronIngestReportsLookupableImpl extends LookupableImpl {
20      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePatronIngestReportsLookupableImpl.class);
21  
22  
23      /**
24       * This method will populate the search criteria and return the search results
25       *
26       * @param form
27       * @param searchCriteria
28       * @param unbounded
29       * @return searchResults(list)
30       */
31      @Override
32      protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
33          LOG.debug("Inside getSearchResults()");
34          List<?> searchResults;
35          List<OlePatronIngestSummaryRecord> finalSearchResult = new ArrayList<OlePatronIngestSummaryRecord>();
36          List<OlePatronIngestSummaryRecord> olePatronIngestSummaryRecords = new ArrayList<OlePatronIngestSummaryRecord>();
37  
38          String dateField = searchCriteria.get(OLEConstants.OlePatronIngestLoadReport.CREATED_DATE);
39          if (dateField != null && !dateField.equals("")) {
40              searchCriteria.remove(OLEConstants.OlePatronIngestLoadReport.CREATED_DATE);
41              String dateFieldOld = "";
42              olePatronIngestSummaryRecords = (List<OlePatronIngestSummaryRecord>) super.getSearchResults(form, searchCriteria, unbounded);
43              for (OlePatronIngestSummaryRecord olePatronIngestSummaryRecord : olePatronIngestSummaryRecords) {
44                  if (olePatronIngestSummaryRecord.getCreatedDate() != null) {
45                      Timestamp dateOnly = olePatronIngestSummaryRecord.getCreatedDate();
46                      SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.OlePatronIngestLoadReport.CREATED_DATE_FORMAT);
47                      String datestr = sdf.format(dateOnly);
48                      if (datestr.equals(dateField)) {
49                          finalSearchResult.add(olePatronIngestSummaryRecord);
50                      }
51                  }
52              }
53              searchCriteria.put(OLEConstants.OlePatronIngestLoadReport.CREATED_DATE, dateField);
54          } else {
55              olePatronIngestSummaryRecords = (List<OlePatronIngestSummaryRecord>) super.getSearchResults(form, searchCriteria, unbounded);
56              finalSearchResult.addAll(olePatronIngestSummaryRecords);
57          }
58          searchResults = finalSearchResult;
59          if (searchResults.size() == 0) {
60              GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
61          }
62  
63          sortSearchResults(form, searchResults);
64  
65          return searchResults;
66      }
67  
68  }