1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.earncode.dao;
17
18 import java.sql.Date;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.List;
22
23 import com.google.common.collect.ImmutableList;
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.log4j.Logger;
26 import org.apache.ojb.broker.query.Criteria;
27 import org.apache.ojb.broker.query.Query;
28 import org.apache.ojb.broker.query.QueryFactory;
29 import org.apache.ojb.broker.query.ReportQueryByCriteria;
30 import org.kuali.hr.core.util.OjbSubQueryUtil;
31 import org.kuali.hr.time.earncode.EarnCode;
32 import org.kuali.hr.time.util.TKUtils;
33 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
34
35 public class EarnCodeDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements EarnCodeDao {
36 private static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
37 .add("earnCode")
38
39 .build();
40
41 private static final Logger LOG = Logger.getLogger(EarnCodeDaoSpringOjbImpl.class);
42
43 public void saveOrUpdate(EarnCode earnCode) {
44 this.getPersistenceBrokerTemplate().store(earnCode);
45 }
46
47 public void saveOrUpdate(List<EarnCode> earnCodeList) {
48 if (earnCodeList != null) {
49 for (EarnCode earnCode : earnCodeList) {
50 this.getPersistenceBrokerTemplate().store(earnCode);
51 }
52 }
53 }
54
55 public EarnCode getEarnCodeById(String earnCodeId) {
56 Criteria crit = new Criteria();
57 crit.addEqualTo("hrEarnCodeId", earnCodeId);
58 return (EarnCode) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(EarnCode.class, crit));
59 }
60
61 @Override
62 public EarnCode getEarnCode(String earnCode, Date asOfDate) {
63 EarnCode ec = null;
64
65 Criteria root = new Criteria();
66
67 root.addEqualTo("earnCode", earnCode);
68 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EarnCode.class, asOfDate, EQUAL_TO_FIELDS, false));
69 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCode.class, EQUAL_TO_FIELDS, false));
70
71 Criteria activeFilter = new Criteria();
72 activeFilter.addEqualTo("active", true);
73 root.addAndCriteria(activeFilter);
74
75
76 Query query = QueryFactory.newQuery(EarnCode.class, root);
77 Object obj = this.getPersistenceBrokerTemplate().getObjectByQuery(query);
78
79 if (obj != null) {
80 ec = (EarnCode) obj;
81 }
82
83 return ec;
84 }
85
86 @Override
87 public List<EarnCode> getOvertimeEarnCodes(Date asOfDate) {
88 Criteria root = new Criteria();
89
90 root.addEqualTo("ovtEarnCode", "Y");
91 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EarnCode.class, asOfDate, EQUAL_TO_FIELDS, false));
92 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCode.class, EQUAL_TO_FIELDS, false));
93
94
95 Criteria activeFilter = new Criteria();
96 activeFilter.addEqualTo("active", true);
97 root.addAndCriteria(activeFilter);
98
99
100 Query query = QueryFactory.newQuery(EarnCode.class, root);
101 List<EarnCode> ovtEarnCodes = (List<EarnCode>)this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
102 return ovtEarnCodes;
103 }
104
105 @Override
106 public int getEarnCodeCount(String earnCode) {
107 Criteria crit = new Criteria();
108 crit.addEqualTo("earnCode", earnCode);
109 Query query = QueryFactory.newQuery(EarnCode.class, crit);
110 return this.getPersistenceBrokerTemplate().getCount(query);
111 }
112
113 @Override
114 public int getNewerEarnCodeCount(String earnCode, Date effdt) {
115 Criteria crit = new Criteria();
116 crit.addEqualTo("earnCode", earnCode);
117 crit.addEqualTo("active", "Y");
118 crit.addGreaterThan("effectiveDate", effdt);
119 Query query = QueryFactory.newQuery(EarnCode.class, crit);
120 return this.getPersistenceBrokerTemplate().getCount(query);
121 }
122
123 @Override
124 public List<EarnCode> getEarnCodes(String leavePlan, Date asOfDate) {
125 List<EarnCode> earnCodes = new ArrayList<EarnCode>();
126 Criteria root = new Criteria();
127
128 List<String> fields = new ArrayList<String>();
129 fields.add("earnCode");
130 fields.add("leavePlan");
131 root.addEqualTo("leavePlan", leavePlan);
132 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EarnCode.class, asOfDate, fields, false));
133 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCode.class, fields, false));
134
135 Criteria activeFilter = new Criteria();
136 activeFilter.addEqualTo("active", true);
137 root.addAndCriteria(activeFilter);
138
139
140 Query query = QueryFactory.newQuery(EarnCode.class, root);
141 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
142
143 if (c != null) {
144 earnCodes.addAll(c);
145 }
146 return earnCodes;
147 }
148
149 @Override
150 @SuppressWarnings("unchecked")
151 public List<EarnCode> getEarnCodes(String earnCode, String ovtEarnCode, String descr, String leavePlan, String accrualCategory, Date fromEffdt, Date toEffdt, String active, String showHistory) {
152 List<EarnCode> results = new ArrayList<EarnCode>();
153
154 Criteria root = new Criteria();
155
156 if (StringUtils.isNotBlank(earnCode)) {
157 root.addLike("earnCode", earnCode);
158 }
159
160 if (StringUtils.isNotBlank(ovtEarnCode)) {
161 root.addEqualTo("ovtEarnCode", ovtEarnCode);
162 }
163
164 if (StringUtils.isNotBlank(descr)) {
165 root.addLike("description", descr);
166 }
167
168 if (StringUtils.isNotBlank(leavePlan)) {
169 root.addLike("leavePlan", leavePlan);
170 }
171
172 if (StringUtils.isNotBlank(accrualCategory)) {
173 root.addLike("accrualCategory", accrualCategory);
174 }
175
176 Criteria effectiveDateFilter = new Criteria();
177 if (fromEffdt != null) {
178 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt);
179 }
180 if (toEffdt != null) {
181 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt);
182 }
183 if (fromEffdt == null && toEffdt == null) {
184 effectiveDateFilter.addLessOrEqualThan("effectiveDate", TKUtils.getCurrentDate());
185 }
186 root.addAndCriteria(effectiveDateFilter);
187
188 if (StringUtils.isNotBlank(active)) {
189 Criteria activeFilter = new Criteria();
190 if (StringUtils.equals(active, "Y")) {
191 activeFilter.addEqualTo("active", true);
192 } else if (StringUtils.equals(active, "N")) {
193 activeFilter.addEqualTo("active", false);
194 }
195 root.addAndCriteria(activeFilter);
196 }
197
198 if (StringUtils.equals(showHistory, "N")) {
199 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(EarnCode.class, effectiveDateFilter, EQUAL_TO_FIELDS, false));
200 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCode.class, EQUAL_TO_FIELDS, false));
201 }
202
203 Query query = QueryFactory.newQuery(EarnCode.class, root);
204 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
205
206 return results;
207 }
208
209 }