1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.syslunch.dao;
17
18 import java.sql.Date;
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.apache.commons.lang.StringUtils;
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.apache.ojb.broker.query.ReportQueryByCriteria;
28 import org.kuali.hr.core.util.OjbSubQueryUtil;
29 import org.kuali.hr.time.syslunch.rule.SystemLunchRule;
30 import org.kuali.hr.time.util.TKUtils;
31 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
32
33 public class SystemLunchRuleDaoImpl extends PlatformAwareDaoBaseOjb implements SystemLunchRuleDao {
34
35 @Override
36 public SystemLunchRule getSystemLunchRule(Date asOfDate) {
37 Criteria root = new Criteria();
38
39 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(SystemLunchRule.class, asOfDate, Collections.EMPTY_LIST, false));
40 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(SystemLunchRule.class, Collections.EMPTY_LIST, false));
41
42 Criteria activeFilter = new Criteria();
43 activeFilter.addEqualTo("active", true);
44 root.addAndCriteria(activeFilter);
45
46 Query query = QueryFactory.newQuery(SystemLunchRule.class, root);
47 return (SystemLunchRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
48 }
49
50 @Override
51 public SystemLunchRule getSystemLunchRule(String tkSystemLunchRuleId) {
52 Criteria crit = new Criteria();
53 crit.addEqualTo("tkSystemLunchRuleId", tkSystemLunchRuleId);
54
55 Query query = QueryFactory.newQuery(SystemLunchRule.class, crit);
56
57 return (SystemLunchRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
58 }
59
60 @Override
61 @SuppressWarnings("unchecked")
62 public List<SystemLunchRule> getSystemLunchRules(Date fromEffdt, Date toEffdt, String active, String showHistory) {
63 List<SystemLunchRule> results = new ArrayList<SystemLunchRule>();
64
65 Criteria root = new Criteria();
66
67 Criteria effectiveDateFilter = new Criteria();
68 if (fromEffdt != null) {
69 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt);
70 }
71 if (toEffdt != null) {
72 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt);
73 }
74 if (fromEffdt == null && toEffdt == null) {
75 effectiveDateFilter.addLessOrEqualThan("effectiveDate", TKUtils.getCurrentDate());
76 }
77 root.addAndCriteria(effectiveDateFilter);
78
79 if (StringUtils.isNotBlank(active)) {
80 Criteria activeFilter = new Criteria();
81 if (StringUtils.equals(active, "Y")) {
82 activeFilter.addEqualTo("active", true);
83 } else if (StringUtils.equals(active, "N")) {
84 activeFilter.addEqualTo("active", false);
85 }
86 root.addAndCriteria(activeFilter);
87 }
88
89 if (StringUtils.equals(showHistory, "N")) {
90 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(SystemLunchRule.class, effectiveDateFilter, Collections.EMPTY_LIST, false));
91 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(SystemLunchRule.class, Collections.EMPTY_LIST, false));
92 }
93
94 Query query = QueryFactory.newQuery(SystemLunchRule.class, root);
95 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
96
97 return results;
98 }
99
100 }