1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.payout.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.log4j.Logger;
24 import org.apache.ojb.broker.query.Criteria;
25 import org.apache.ojb.broker.query.Query;
26 import org.apache.ojb.broker.query.QueryFactory;
27 import org.joda.time.LocalDate;
28 import org.kuali.kpme.tklm.leave.payout.LeavePayout;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31
32 public class LeavePayoutDaoOjbImpl extends PlatformAwareDaoBaseOjb implements
33 LeavePayoutDao {
34
35 private static final Logger LOG = Logger.getLogger(LeavePayout.class);
36
37 @Override
38 public List<LeavePayout> getAllLeavePayoutsForPrincipalId(
39 String principalId) {
40 Criteria crit = new Criteria();
41 List<LeavePayout> leavePayouts = new ArrayList<LeavePayout>();
42 crit.addEqualTo("principalId",principalId);
43 Query query = QueryFactory.newQuery(LeavePayout.class,crit);
44
45 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
46
47 if(c != null)
48 leavePayouts.addAll(c);
49
50 return leavePayouts;
51 }
52
53 @Override
54 public List<LeavePayout> getAllLeavePayoutsForPrincipalIdAsOfDate(
55 String principalId, LocalDate effectiveDate) {
56 List<LeavePayout> leavePayouts = new ArrayList<LeavePayout>();
57 Criteria crit = new Criteria();
58 crit.addEqualTo("principalId",principalId);
59 Criteria effDate = new Criteria();
60 effDate.addGreaterOrEqualThan("effectiveDate", effectiveDate.toDate());
61 crit.addAndCriteria(effDate);
62 Query query = QueryFactory.newQuery(LeavePayout.class,crit);
63 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
64
65 if(c != null)
66 leavePayouts.addAll(c);
67
68 return leavePayouts;
69 }
70
71 @Override
72 public List<LeavePayout> getAllLeavePayoutsByEffectiveDate(
73 LocalDate effectiveDate) {
74 List<LeavePayout> leavePayouts = new ArrayList<LeavePayout>();
75 Criteria effDate = new Criteria();
76 effDate.addGreaterOrEqualThan("effectiveDate", effectiveDate.toDate());
77 Query query = QueryFactory.newQuery(LeavePayout.class,effDate);
78
79 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
80
81 if(c != null)
82 leavePayouts.addAll(c);
83
84 return leavePayouts;
85 }
86
87 @Override
88 public LeavePayout getLeavePayoutById(String lmLeavePayoutId) {
89 Criteria crit = new Criteria();
90 crit.addEqualTo("lmLeavePayoutId",lmLeavePayoutId);
91 Query query = QueryFactory.newQuery(LeavePayout.class,crit);
92 return (LeavePayout) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
93 }
94
95 @Override
96 public List<LeavePayout> getAllLeavePayoutsMarkedPayoutForPrincipalId(
97 String principalId) {
98 Criteria crit = new Criteria();
99 List<LeavePayout> leavePayouts = new ArrayList<LeavePayout>();
100 crit.addEqualTo("principalId",principalId);
101 Criteria payoutCrit = new Criteria();
102 payoutCrit.addNotNull("earnCode");
103 crit.addAndCriteria(payoutCrit);
104 Query query = QueryFactory.newQuery(LeavePayout.class,crit);
105
106 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
107
108 if(c != null)
109 leavePayouts.addAll(c);
110
111 return leavePayouts;
112 }
113
114 @Override
115 public List<LeavePayout> getLeavePayouts(String viewPrincipal,
116 LocalDate beginPeriodDate, LocalDate endPeriodDate) {
117
118 List<LeavePayout> leavePayouts = new ArrayList<LeavePayout>();
119 Criteria crit = new Criteria();
120 crit.addEqualTo("principalId",viewPrincipal);
121
122 Criteria effDate = new Criteria();
123 effDate.addGreaterOrEqualThan("effectiveDate", beginPeriodDate.toDate());
124 effDate.addLessOrEqualThan("effectiveDate", endPeriodDate.toDate());
125
126 crit.addAndCriteria(effDate);
127
128 Query query = QueryFactory.newQuery(LeavePayout.class,crit);
129
130 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
131
132 if(c != null)
133 leavePayouts.addAll(c);
134
135 return leavePayouts;
136 }
137
138 @Override
139 public void saveOrUpdate(LeavePayout payout) {
140 this.getPersistenceBrokerTemplate().store(payout);
141 }
142
143 @Override
144 public List<LeavePayout> getLeavePayouts(String principalId, String fromAccrualCategory, String payoutAmount, String earnCode, String forfeitedAmount, LocalDate fromEffdt, LocalDate toEffdt) {
145 List<LeavePayout> results = new ArrayList<LeavePayout>();
146
147 Criteria root = new Criteria();
148
149 if (StringUtils.isNotBlank(principalId)) {
150 root.addLike("UPPER(principalId)", principalId.toUpperCase());
151 }
152
153 if (StringUtils.isNotBlank(fromAccrualCategory)) {
154 root.addLike("UPPER(fromAccrualCategory)", fromAccrualCategory.toUpperCase());
155 }
156
157 if (StringUtils.isNotBlank(payoutAmount)) {
158 root.addLike("payoutAmount", payoutAmount);
159 }
160
161 if (StringUtils.isNotBlank(earnCode)) {
162 root.addLike("UPPER(earnCode)", earnCode.toUpperCase());
163 }
164
165 if (StringUtils.isNotBlank(forfeitedAmount)) {
166 root.addLike("forfeitedAmount", forfeitedAmount);
167 }
168
169 Criteria effectiveDateFilter = new Criteria();
170 if (fromEffdt != null) {
171 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
172 }
173 if (toEffdt != null) {
174 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
175 }
176 if (fromEffdt == null && toEffdt == null) {
177 effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
178 }
179 root.addAndCriteria(effectiveDateFilter);
180
181 Query query = QueryFactory.newQuery(LeavePayout.class, root);
182 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
183
184 return results;
185 }
186
187 }