001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.pdp.dao.ojb;
017:
018: import java.sql.Timestamp;
019: import java.util.ArrayList;
020: import java.util.Calendar;
021: import java.util.Date;
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import org.apache.ojb.broker.query.Criteria;
026: import org.apache.ojb.broker.query.QueryByCriteria;
027: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
028: import org.kuali.module.pdp.PdpConstants;
029: import org.kuali.module.pdp.bo.CustomerProfile;
030: import org.kuali.module.pdp.bo.PaymentGroup;
031: import org.kuali.module.pdp.bo.PaymentProcess;
032: import org.kuali.module.pdp.bo.PaymentStatus;
033: import org.kuali.module.pdp.dao.FormatPaymentDao;
034: import org.kuali.module.pdp.service.ReferenceService;
035:
036: public class FormatPaymentDaoOjb extends PlatformAwareDaoBaseOjb
037: implements FormatPaymentDao {
038: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
039: .getLogger(FormatPaymentDaoOjb.class);
040:
041: private ReferenceService referenceService;
042:
043: public void markPaymentsForFormat(PaymentProcess proc,
044: List customers, Date paydate, boolean immediate,
045: String paymentTypes) {
046: LOG.debug("markPaymentsForFormat() started");
047:
048: Timestamp now = new Timestamp((new Date()).getTime());
049: java.sql.Date sqlDate = new java.sql.Date(paydate.getTime());
050: Calendar c = Calendar.getInstance();
051: c.setTime(sqlDate);
052: c.set(Calendar.HOUR, 11);
053: c.set(Calendar.MINUTE, 59);
054: c.set(Calendar.SECOND, 59);
055: c.set(Calendar.MILLISECOND, 59);
056: c.set(Calendar.AM_PM, Calendar.PM);
057: Timestamp paydateTs = new Timestamp(c.getTime().getTime());
058:
059: LOG.debug("markPaymentsForFormat() last update = " + now);
060: LOG.debug("markPaymentsForFormat() entered paydate = "
061: + paydate);
062: LOG.debug("markPaymentsForFormat() actual paydate = "
063: + paydateTs);
064:
065: PaymentStatus format = (PaymentStatus) referenceService
066: .getCode("PaymentStatus",
067: PdpConstants.PaymentStatusCodes.FORMAT);
068:
069: List customerIds = new ArrayList();
070: for (Iterator iter = customers.iterator(); iter.hasNext();) {
071: CustomerProfile element = (CustomerProfile) iter.next();
072: customerIds.add(element.getId());
073: }
074:
075: Criteria criteria = new Criteria();
076: criteria.addIn("batch.customerId", customerIds);
077: criteria.addEqualTo("paymentStatusCode",
078: PdpConstants.PaymentStatusCodes.OPEN);
079:
080: if ("SY".equals(paymentTypes)) {
081: // special handling only
082: criteria.addEqualTo("pymtSpecialHandling", Boolean.TRUE);
083: } else if ("SN".equals(paymentTypes)) {
084: // no special handling only
085: criteria.addEqualTo("pymtSpecialHandling", Boolean.FALSE);
086: } else if ("AY".equals(paymentTypes)) {
087: // attachments only
088: criteria.addEqualTo("pymtAttachment", Boolean.TRUE);
089: } else if ("AN".equals(paymentTypes)) {
090: // no attachments only
091: criteria.addEqualTo("pymtAttachment", Boolean.FALSE);
092: }
093:
094: if (immediate) {
095: criteria.addEqualTo("processImmediate", Boolean.TRUE);
096: } else {
097: // (Payment date <= usePaydate OR immediate = TRUE)
098: Criteria criteria1 = new Criteria();
099: criteria1.addEqualTo("processImmediate", Boolean.TRUE);
100:
101: Criteria criteria2 = new Criteria();
102: criteria2.addLessOrEqualThan("paymentDate", paydateTs);
103: criteria1.addOrCriteria(criteria2);
104:
105: criteria.addAndCriteria(criteria1);
106: }
107:
108: Iterator groupIterator = getPersistenceBrokerTemplate()
109: .getIteratorByQuery(
110: new QueryByCriteria(PaymentGroup.class,
111: criteria));
112: while (groupIterator.hasNext()) {
113: PaymentGroup paymentGroup = (PaymentGroup) groupIterator
114: .next();
115: paymentGroup.setLastUpdate(paydateTs);
116: paymentGroup.setPaymentStatus(format);
117: paymentGroup.setProcess(proc);
118: getPersistenceBrokerTemplate().store(paymentGroup);
119: }
120: }
121:
122: public void unmarkPaymentsForFormat(PaymentProcess proc) {
123: LOG.debug("unmarkPaymentsForFormat() started");
124:
125: Timestamp now = new Timestamp((new Date()).getTime());
126:
127: PaymentStatus openStatus = (PaymentStatus) referenceService
128: .getCode("PaymentStatus",
129: PdpConstants.PaymentStatusCodes.OPEN);
130:
131: Criteria criteria = new Criteria();
132: criteria.addEqualTo("processId", proc.getId());
133: criteria.addEqualTo("paymentStatusCode",
134: PdpConstants.PaymentStatusCodes.FORMAT);
135:
136: Iterator groupIterator = getPersistenceBrokerTemplate()
137: .getIteratorByQuery(
138: new QueryByCriteria(PaymentGroup.class,
139: criteria));
140: while (groupIterator.hasNext()) {
141: PaymentGroup paymentGroup = (PaymentGroup) groupIterator
142: .next();
143: paymentGroup.setLastUpdate(now);
144: paymentGroup.setPaymentStatus(openStatus);
145: getPersistenceBrokerTemplate().store(paymentGroup);
146: }
147: }
148:
149: public void setReferenceService(ReferenceService referenceService) {
150: this.referenceService = referenceService;
151: }
152: }
|