View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.pdp.dataaccess.impl;
20  
21  import java.math.BigDecimal;
22  import java.util.ArrayList;
23  import java.util.Iterator;
24  import java.util.List;
25  
26  import org.apache.ojb.broker.query.Criteria;
27  import org.apache.ojb.broker.query.QueryByCriteria;
28  import org.apache.ojb.broker.query.QueryFactory;
29  import org.apache.ojb.broker.query.ReportQueryByCriteria;
30  import org.kuali.kfs.pdp.PdpConstants;
31  import org.kuali.kfs.pdp.PdpPropertyConstants;
32  import org.kuali.kfs.pdp.businessobject.PaymentGroup;
33  import org.kuali.kfs.pdp.dataaccess.PaymentGroupDao;
34  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
35  
36  public class PaymentGroupDaoOjb extends PlatformAwareDaoBaseOjb implements PaymentGroupDao {
37      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PaymentGroupDaoOjb.class);
38  
39      
40      public PaymentGroupDaoOjb() {
41          super();
42      }
43  
44      /**
45       * @see org.kuali.kfs.pdp.dataaccess.PaymentGroupDao#getDisbursementNumbersByDisbursementType(java.lang.Integer, java.lang.String)
46       */
47      public List<Integer> getDisbursementNumbersByDisbursementType(Integer pid,String disbursementType) {
48          LOG.debug("getDisbursementNumbersByDisbursementType() started");
49  
50          List<Integer> results = new ArrayList<Integer>();
51  
52          Criteria criteria = new Criteria();
53          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PROCESS_ID, pid);
54          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_TYPE_CODE, disbursementType);
55  
56          String[] fields = new String[] { PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_NBR };
57  
58          ReportQueryByCriteria rq = QueryFactory.newReportQuery(PaymentGroup.class, fields, criteria, true);
59          rq.addOrderBy(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_NBR, true);
60  
61          Iterator i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(rq);
62          while ( i.hasNext() ) {
63              Object[] data = (Object[])i.next();
64              BigDecimal d = (BigDecimal)data[0];
65              results.add( new Integer(d.intValue()) );
66          }
67          return results;
68      }
69      
70      /**
71       * @see org.kuali.kfs.pdp.dataaccess.PaymentGroupDao#getDisbursementNumbersByDisbursementType(java.lang.Integer, java.lang.String, java.lang.String)
72       */
73      public List<Integer> getDisbursementNumbersByDisbursementTypeAndBankCode(Integer pid, String disbursementType, String bankCode) {
74          if (LOG.isDebugEnabled()) {
75              LOG.debug("getDisbursementNumbersByDisbursementType() started");
76          }
77  
78          List<Integer> results = new ArrayList<Integer>();
79  
80          Criteria criteria = new Criteria();
81          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PROCESS_ID, pid);
82          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_TYPE_CODE, disbursementType);
83          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BANK_CODE, bankCode);
84  
85          String[] fields = new String[] { PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_NBR };
86  
87          ReportQueryByCriteria rq = QueryFactory.newReportQuery(PaymentGroup.class, fields, criteria, true);
88          rq.addOrderBy(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_NBR, true);
89  
90          Iterator i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(rq);
91          while ( i.hasNext() ) {
92              Object[] data = (Object[])i.next();
93              BigDecimal d = (BigDecimal)data[0];
94              results.add( new Integer(d.intValue()) );
95          }
96          return results;
97      }
98  
99      /**
100      * Given a process id and a disbursement type, finds a distinct list of bank codes used by payment groups within that payment process
101      * @param pid payment process to query payment groups of
102      * @param disbursementType the type of disbursements to query
103      * @return a sorted List of bank codes
104      */
105     public List<String> getDistinctBankCodesForProcessAndType(Integer pid, String disbursementType) {
106         List<String> results = new ArrayList<String>();
107         
108         Criteria criteria = new Criteria();
109         criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PROCESS_ID, pid);
110         criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_TYPE_CODE, disbursementType);
111 
112         String[] fields = new String[] { PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BANK_CODE };
113         
114         ReportQueryByCriteria rq = QueryFactory.newReportQuery(PaymentGroup.class, fields, criteria, true);
115         rq.addOrderBy(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BANK_CODE, true);
116         
117         Iterator iter = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(rq);
118         while (iter.hasNext()) {
119             final Object[] row = (Object[])iter.next();
120             final String bankCode = (String)row[0];
121         
122             results.add(bankCode);
123         }
124         
125         return results;
126     }
127 
128     /**
129      * @see org.kuali.kfs.pdp.dataaccess.PaymentGroupDao#getAchPaymentsNeedingAdviceNotification()
130      */
131     public List<PaymentGroup> getAchPaymentsNeedingAdviceNotification() {
132         LOG.debug("getAchPaymentsNeedingAdviceNotification() started");
133 
134         Criteria criteria = new Criteria();
135         criteria.addEqualTo(PdpPropertyConstants.PAYMENT_STATUS_CODE, PdpConstants.PaymentStatusCodes.EXTRACTED);
136         criteria.addEqualTo(PdpPropertyConstants.DISBURSEMENT_TYPE_CODE, PdpConstants.DisbursementTypeCodes.ACH);
137         criteria.addIsNull(PdpPropertyConstants.ADVICE_EMAIL_SENT_DATE);
138 
139         return (List<PaymentGroup>) getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(PaymentGroup.class, criteria));
140     }
141  
142 }
143