1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.rules.overtime.daily.dao;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.apache.ojb.broker.query.Criteria;
23 import org.apache.ojb.broker.query.Query;
24 import org.apache.ojb.broker.query.QueryFactory;
25 import org.joda.time.LocalDate;
26 import org.kuali.kpme.core.util.OjbSubQueryUtil;
27 import org.kuali.kpme.tklm.time.rules.overtime.daily.DailyOvertimeRule;
28 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29
30 public class DailyOvertimeRuleDaoOjbImpl extends PlatformAwareDaoBaseOjb implements DailyOvertimeRuleDao {
31 @Override
32 public DailyOvertimeRule findDailyOvertimeRule(String location, String paytype, String dept, Long workArea, LocalDate asOfDate) {
33 DailyOvertimeRule dailyOvertimeRule;
34
35 Criteria root = new Criteria();
36 root.addEqualTo("dept", dept);
37 root.addEqualTo("workArea", workArea);
38 root.addEqualTo("location", location);
39 root.addEqualTo("paytype", paytype);
40 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(DailyOvertimeRule.class, asOfDate, DailyOvertimeRule.EQUAL_TO_FIELDS, false));
41 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(DailyOvertimeRule.class, DailyOvertimeRule.EQUAL_TO_FIELDS, false));
42
43 Criteria activeFilter = new Criteria();
44 activeFilter.addEqualTo("active", true);
45 root.addAndCriteria(activeFilter);
46
47
48 Query query = QueryFactory.newQuery(DailyOvertimeRule.class, root);
49 dailyOvertimeRule = (DailyOvertimeRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
50
51 return dailyOvertimeRule;
52 }
53
54 @Override
55 public void saveOrUpdate(DailyOvertimeRule dailyOvertimeRule) {
56 this.getPersistenceBrokerTemplate().store(dailyOvertimeRule);
57 }
58
59 @Override
60 public void saveOrUpdate(List<DailyOvertimeRule> dailyOvertimeRules) {
61 for (DailyOvertimeRule dor : dailyOvertimeRules) {
62 saveOrUpdate(dor);
63 }
64 }
65
66 @Override
67 public DailyOvertimeRule getDailyOvertimeRule(String tkDailyOvertimeRuleId) {
68 Criteria crit = new Criteria();
69 crit.addEqualTo("tkDailyOvertimeRuleId", tkDailyOvertimeRuleId);
70
71 Query query = QueryFactory.newQuery(DailyOvertimeRule.class, crit);
72 return (DailyOvertimeRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
73 }
74
75 @Override
76 public List<DailyOvertimeRule> getDailyOvertimeRules(String dept, String workArea, String location, LocalDate fromEffdt, LocalDate toEffdt, String active, String showHist) {
77 List<DailyOvertimeRule> results = new ArrayList<DailyOvertimeRule>();
78
79 Criteria root = new Criteria();
80
81 if (StringUtils.isNotBlank(dept)) {
82 root.addLike("dept", dept);
83 }
84
85 if (StringUtils.isNotBlank(workArea)) {
86 OjbSubQueryUtil.addNumericCriteria(root, "workArea", workArea);
87 }
88
89
90 if (StringUtils.isNotBlank(location)) {
91 root.addLike("UPPER(location)", location.toUpperCase());
92 }
93
94 Criteria effectiveDateFilter = new Criteria();
95 if (fromEffdt != null) {
96 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
97 }
98 if (toEffdt != null) {
99 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
100 }
101 if (fromEffdt == null && toEffdt == null) {
102 effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
103 }
104 root.addAndCriteria(effectiveDateFilter);
105
106 if (StringUtils.isNotBlank(active)) {
107 Criteria activeFilter = new Criteria();
108 if (StringUtils.equals(active, "Y")) {
109 activeFilter.addEqualTo("active", true);
110 } else if (StringUtils.equals(active, "N")) {
111 activeFilter.addEqualTo("active", false);
112 }
113 root.addAndCriteria(activeFilter);
114 }
115
116 if (StringUtils.equals(showHist, "N")) {
117 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(DailyOvertimeRule.class, effectiveDateFilter, DailyOvertimeRule.EQUAL_TO_FIELDS, false));
118 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(DailyOvertimeRule.class, DailyOvertimeRule.EQUAL_TO_FIELDS, false));
119 }
120
121 Query query = QueryFactory.newQuery(DailyOvertimeRule.class, root);
122 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
123
124 return results;
125 }
126
127 }