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.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.apache.ojb.broker.query.ReportQueryByCriteria;
27 import org.kuali.hr.time.graceperiod.rule.GracePeriodRule;
28 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29
30 public class GracePeriodDaoImpl extends PlatformAwareDaoBaseOjb implements GracePeriodDao {
31 public GracePeriodRule getGracePeriodRule(Date asOfDate){
32 GracePeriodRule gracePeriodRule = null;
33
34 Criteria root = new Criteria();
35 Criteria effdt = new Criteria();
36 Criteria timestamp = new Criteria();
37
38
39 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
40
41 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(GracePeriodRule.class, effdt);
42 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
43
44
45 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
46
47 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(GracePeriodRule.class, timestamp);
48 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
49
50 root.addEqualTo("effectiveDate", effdtSubQuery);
51 root.addEqualTo("timestamp", timestampSubQuery);
52
53 Criteria activeFilter = new Criteria();
54 activeFilter.addEqualTo("active", true);
55 root.addAndCriteria(activeFilter);
56
57
58 Query query = QueryFactory.newQuery(GracePeriodRule.class, root);
59 Object obj = this.getPersistenceBrokerTemplate().getObjectByQuery(query);
60
61 if (obj != null) {
62 gracePeriodRule = (GracePeriodRule) obj;
63 }
64
65 return gracePeriodRule;
66 }
67
68 @Override
69 public GracePeriodRule getGracePeriodRule(String tkGracePeriodId) {
70 Criteria crit = new Criteria();
71 crit.addEqualTo("tkGracePeriodRuleId", tkGracePeriodId);
72
73 Query query = QueryFactory.newQuery(GracePeriodRule.class, crit);
74 return (GracePeriodRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
75 }
76
77 @Override
78 @SuppressWarnings("unchecked")
79 public List<GracePeriodRule> getGracePeriodRules(String hourFactor, String active) {
80 List<GracePeriodRule> results = new ArrayList<GracePeriodRule>();
81
82 Criteria root = new Criteria();
83
84 if (StringUtils.isNotBlank(hourFactor)) {
85 root.addLike("hourFactor", hourFactor);
86 }
87
88 if (StringUtils.isNotBlank(active)) {
89 Criteria activeFilter = new Criteria();
90 if (StringUtils.equals(active, "Y")) {
91 activeFilter.addEqualTo("active", true);
92 } else if (StringUtils.equals(active, "N")) {
93 activeFilter.addEqualTo("active", false);
94 }
95 root.addAndCriteria(activeFilter);
96 }
97
98 Query query = QueryFactory.newQuery(GracePeriodRule.class, root);
99 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
100
101 return results;
102 }
103
104 }