View Javadoc
1   package org.kuali.ole.describe.lookup;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.describe.bo.OleLocationIngestSummaryRecord;
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   * Created with IntelliJ IDEA.
18   * User: SG7940
19   * Date: 4/18/13
20   * Time: 5:57 PM
21   * To change this template use File | Settings | File Templates.
22   */
23  public class OleLocationSummaryLookupableImpl extends LookupableImpl {
24      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleLocationSummaryLookupableImpl.class);
25  
26      /**
27       * This method will populate the search criteria and return the search results
28       *
29       * @param form
30       * @param searchCriteria
31       * @param unbounded
32       * @return searchResults(list)
33       */
34      @Override
35      protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
36          LOG.debug("Inside getSearchResults()");
37          List<?> searchResults;
38          List<OleLocationIngestSummaryRecord> finalSearchResult = new ArrayList<OleLocationIngestSummaryRecord>();
39          List<OleLocationIngestSummaryRecord> oleLocationIngestSummaryRecords = new ArrayList<OleLocationIngestSummaryRecord>();
40          String dateField = searchCriteria.get(OLEConstants.OleLocationIngestSummaryRecord.DATE);
41          if (dateField != null && !dateField.equals("")) {
42              searchCriteria.remove(OLEConstants.OleLocationIngestSummaryRecord.DATE);
43              oleLocationIngestSummaryRecords = (List<OleLocationIngestSummaryRecord>) super.getSearchResults(form, searchCriteria, unbounded);
44              for (OleLocationIngestSummaryRecord oleLocationIngestSummaryRecord : oleLocationIngestSummaryRecords) {
45                  if (oleLocationIngestSummaryRecord.getDate() != null) {
46                      Timestamp dateOnly = oleLocationIngestSummaryRecord.getDate();
47                      SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.OleLocationIngestSummaryRecord.DATE_FORMAT);
48                      String datestr = sdf.format(dateOnly);
49                      if (datestr.equals(dateField)) {
50                          finalSearchResult.add(oleLocationIngestSummaryRecord);
51                      }
52                  }
53              }
54              searchCriteria.put(OLEConstants.OleLocationIngestSummaryRecord.DATE, dateField);
55          } else {
56              oleLocationIngestSummaryRecords = (List<OleLocationIngestSummaryRecord>) super.getSearchResults(form, searchCriteria, unbounded);
57              finalSearchResult.addAll(oleLocationIngestSummaryRecords);
58          }
59          searchResults = finalSearchResult;
60          if (searchResults.size() == 0) {
61              GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
62          }
63          sortSearchResults(form, searchResults);
64          return searchResults;
65      }
66  }