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.sql.Timestamp;
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import org.apache.ojb.broker.query.Criteria;
23  import org.apache.ojb.broker.query.QueryByCriteria;
24  import org.kuali.ole.pdp.PdpConstants;
25  import org.kuali.ole.pdp.PdpPropertyConstants;
26  import org.kuali.ole.pdp.businessobject.PaymentGroup;
27  import org.kuali.ole.pdp.businessobject.PaymentProcess;
28  import org.kuali.ole.pdp.dataaccess.FormatPaymentDao;
29  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30  import org.kuali.rice.krad.service.BusinessObjectService;
31  
32  public class FormatPaymentDaoOjb extends PlatformAwareDaoBaseOjb implements FormatPaymentDao {
33      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(FormatPaymentDaoOjb.class);
34  
35      private BusinessObjectService businessObjectService;
36  
37      /**
38       * @see org.kuali.ole.pdp.dataaccess.FormatPaymentDao#markPaymentsForFormat(org.kuali.ole.pdp.businessobject.PaymentProcess,
39       *      java.util.List, java.util.Date, java.lang.String)
40       */
41      public Iterator markPaymentsForFormat(List customerIds, Timestamp paydateTs, String paymentTypes) {
42          LOG.debug("markPaymentsForFormat() started");
43  
44          Criteria criteria = new Criteria();
45  
46          if (customerIds.size() > 0) {
47              criteria.addIn(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BATCH + "." + PdpPropertyConstants.BatchConstants.CUSTOMER_ID, customerIds);
48          }
49  
50          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE, PdpConstants.PaymentStatusCodes.OPEN);
51  
52          if (PdpConstants.PaymentTypes.DISBURSEMENTS_WITH_SPECIAL_HANDLING.equals(paymentTypes)) {
53              // special handling only
54              criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_SPECIAL_HANDLING, Boolean.TRUE);
55          }
56          else if (PdpConstants.PaymentTypes.DISBURSEMENTS_NO_SPECIAL_HANDLING.equals(paymentTypes)) {
57              // no special handling only
58              criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_SPECIAL_HANDLING, Boolean.FALSE);
59          }
60          else if (PdpConstants.PaymentTypes.DISBURSEMENTS_WITH_ATTACHMENTS.equals(paymentTypes)) {
61              // attachments only
62              criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_ATTACHMENT, Boolean.TRUE);
63          }
64          else if (PdpConstants.PaymentTypes.DISBURSEMENTS_NO_ATTACHMENTS.equals(paymentTypes)) {
65              // no attachments only
66              criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_ATTACHMENT, Boolean.FALSE);
67          }
68  
69          if (PdpConstants.PaymentTypes.PROCESS_IMMEDIATE.equals(paymentTypes)) {
70              criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PROCESS_IMMEDIATE, Boolean.TRUE);
71          }
72          else {
73              // (Payment date <= usePaydate OR immediate = TRUE)
74              Criteria criteria1 = new Criteria();
75              criteria1.addEqualTo(PdpPropertyConstants.PaymentGroup.PROCESS_IMMEDIATE, Boolean.TRUE);
76  
77              Criteria criteria2 = new Criteria();
78              criteria2.addLessOrEqualThan(PdpPropertyConstants.PaymentGroup.PAYMENT_DATE, paydateTs);
79              criteria1.addOrCriteria(criteria2);
80  
81              criteria.addAndCriteria(criteria1);
82          }
83  
84          Iterator groupIterator = getPersistenceBrokerTemplate().getIteratorByQuery(new QueryByCriteria(PaymentGroup.class, criteria));
85          return groupIterator;
86      }
87  
88      /**
89       * @see org.kuali.ole.pdp.dataaccess.FormatPaymentDao#unmarkPaymentsForFormat(org.kuali.ole.pdp.businessobject.PaymentProcess)
90       */
91      public Iterator unmarkPaymentsForFormat(PaymentProcess proc) {
92          LOG.debug("unmarkPaymentsForFormat() started");
93  
94          Criteria criteria = new Criteria();
95          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PROCESS_ID, proc.getId());
96          criteria.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE, PdpConstants.PaymentStatusCodes.FORMAT);
97  
98          Iterator groupIterator = getPersistenceBrokerTemplate().getIteratorByQuery(new QueryByCriteria(PaymentGroup.class, criteria));
99          return groupIterator;
100     }
101 
102     /**
103      * Gets the businessObjectService attribute.
104      * 
105      * @return Returns the KRADServiceLocatorWeb.getLegacyDataAdapter().
106      */
107     public BusinessObjectService getBusinessObjectService() {
108         return businessObjectService;
109     }
110 
111     /**
112      * Sets the businessObjectService attribute value.
113      * 
114      * @param businessObjectService The businessObjectService to set.
115      */
116     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
117         this.businessObjectService = businessObjectService;
118     }
119 
120 }