1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.adjustment.dao;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
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.adjustment.LeaveAdjustment;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31 public class LeaveAdjustmentDaoOjbImpl extends PlatformAwareDaoBaseOjb implements LeaveAdjustmentDao{
32
33 @SuppressWarnings("unchecked")
34 @Override
35 public List<LeaveAdjustment> getLeaveAdjustments(String principalId, LocalDate asOfDate) {
36 List<LeaveAdjustment> leaveAdjustments = new ArrayList<LeaveAdjustment>();
37 Criteria root = new Criteria();
38 root.addEqualTo("principalId", principalId);
39 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(LeaveAdjustment.class, asOfDate, LeaveAdjustment.EQUAL_TO_FIELDS, false));
40 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(LeaveAdjustment.class, LeaveAdjustment.EQUAL_TO_FIELDS, false));
41
42 Criteria activeFilter = new Criteria();
43 activeFilter.addEqualTo("active", true);
44 root.addAndCriteria(activeFilter);
45
46 Query query = QueryFactory.newQuery(LeaveAdjustment.class, root);
47 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
48
49 if (c != null) {
50 leaveAdjustments.addAll(c);
51 }
52 return leaveAdjustments;
53 }
54
55 @Override
56 public LeaveAdjustment getLeaveAdjustment(String lmLeaveAdjustmentId) {
57 Criteria crit = new Criteria();
58 crit.addEqualTo("lmLeaveAdjustmentId", lmLeaveAdjustmentId);
59 Query query = QueryFactory.newQuery(LeaveAdjustment.class, crit);
60 return (LeaveAdjustment) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
61 }
62
63 @Override
64 public List<LeaveAdjustment> getLeaveAdjustments(LocalDate fromEffdt, LocalDate toEffdt, String principalId, String accrualCategory, String earnCode) {
65 List<LeaveAdjustment> results = new ArrayList<LeaveAdjustment>();
66
67 Criteria root = new Criteria();
68
69 Criteria effectiveDateFilter = new Criteria();
70 if (fromEffdt != null) {
71 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
72 }
73 if (toEffdt != null) {
74 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
75 }
76 if (fromEffdt == null && toEffdt == null) {
77 effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
78 }
79 root.addAndCriteria(effectiveDateFilter);
80
81 if (StringUtils.isNotBlank(principalId)) {
82 root.addLike("UPPER(`principal_id`)", principalId.toUpperCase());
83 }
84
85 if (StringUtils.isNotBlank(accrualCategory)) {
86 root.addLike("UPPER(`accrual_cat`)", accrualCategory.toUpperCase());
87 }
88
89 if (StringUtils.isNotBlank(earnCode)) {
90 root.addLike("UPPER(`earn_code`)", earnCode.toUpperCase());
91 }
92
93 Query query = QueryFactory.newQuery(LeaveAdjustment.class, root);
94 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
95
96 return results;
97 }
98
99 }