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: /*
017: * Created on Aug 11, 2004
018: *
019: */
020: package org.kuali.module.pdp.dao.ojb;
021:
022: import java.util.ArrayList;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: import org.apache.ojb.broker.query.Criteria;
027: import org.apache.ojb.broker.query.QueryFactory;
028: import org.apache.ojb.broker.query.ReportQueryByCriteria;
029: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
030: import org.kuali.core.util.TransactionalServiceUtils;
031: import org.kuali.module.pdp.bo.PaymentGroup;
032: import org.kuali.module.pdp.bo.PaymentStatus;
033: import org.kuali.module.pdp.dao.BatchMaintenanceDao;
034: import org.kuali.module.pdp.service.ReferenceService;
035:
036: /**
037: * @author delyea
038: */
039: public class BatchMaintenanceDaoOjb extends PlatformAwareDaoBaseOjb
040: implements BatchMaintenanceDao {
041: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
042: .getLogger(BatchMaintenanceDaoOjb.class);
043: private ReferenceService referenceService;
044:
045: public BatchMaintenanceDaoOjb() {
046: super ();
047: }
048:
049: public void setReferenceService(ReferenceService ref) {
050: referenceService = ref;
051: }
052:
053: /**
054: * doBatchPaymentsHaveOpenStatus() Return true if all payments in batch have an 'OPEN' status. Return false if all payments in
055: * batch do not have an 'OPEN' status. The query in this method searches the payment detail table for payments of the given
056: * batchId where the status equals any status other than 'OPEN'. If any rows exist with a status other than 'OPEN', return
057: * false.
058: *
059: * @param batchId Integer value of batch id of payments to search.
060: * @return boolean true = all payments are 'OPEN'; false = all payments are not 'OPEN'
061: */
062: public boolean doBatchPaymentsHaveOpenStatus(Integer batchId) {
063: LOG.debug("doBatchPaymentsHaveOpenStatus() enter method.");
064: List codeList = new ArrayList();
065: List statusList = referenceService.getAll("PaymentStatus");
066: for (Iterator i = statusList.iterator(); i.hasNext();) {
067: PaymentStatus element = (PaymentStatus) i.next();
068: if (!(element.getCode().equals("OPEN"))) {
069: codeList.add(element.getCode());
070: }
071: }
072:
073: Criteria crit = new Criteria();
074: crit.addEqualTo("batchId", batchId);
075: crit.addIn("paymentStatusCode", codeList);
076:
077: ReportQueryByCriteria q = QueryFactory.newReportQuery(
078: PaymentGroup.class, crit);
079: q.setAttributes(new String[] { "paymentStatusCode" });
080: q.addGroupBy("paymentStatusCode");
081:
082: Iterator i = getPersistenceBrokerTemplate()
083: .getReportQueryIteratorByQuery(q);
084: if (i.hasNext()) {
085: LOG
086: .debug("doBatchPaymentsHaveOpenStatus() Not all payment groups have status 'OPEN'.");
087: TransactionalServiceUtils.exhaustIterator(i);
088: return false;
089: } else {
090: LOG
091: .debug("doBatchPaymentsHaveOpenStatus() All payment groups have status 'OPEN'.");
092: return true;
093: }
094: }// end doBatchPaymentsHaveOpenStatus()
095:
096: /**
097: * doBatchPaymentsHaveHeldStatus() Return true if all payments in batch have an 'HELD' status. Return false if all payments in
098: * batch do not have an 'HELD' status. The query in this method searches the payment detail table for payments of the given
099: * batchId where the status equals any status other than 'HELD'. If any rows exist with a status other than 'HELD', return
100: * false.
101: *
102: * @param batchId Integer value of batch id of payments to search.
103: * @return boolean true = all payments are 'HELD'; false = all payments are not 'HELD'
104: */
105: public boolean doBatchPaymentsHaveHeldStatus(Integer batchId) {
106: LOG.debug("doBatchPaymentsHaveHeldStatus() enter method.");
107: List codeList = new ArrayList();
108: List statusList = referenceService.getAll("PaymentStatus");
109: for (Iterator i = statusList.iterator(); i.hasNext();) {
110: PaymentStatus element = (PaymentStatus) i.next();
111: if (!(element.getCode().equals("HELD"))) {
112: codeList.add(element.getCode());
113: }
114: }
115:
116: Criteria crit = new Criteria();
117: crit.addEqualTo("batchId", batchId);
118: crit.addIn("paymentStatusCode", codeList);
119:
120: ReportQueryByCriteria q = QueryFactory.newReportQuery(
121: PaymentGroup.class, crit);
122: q.setAttributes(new String[] { "paymentStatusCode" });
123: q.addGroupBy("paymentStatusCode");
124:
125: Iterator i = getPersistenceBrokerTemplate()
126: .getReportQueryIteratorByQuery(q);
127: if (i.hasNext()) {
128: LOG
129: .debug("doBatchPaymentsHaveHeldStatus() Not all payment groups have status 'HELD'.");
130: TransactionalServiceUtils.exhaustIterator(i);
131: return false;
132: } else {
133: LOG
134: .debug("doBatchPaymentsHaveHeldStatus() All payment groups have status 'HELD'.");
135: return true;
136: }
137: }// end doBatchPaymentsHaveHeldStatus()
138: }
|