View Javadoc
1   package org.kuali.ole.deliver.service;
2   
3   import org.kuali.rice.core.api.config.property.ConfigContext;
4   import org.kuali.rice.core.api.datetime.DateTimeService;
5   import org.kuali.rice.core.framework.persistence.jdbc.dao.PlatformAwareDaoBaseJdbc;
6   
7   import java.sql.Date;
8   import java.sql.SQLException;
9   import java.sql.Statement;
10  import java.text.ParseException;
11  import java.util.*;
12  
13  /**
14   * Created by pvsubrah on 3/31/15.
15   */
16  public class LoanWithNoticesDAO extends PlatformAwareDaoBaseJdbc {
17  
18      private DateTimeService dateTimeService;
19  
20      public List<String> getLoanIdsForOverudeNotices(String noticeToSendDate,String noticeType) {
21          String date = null;
22          String query = null;
23          String dbVendor = getProperty("db.vendor");
24          if (dbVendor.equals("mysql")) {
25              StringBuffer stringBuffer = new StringBuffer();
26              String formattedDateForMySQL = null == noticeToSendDate ? "curdate()" : stringBuffer
27                      .append("str_to_date(")
28                      .append(formatDateForMySQL(noticeToSendDate))
29                      .append(")")
30                      .toString();
31              query = "select loan_tran_id from ole_dlvr_loan_t where loan_tran_id in (select loan_id from " +
32                      "ole_dlvr_loan_notice_t where ntc_typ='"+noticeType+"' and ntc_to_snd_dt < " +
33                      formattedDateForMySQL + ")";
34          } else {
35              StringBuffer stringBuffer = new StringBuffer();
36              String formatDateForOracle = null == noticeToSendDate ? "sysdate" : stringBuffer.append("'")
37              .append(formatDateForOracle
38                      (noticeToSendDate))
39                      .append("'")
40                      .toString();
41              query = "select loan_tran_id from ole_dlvr_loan_t where loan_tran_id in (select loan_id from ole_dlvr_loan_notice_t where ntc_typ='"+noticeType+"' and ntc_to_snd_dt < " + formatDateForOracle + ")";
42          }
43          List loanIds = new ArrayList();
44          List<Map<String, Object>> queryForList = executeQuery(query);
45          for (Iterator<Map<String, Object>> iterator = queryForList.iterator(); iterator.hasNext(); ) {
46              Map<String, Object> next = iterator.next();
47              Object loan_id = next.get("loan_tran_id");
48              String loanId = loan_id.toString();
49              loanIds.add(loanId);
50          }
51          return loanIds;
52      }
53  
54      protected List<Map<String, Object>> executeQuery(String query) {
55          return getSimpleJdbcTemplate().queryForList(query);
56      }
57  
58      protected String getProperty(String property) {
59          return ConfigContext.getCurrentContextConfig().getProperty(property);
60      }
61  
62      private String formatDateForOracle(String overdueNoticeToDate) {
63          String forOracle = DateFormatHelper.getInstance().generateDateStringsForOracle(overdueNoticeToDate);
64          return forOracle;
65      }
66  
67      private String formatDateForMySQL(String overdueNoticeToDate) {
68          String forMySQL = DateFormatHelper.getInstance().generateDateStringsForMySQL(overdueNoticeToDate);
69          return forMySQL;
70      }
71  
72  
73      public void setDateTimeService(DateTimeService dateTimeService) {
74          this.dateTimeService = dateTimeService;
75      }
76  
77      public DateTimeService getDateTimeService() {
78          return dateTimeService;
79      }
80  }