1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.donation.dao;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.apache.log4j.Logger;
23 import org.apache.ojb.broker.query.Criteria;
24 import org.apache.ojb.broker.query.Query;
25 import org.apache.ojb.broker.query.QueryFactory;
26 import org.joda.time.LocalDate;
27 import org.kuali.kpme.core.util.OjbSubQueryUtil;
28 import org.kuali.kpme.tklm.leave.donation.LeaveDonation;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31 public class LeaveDonationDaoOjbImpl extends PlatformAwareDaoBaseOjb implements LeaveDonationDao {
32
33 private static final Logger LOG = Logger.getLogger(LeaveDonationDaoOjbImpl.class);
34
35 @Override
36 public LeaveDonation getLeaveDonation(String lmLeaveDonationId) {
37 Criteria crit = new Criteria();
38 crit.addEqualTo("lmLeaveDonationId", lmLeaveDonationId);
39 Query query = QueryFactory.newQuery(LeaveDonation.class, crit);
40 return (LeaveDonation) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
41 }
42
43 @Override
44 public List<LeaveDonation> getLeaveDonations(LocalDate fromEffdt, LocalDate toEffdt, String donorsPrincipalId, String donatedAccrualCategory, String amountDonated, String recipientsPrincipalId, String recipientsAccrualCategory, String amountReceived, String active, String showHist) {
45 List<LeaveDonation> results = new ArrayList<LeaveDonation>();
46
47 Criteria root = new Criteria();
48
49 Criteria effectiveDateFilter = new Criteria();
50 if (fromEffdt != null) {
51 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
52 }
53 if (toEffdt != null) {
54 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
55 }
56 if (fromEffdt == null && toEffdt == null) {
57 effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
58 }
59 root.addAndCriteria(effectiveDateFilter);
60
61 if (StringUtils.isNotBlank(donorsPrincipalId)) {
62 root.addLike("UPPER(donor)", donorsPrincipalId.toUpperCase());
63 }
64
65 if (StringUtils.isNotBlank(donatedAccrualCategory)) {
66 root.addLike("UPPER(donatedAccrualCategory)", donatedAccrualCategory.toUpperCase());
67 }
68
69 if (StringUtils.isNotBlank(amountDonated)) {
70 root.addLike("amountDonated", amountDonated);
71 }
72
73 if (StringUtils.isNotBlank(recipientsPrincipalId)) {
74 root.addLike("UPPER(recepient)", recipientsPrincipalId.toUpperCase());
75 }
76
77 if (StringUtils.isNotBlank(recipientsAccrualCategory)) {
78 root.addLike("UPPER(recipientsAccrualCategory)", recipientsAccrualCategory.toUpperCase());
79 }
80
81 if (StringUtils.isNotBlank(amountReceived)) {
82 root.addLike("amountReceived", amountReceived);
83 }
84
85 if (StringUtils.isNotBlank(active)) {
86 Criteria activeFilter = new Criteria();
87 if (StringUtils.equals(active, "Y")) {
88 activeFilter.addEqualTo("active", true);
89 } else if (StringUtils.equals(active, "N")) {
90 activeFilter.addEqualTo("active", false);
91 }
92 root.addAndCriteria(activeFilter);
93 }
94
95 if (StringUtils.equals(showHist, "N")) {
96 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(LeaveDonation.class, effectiveDateFilter, LeaveDonation.EQUAL_TO_FIELDS, false));
97 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(LeaveDonation.class, LeaveDonation.EQUAL_TO_FIELDS, false));
98 }
99
100 Query query = QueryFactory.newQuery(LeaveDonation.class, root);
101 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
102
103 return results;
104 }
105
106 }