1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.graceperiod.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.graceperiod.rule.GracePeriodRule;
30 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
31
32 public class GracePeriodDaoImpl extends PlatformAwareDaoBaseOjb implements GracePeriodDao {
33 public GracePeriodRule getGracePeriodRule(Date asOfDate){
34 GracePeriodRule gracePeriodRule = null;
35
36 Criteria root = new Criteria();
37
38 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(GracePeriodRule.class, asOfDate, Collections.EMPTY_LIST, false));
39 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(GracePeriodRule.class, Collections.EMPTY_LIST, false));
40
41 Criteria activeFilter = new Criteria();
42 activeFilter.addEqualTo("active", true);
43 root.addAndCriteria(activeFilter);
44
45
46 Query query = QueryFactory.newQuery(GracePeriodRule.class, root);
47 Object obj = this.getPersistenceBrokerTemplate().getObjectByQuery(query);
48
49 if (obj != null) {
50 gracePeriodRule = (GracePeriodRule) obj;
51 }
52
53 return gracePeriodRule;
54 }
55
56 @Override
57 public GracePeriodRule getGracePeriodRule(String tkGracePeriodId) {
58 Criteria crit = new Criteria();
59 crit.addEqualTo("tkGracePeriodRuleId", tkGracePeriodId);
60
61 Query query = QueryFactory.newQuery(GracePeriodRule.class, crit);
62 return (GracePeriodRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
63 }
64
65 @Override
66 @SuppressWarnings("unchecked")
67 public List<GracePeriodRule> getGracePeriodRules(String hourFactor, String active, String showHistory) {
68 List<GracePeriodRule> results = new ArrayList<GracePeriodRule>();
69
70 Criteria root = new Criteria();
71
72 if (StringUtils.isNotBlank(hourFactor)) {
73 root.addLike("hourFactor", hourFactor);
74 }
75
76 if (StringUtils.isNotBlank(active)) {
77 Criteria activeFilter = new Criteria();
78 if (StringUtils.equals(active, "Y")) {
79 activeFilter.addEqualTo("active", true);
80 } else if (StringUtils.equals(active, "N")) {
81 activeFilter.addEqualTo("active", false);
82 }
83 root.addAndCriteria(activeFilter);
84 }
85
86 if (StringUtils.equals(showHistory, "N")) {
87 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithoutFilter(GracePeriodRule.class, Collections.EMPTY_LIST, false));
88 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(GracePeriodRule.class, Collections.EMPTY_LIST, false));
89 }
90
91 Query query = QueryFactory.newQuery(GracePeriodRule.class, root);
92 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
93
94 return results;
95 }
96
97 }