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 7, 2004
018: *
019: */
020: package org.kuali.module.pdp.dao.ojb;
021:
022: import java.math.BigDecimal;
023: import java.sql.Timestamp;
024: import java.util.Calendar;
025: import java.util.GregorianCalendar;
026: import java.util.Iterator;
027: import java.util.List;
028:
029: import org.apache.ojb.broker.query.Criteria;
030: import org.apache.ojb.broker.query.QueryByCriteria;
031: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
032: import org.kuali.core.exceptions.UserNotFoundException;
033: import org.kuali.core.service.UniversalUserService;
034: import org.kuali.module.pdp.bo.Batch;
035: import org.kuali.module.pdp.bo.BatchSearch;
036: import org.kuali.module.pdp.bo.PaymentDetail;
037: import org.kuali.module.pdp.bo.UserRequired;
038: import org.kuali.module.pdp.dao.BatchSearchDao;
039:
040: /**
041: * @author jsissom
042: */
043: public class BatchSearchDaoOjb extends PlatformAwareDaoBaseOjb
044: implements BatchSearchDao {
045: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
046: .getLogger(BatchSearchDaoOjb.class);
047: private UniversalUserService userService;
048:
049: public BatchSearchDaoOjb() {
050: super ();
051: }
052:
053: public List getAllBatchesForSearchCriteria(BatchSearch bs, int bsl) {
054: LOG
055: .info("getAllBatchesForSearchCriteria(PaymentDetailSearch) starting");
056: String dateToSearchOn = "customerFileCreateTimestamp";
057: Criteria criteria = new Criteria();
058:
059: if ((!(bs.getBatchId() == null))
060: && (!(bs.getBatchId() == new Integer(0)))) {
061: criteria.addEqualTo("id", bs.getBatchId());
062: }
063: if ((!(bs.getChartCode() == null))
064: && (!(bs.getChartCode().equals("")))) {
065: criteria.addLike("customerProfile.chartCode", "%"
066: + bs.getChartCode() + "%");
067: }
068: if ((!(bs.getOrgCode() == null))
069: && (!(bs.getOrgCode().equals("")))) {
070: criteria.addLike("customerProfile.orgCode", "%"
071: + bs.getOrgCode() + "%");
072: }
073: if ((!(bs.getSubUnitCode() == null))
074: && (!(bs.getSubUnitCode().equals("")))) {
075: criteria.addLike("customerProfile.subUnitCode", "%"
076: + bs.getSubUnitCode() + "%");
077: }
078: if ((!(bs.getPaymentCount() == null))
079: && (!(bs.getPaymentCount() == new Integer(0)))) {
080: criteria.addEqualTo("paymentCount", bs.getPaymentCount());
081: }
082: if ((!(bs.getPaymentTotalAmount() == null))
083: && (!(bs.getPaymentTotalAmount() == new BigDecimal(0.00)))) {
084: criteria.addEqualTo("paymentTotalAmount", bs
085: .getPaymentTotalAmount());
086: }
087: if (!(bs.getBeginDate() == null)) {
088: criteria.addGreaterOrEqualThan(dateToSearchOn, bs
089: .getBeginDate());
090: }
091: if (!(bs.getEndDate() == null)) {
092: GregorianCalendar gc = new GregorianCalendar();
093: gc.setTime(bs.getEndDate());
094: gc.add(Calendar.DATE, 1);
095: criteria.addLessOrEqualThan(dateToSearchOn, new Timestamp(
096: gc.getTimeInMillis()));
097: }
098:
099: QueryByCriteria qbc = new QueryByCriteria(Batch.class, criteria);
100: qbc.addOrderBy("customerProfile.chartCode", true);
101: qbc.addOrderBy("customerProfile.orgCode", true);
102: qbc.addOrderBy("customerProfile.subUnitCode", true);
103: qbc.addOrderBy(dateToSearchOn, true);
104: int total = bsl + 1;
105: qbc.setEndAtIndex(total);
106: LOG.debug("getAllBatchesForSearchCriteria() Query = "
107: + qbc.toString());
108:
109: List l = (List) getPersistenceBrokerTemplate()
110: .getCollectionByQuery(qbc);
111: updateUser(l);
112: return l;
113:
114: }
115:
116: public List getAllSingleBatchPayments(Integer id) {
117: LOG.info("getAllSingleBatchPayments(id) starting");
118:
119: Criteria criteria = new Criteria();
120: criteria.addEqualTo("paymentGroup.batch.id", id);
121: QueryByCriteria qbc = new QueryByCriteria(PaymentDetail.class,
122: criteria);
123: qbc.addOrderBy("paymentGroup.payeeName", true);
124: LOG.debug("getAllSingleBatchPayments() Query = "
125: + qbc.toString());
126: List l = (List) getPersistenceBrokerTemplate()
127: .getCollectionByQuery(qbc);
128:
129: return l;
130: }
131:
132: // Inject
133: public void setUniversalUserService(UniversalUserService us) {
134: userService = us;
135: }
136:
137: private void updateUser(List l) {
138: for (Iterator iter = l.iterator(); iter.hasNext();) {
139: updateUser((Batch) iter.next());
140: }
141: }
142:
143: private void updateUser(Batch b) {
144: UserRequired ur = (UserRequired) b;
145: try {
146: ur.updateUser(userService);
147: } catch (UserNotFoundException e) {
148: b.setSubmiterUser(null);
149: }
150: }
151: }
|