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  /*
17   * Created on Aug 11, 2004
18   *
19   */
20  package org.kuali.ole.pdp.dataaccess.impl;
21  
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.QueryFactory;
28  import org.apache.ojb.broker.query.ReportQueryByCriteria;
29  import org.kuali.ole.pdp.PdpConstants.PaymentStatusCodes;
30  import org.kuali.ole.pdp.PdpPropertyConstants;
31  import org.kuali.ole.pdp.businessobject.PaymentGroup;
32  import org.kuali.ole.pdp.businessobject.PaymentStatus;
33  import org.kuali.ole.pdp.dataaccess.BatchMaintenanceDao;
34  import org.kuali.ole.sys.util.TransactionalServiceUtils;
35  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
36  import org.kuali.rice.krad.util.ObjectUtils;
37  
38  
39  /**
40   * 
41   */
42  public class BatchMaintenanceDaoOjb extends PlatformAwareDaoBaseOjb implements BatchMaintenanceDao {
43      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BatchMaintenanceDaoOjb.class);
44  
45      public BatchMaintenanceDaoOjb() {
46          super();
47      }
48  
49      /**
50       * doBatchPaymentsHaveOpenStatus() Return true if all payments in batch have an 'OPEN' status. Return false if all payments in
51       * batch do not have an 'OPEN' status. The query in this method searches the payment detail table for payments of the given
52       * batchId where the status equals any status other than 'OPEN'. If any rows exist with a status other than 'OPEN', return
53       * false.
54       * 
55       * @param batchId Integer value of batch id of payments to search.
56       * @return boolean true = all payments are 'OPEN'; false = all payments are not 'OPEN'
57       * @see org.kuali.ole.pdp.dataaccess.BatchMaintenanceDao#doBatchPaymentsHaveOpenStatus(java.lang.Integer, java.util.List,
58       *      java.util.List)
59       */
60      public boolean doBatchPaymentsHaveOpenStatus(Integer batchId, List batchPayments, List statusList) {
61          LOG.debug("doBatchPaymentsHaveOpenStatus() enter method.");
62          List codeList = new ArrayList();
63  
64          if (ObjectUtils.isNull(batchPayments) || batchPayments.isEmpty()) {
65              return false;
66          }
67  
68          for (Iterator i = statusList.iterator(); i.hasNext();) {
69              PaymentStatus element = (PaymentStatus) i.next();
70              if (!(element.getCode().equals(PaymentStatusCodes.OPEN))) {
71                  codeList.add(element.getCode());
72              }
73          }
74  
75          Criteria crit = new Criteria();
76          crit.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BATCH_ID, batchId);
77          crit.addIn(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE, codeList);
78  
79          ReportQueryByCriteria q = QueryFactory.newReportQuery(PaymentGroup.class, crit);
80          q.setAttributes(new String[] { PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE });
81          q.addGroupBy(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE);
82  
83          Iterator i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
84          if (i.hasNext()) {
85              LOG.debug("doBatchPaymentsHaveOpenStatus() Not all payment groups have status 'OPEN'.");
86              TransactionalServiceUtils.exhaustIterator(i);
87              return false;
88          }
89          else {
90              LOG.debug("doBatchPaymentsHaveOpenStatus() All payment groups have status 'OPEN'.");
91              return true;
92          }
93      }
94  
95      /**
96       * doBatchPaymentsHaveHeldStatus() Return true if all payments in batch have an 'HELD' status. Return false if all payments in
97       * batch do not have an 'HELD' status. The query in this method searches the payment detail table for payments of the given
98       * batchId where the status equals any status other than 'HELD'. If any rows exist with a status other than 'HELD', return
99       * false.
100      * 
101      * @param batchId Integer value of batch id of payments to search.
102      * @return boolean true = all payments are 'HELD'; false = all payments are not 'HELD'
103      * @see org.kuali.ole.pdp.dataaccess.BatchMaintenanceDao#doBatchPaymentsHaveHeldStatus(java.lang.Integer, java.util.List,
104      *      java.util.List)
105      */
106     public boolean doBatchPaymentsHaveHeldStatus(Integer batchId, List batchPayments, List statusList) {
107         LOG.debug("doBatchPaymentsHaveHeldStatus() enter method.");
108 
109         if (ObjectUtils.isNull(batchPayments) || batchPayments.isEmpty()) {
110             return false;
111         }
112 
113         List codeList = new ArrayList();
114 
115         for (Iterator i = statusList.iterator(); i.hasNext();) {
116             PaymentStatus element = (PaymentStatus) i.next();
117             if (!(element.getCode().equals(PaymentStatusCodes.HELD_CD))) {
118                 codeList.add(element.getCode());
119             }
120         }
121 
122         Criteria crit = new Criteria();
123         crit.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BATCH_ID, batchId);
124         crit.addIn(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE, codeList);
125 
126         ReportQueryByCriteria q = QueryFactory.newReportQuery(PaymentGroup.class, crit);
127         q.setAttributes(new String[] { PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE });
128         q.addGroupBy(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE);
129 
130         Iterator i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
131         if (i.hasNext()) {
132             LOG.debug("doBatchPaymentsHaveHeldStatus() Not all payment groups have status 'HELD'.");
133             TransactionalServiceUtils.exhaustIterator(i);
134             return false;
135         }
136         else {
137             LOG.debug("doBatchPaymentsHaveHeldStatus() All payment groups have status 'HELD'.");
138             return true;
139         }
140     }
141 }