1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.timeoff.dao;
17
18
19 import java.util.ArrayList;
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.timeoff.SystemScheduledTimeOff;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31 public class SystemScheduledTimeOffDaoOjbImpl extends PlatformAwareDaoBaseOjb implements SystemScheduledTimeOffDao {
32
33 @Override
34 public SystemScheduledTimeOff getSystemScheduledTimeOff(String lmSystemScheduledTimeOffId) {
35 Criteria crit = new Criteria();
36 crit.addEqualTo("lmSystemScheduledTimeOffId", lmSystemScheduledTimeOffId);
37 Query query = QueryFactory.newQuery(SystemScheduledTimeOff.class, crit);
38 return (SystemScheduledTimeOff) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
39 }
40
41 @Override
42 public List<SystemScheduledTimeOff> getSystemScheduledTimeOffForPayPeriod(
43 String leavePlan, LocalDate startDate, LocalDate endDate) {
44 Criteria root = new Criteria();
45 root.addEqualTo("leavePlan", leavePlan);
46 root.addBetween("accruedDate", startDate.toDate(), endDate.toDate());
47 return (List<SystemScheduledTimeOff>)this.getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(SystemScheduledTimeOff.class, root));
48 }
49
50 @Override
51 public SystemScheduledTimeOff getSystemScheduledTimeOffByDate(String leavePlan, LocalDate startDate) {
52 Criteria root = new Criteria();
53 root.addEqualTo("leavePlan", leavePlan);
54 root.addEqualTo("accruedDate", startDate.toDate());
55 root.addEqualTo("active", true);
56 return (SystemScheduledTimeOff)this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(SystemScheduledTimeOff.class, root));
57 }
58
59 @Override
60 @SuppressWarnings("unchecked")
61 public List<SystemScheduledTimeOff> getSystemScheduledTimeOffs(LocalDate fromEffdt, LocalDate toEffdt, String earnCode, LocalDate fromAccruedDate,LocalDate toAccruedDate,
62 LocalDate fromSchTimeOffDate, LocalDate toSchTimeOffDate, String premiumEarnCode, String active, String showHistory) {
63
64 List<SystemScheduledTimeOff> results = new ArrayList<SystemScheduledTimeOff>();
65
66 Criteria root = new Criteria();
67
68 if (StringUtils.isNotBlank(earnCode)) {
69 root.addLike("UPPER(earnCode)", earnCode.toUpperCase());
70 }
71
72 if (StringUtils.isNotBlank(premiumEarnCode)) {
73 root.addLike("UPPER(premiumEarnCode)", premiumEarnCode.toUpperCase());
74 }
75
76 Criteria effectiveDateFilter = new Criteria();
77 if (fromEffdt != null) {
78 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
79 }
80 if (toEffdt != null) {
81 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
82 }
83 if (fromEffdt == null && toEffdt == null) {
84 effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
85 }
86 root.addAndCriteria(effectiveDateFilter);
87
88 if (fromAccruedDate != null) {
89 root.addGreaterOrEqualThan("accruedDate", fromAccruedDate.toDate());
90 }
91 if (toAccruedDate != null) {
92 root.addLessOrEqualThan("accruedDate", toAccruedDate.toDate());
93 }
94
95 if (fromSchTimeOffDate != null) {
96 root.addGreaterOrEqualThan("scheduledTimeOffDate", fromSchTimeOffDate.toDate());
97 }
98 if (toSchTimeOffDate != null) {
99 root.addLessOrEqualThan("scheduledTimeOffDate", toSchTimeOffDate.toDate());
100 }
101
102 if (StringUtils.isNotBlank(active)) {
103 Criteria activeFilter = new Criteria();
104 if (StringUtils.equals(active, "Y")) {
105 activeFilter.addEqualTo("active", true);
106 } else if (StringUtils.equals(active, "N")) {
107 activeFilter.addEqualTo("active", false);
108 }
109 root.addAndCriteria(activeFilter);
110 }
111
112 if (StringUtils.equals(showHistory, "N")) {
113
114
115
116
117
118 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(SystemScheduledTimeOff.class, effectiveDateFilter, SystemScheduledTimeOff.fields, false));
119 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(SystemScheduledTimeOff.class, SystemScheduledTimeOff.fields, false));
120 }
121
122 Query query = QueryFactory.newQuery(SystemScheduledTimeOff.class, root);
123 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
124
125 return results;
126 }
127
128 @Override
129 @SuppressWarnings("unchecked")
130 public List<SystemScheduledTimeOff> getSystemScheduledTimeOffsForLeavePlan(LocalDate fromAccruedDate,LocalDate toAccruedDate, String leavePlan) {
131 List<SystemScheduledTimeOff> results = new ArrayList<SystemScheduledTimeOff>();
132 Criteria root = new Criteria();
133
134 if (fromAccruedDate != null) {
135 root.addGreaterOrEqualThan("accruedDate", fromAccruedDate.toDate());
136 }
137 if (toAccruedDate != null) {
138 root.addLessOrEqualThan("accruedDate", toAccruedDate.toDate());
139 }
140
141 if(StringUtils.isNotEmpty(leavePlan)) {
142 root.addEqualTo("leavePlan", leavePlan);
143 }
144 Criteria activeFilter = new Criteria();
145 activeFilter.addEqualTo("active", true);
146 root.addAndCriteria(activeFilter);
147
148
149
150
151
152
153 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithoutFilter(SystemScheduledTimeOff.class, SystemScheduledTimeOff.fields, false));
154 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(SystemScheduledTimeOff.class, SystemScheduledTimeOff.fields, false));
155
156 Query query = QueryFactory.newQuery(SystemScheduledTimeOff.class, root);
157 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
158
159 return results;
160 }
161
162 }