View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.pdp.dataaccess.impl;
17  
18  import java.math.BigDecimal;
19  import java.util.ArrayList;
20  import java.util.Iterator;
21  import java.util.List;
22  
23  import org.apache.ojb.broker.query.Criteria;
24  import org.apache.ojb.broker.query.QueryByCriteria;
25  import org.apache.ojb.broker.query.QueryFactory;
26  import org.apache.ojb.broker.query.ReportQueryByCriteria;
27  import org.kuali.ole.pdp.PdpConstants;
28  import org.kuali.ole.pdp.PdpPropertyConstants;
29  import org.kuali.ole.pdp.businessobject.PaymentGroup;
30  import org.kuali.ole.pdp.dataaccess.PaymentGroupDao;
31  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
32  
33  public class PaymentGroupDaoOjb extends PlatformAwareDaoBaseOjb implements PaymentGroupDao {
34      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PaymentGroupDaoOjb.class);
35  
36      
37      public PaymentGroupDaoOjb() {
38          super();
39      }
40  
41      /**
42       * @see org.kuali.ole.pdp.dataaccess.PaymentGroupDao#getDisbursementNumbersByDisbursementType(java.lang.Integer, java.lang.String)
43       */
44      public List<Integer> getDisbursementNumbersByDisbursementType(Integer pid,String disbursementType) {
45          LOG.debug("getDisbursementNumbersByDisbursementType() started");
46  
47          List<Integer> results = new ArrayList<Integer>();
48  
49          Criteria criteria = new Criteria();
50          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PROCESS_ID, pid);
51          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_TYPE_CODE, disbursementType);
52  
53          String[] fields = new String[] { PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_NBR };
54  
55          ReportQueryByCriteria rq = QueryFactory.newReportQuery(PaymentGroup.class, fields, criteria, true);
56          rq.addOrderBy(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_NBR, true);
57  
58          Iterator i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(rq);
59          while ( i.hasNext() ) {
60              Object[] data = (Object[])i.next();
61              BigDecimal d = (BigDecimal)data[0];
62              results.add( new Integer(d.intValue()) );
63          }
64          return results;
65      }
66      
67      /**
68       * @see org.kuali.ole.pdp.dataaccess.PaymentGroupDao#getDisbursementNumbersByDisbursementType(java.lang.Integer, java.lang.String, java.lang.String)
69       */
70      public List<Integer> getDisbursementNumbersByDisbursementTypeAndBankCode(Integer pid, String disbursementType, String bankCode) {
71          if (LOG.isDebugEnabled()) {
72              LOG.debug("getDisbursementNumbersByDisbursementType() started");
73          }
74  
75          List<Integer> results = new ArrayList<Integer>();
76  
77          Criteria criteria = new Criteria();
78          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PROCESS_ID, pid);
79          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_TYPE_CODE, disbursementType);
80          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BANK_CODE, bankCode);
81  
82          String[] fields = new String[] { PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_NBR };
83  
84          ReportQueryByCriteria rq = QueryFactory.newReportQuery(PaymentGroup.class, fields, criteria, true);
85          rq.addOrderBy(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_NBR, true);
86  
87          Iterator i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(rq);
88          while ( i.hasNext() ) {
89              Object[] data = (Object[])i.next();
90              BigDecimal d = (BigDecimal)data[0];
91              results.add( new Integer(d.intValue()) );
92          }
93          return results;
94      }
95  
96      /**
97       * Given a process id and a disbursement type, finds a distinct list of bank codes used by payment groups within that payment process
98       * @param pid payment process to query payment groups of
99       * @param disbursementType the type of disbursements to query
100      * @return a sorted List of bank codes
101      */
102     public List<String> getDistinctBankCodesForProcessAndType(Integer pid, String disbursementType) {
103         List<String> results = new ArrayList<String>();
104         
105         Criteria criteria = new Criteria();
106         criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PROCESS_ID, pid);
107         criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_TYPE_CODE, disbursementType);
108 
109         String[] fields = new String[] { PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BANK_CODE };
110         
111         ReportQueryByCriteria rq = QueryFactory.newReportQuery(PaymentGroup.class, fields, criteria, true);
112         rq.addOrderBy(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BANK_CODE, true);
113         
114         Iterator iter = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(rq);
115         while (iter.hasNext()) {
116             final Object[] row = (Object[])iter.next();
117             final String bankCode = (String)row[0];
118         
119             results.add(bankCode);
120         }
121         
122         return results;
123     }
124 
125     /**
126      * @see org.kuali.ole.pdp.dataaccess.PaymentGroupDao#getAchPaymentsNeedingAdviceNotification()
127      */
128     public List<PaymentGroup> getAchPaymentsNeedingAdviceNotification() {
129         LOG.debug("getAchPaymentsNeedingAdviceNotification() started");
130 
131         Criteria criteria = new Criteria();
132         criteria.addEqualTo(PdpPropertyConstants.PAYMENT_STATUS_CODE, PdpConstants.PaymentStatusCodes.EXTRACTED);
133         criteria.addEqualTo(PdpPropertyConstants.DISBURSEMENT_TYPE_CODE, PdpConstants.DisbursementTypeCodes.ACH);
134         criteria.addIsNull(PdpPropertyConstants.ADVICE_EMAIL_SENT_DATE);
135 
136         return (List<PaymentGroup>) getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(PaymentGroup.class, criteria));
137     }
138  
139 }
140