001/* 002 * Copyright 2007 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.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/ecl2.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 */ 020package org.kuali.ole.pdp.dataaccess.impl; 021 022import java.util.ArrayList; 023import java.util.Iterator; 024import java.util.List; 025 026import org.apache.ojb.broker.query.Criteria; 027import org.apache.ojb.broker.query.QueryFactory; 028import org.apache.ojb.broker.query.ReportQueryByCriteria; 029import org.kuali.ole.pdp.PdpConstants.PaymentStatusCodes; 030import org.kuali.ole.pdp.PdpPropertyConstants; 031import org.kuali.ole.pdp.businessobject.PaymentGroup; 032import org.kuali.ole.pdp.businessobject.PaymentStatus; 033import org.kuali.ole.pdp.dataaccess.BatchMaintenanceDao; 034import org.kuali.ole.sys.util.TransactionalServiceUtils; 035import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; 036import org.kuali.rice.krad.util.ObjectUtils; 037 038 039/** 040 * 041 */ 042public class BatchMaintenanceDaoOjb extends PlatformAwareDaoBaseOjb implements BatchMaintenanceDao { 043 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BatchMaintenanceDaoOjb.class); 044 045 public BatchMaintenanceDaoOjb() { 046 super(); 047 } 048 049 /** 050 * doBatchPaymentsHaveOpenStatus() Return true if all payments in batch have an 'OPEN' status. Return false if all payments in 051 * batch do not have an 'OPEN' status. The query in this method searches the payment detail table for payments of the given 052 * batchId where the status equals any status other than 'OPEN'. If any rows exist with a status other than 'OPEN', return 053 * false. 054 * 055 * @param batchId Integer value of batch id of payments to search. 056 * @return boolean true = all payments are 'OPEN'; false = all payments are not 'OPEN' 057 * @see org.kuali.ole.pdp.dataaccess.BatchMaintenanceDao#doBatchPaymentsHaveOpenStatus(java.lang.Integer, java.util.List, 058 * java.util.List) 059 */ 060 public boolean doBatchPaymentsHaveOpenStatus(Integer batchId, List batchPayments, List statusList) { 061 LOG.debug("doBatchPaymentsHaveOpenStatus() enter method."); 062 List codeList = new ArrayList(); 063 064 if (ObjectUtils.isNull(batchPayments) || batchPayments.isEmpty()) { 065 return false; 066 } 067 068 for (Iterator i = statusList.iterator(); i.hasNext();) { 069 PaymentStatus element = (PaymentStatus) i.next(); 070 if (!(element.getCode().equals(PaymentStatusCodes.OPEN))) { 071 codeList.add(element.getCode()); 072 } 073 } 074 075 Criteria crit = new Criteria(); 076 crit.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BATCH_ID, batchId); 077 crit.addIn(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE, codeList); 078 079 ReportQueryByCriteria q = QueryFactory.newReportQuery(PaymentGroup.class, crit); 080 q.setAttributes(new String[] { PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE }); 081 q.addGroupBy(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE); 082 083 Iterator i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q); 084 if (i.hasNext()) { 085 LOG.debug("doBatchPaymentsHaveOpenStatus() Not all payment groups have status 'OPEN'."); 086 TransactionalServiceUtils.exhaustIterator(i); 087 return false; 088 } 089 else { 090 LOG.debug("doBatchPaymentsHaveOpenStatus() All payment groups have status 'OPEN'."); 091 return true; 092 } 093 } 094 095 /** 096 * doBatchPaymentsHaveHeldStatus() Return true if all payments in batch have an 'HELD' status. Return false if all payments in 097 * batch do not have an 'HELD' status. The query in this method searches the payment detail table for payments of the given 098 * batchId where the status equals any status other than 'HELD'. If any rows exist with a status other than 'HELD', return 099 * 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}