1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.kuali.ole.pdp.dataaccess.impl;
21
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import org.apache.ojb.broker.query.Criteria;
27 import org.apache.ojb.broker.query.QueryFactory;
28 import org.apache.ojb.broker.query.ReportQueryByCriteria;
29 import org.kuali.ole.pdp.PdpConstants.PaymentStatusCodes;
30 import org.kuali.ole.pdp.PdpPropertyConstants;
31 import org.kuali.ole.pdp.businessobject.PaymentGroup;
32 import org.kuali.ole.pdp.businessobject.PaymentStatus;
33 import org.kuali.ole.pdp.dataaccess.BatchMaintenanceDao;
34 import org.kuali.ole.sys.util.TransactionalServiceUtils;
35 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
36 import org.kuali.rice.krad.util.ObjectUtils;
37
38
39
40
41
42 public class BatchMaintenanceDaoOjb extends PlatformAwareDaoBaseOjb implements BatchMaintenanceDao {
43 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BatchMaintenanceDaoOjb.class);
44
45 public BatchMaintenanceDaoOjb() {
46 super();
47 }
48
49
50
51
52
53
54
55
56
57
58
59
60 public boolean doBatchPaymentsHaveOpenStatus(Integer batchId, List batchPayments, List statusList) {
61 LOG.debug("doBatchPaymentsHaveOpenStatus() enter method.");
62 List codeList = new ArrayList();
63
64 if (ObjectUtils.isNull(batchPayments) || batchPayments.isEmpty()) {
65 return false;
66 }
67
68 for (Iterator i = statusList.iterator(); i.hasNext();) {
69 PaymentStatus element = (PaymentStatus) i.next();
70 if (!(element.getCode().equals(PaymentStatusCodes.OPEN))) {
71 codeList.add(element.getCode());
72 }
73 }
74
75 Criteria crit = new Criteria();
76 crit.addEqualTo(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BATCH_ID, batchId);
77 crit.addIn(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE, codeList);
78
79 ReportQueryByCriteria q = QueryFactory.newReportQuery(PaymentGroup.class, crit);
80 q.setAttributes(new String[] { PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE });
81 q.addGroupBy(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE);
82
83 Iterator i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
84 if (i.hasNext()) {
85 LOG.debug("doBatchPaymentsHaveOpenStatus() Not all payment groups have status 'OPEN'.");
86 TransactionalServiceUtils.exhaustIterator(i);
87 return false;
88 }
89 else {
90 LOG.debug("doBatchPaymentsHaveOpenStatus() All payment groups have status 'OPEN'.");
91 return true;
92 }
93 }
94
95
96
97
98
99
100
101
102
103
104
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 }