1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.rules.shiftdifferential.dao;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
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.joda.time.DateTime;
27 import org.joda.time.LocalDate;
28 import org.kuali.kpme.core.assignment.Assignment;
29 import org.kuali.kpme.core.util.OjbSubQueryUtil;
30 import org.kuali.kpme.tklm.time.rules.shiftdifferential.ShiftDifferentialRule;
31 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
32
33 public class ShiftDifferentialRuleDaoOjbImpl extends PlatformAwareDaoBaseOjb implements ShiftDifferentialRuleDao {
34
35 @Override
36 public ShiftDifferentialRule findShiftDifferentialRule(String id) {
37 Object o = this.getPersistenceBrokerTemplate().getObjectById(ShiftDifferentialRule.class, id);
38
39 return (ShiftDifferentialRule)o;
40 }
41
42 @SuppressWarnings("unchecked")
43 @Override
44 public List<ShiftDifferentialRule> findShiftDifferentialRules(String location, String hrSalGroup, String payGrade, String pyCalendarGroup, LocalDate asOfDate) {
45 List<ShiftDifferentialRule> list = new ArrayList<ShiftDifferentialRule>();
46
47 Criteria root = new Criteria();
48
49 root.addEqualTo("location", location);
50 root.addEqualTo("hrSalGroup", hrSalGroup);
51 root.addEqualTo("payGrade", payGrade);
52 root.addEqualTo("pyCalendarGroup", pyCalendarGroup);
53
54
55
56
57
58
59
60
61 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(ShiftDifferentialRule.class, asOfDate, ShiftDifferentialRule.EQUAL_TO_FIELDS, false));
62 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(ShiftDifferentialRule.class, ShiftDifferentialRule.EQUAL_TO_FIELDS, false));
63
64
65 Criteria activeFilter = new Criteria();
66 activeFilter.addEqualTo("active", true);
67 root.addAndCriteria(activeFilter);
68
69 Query query = QueryFactory.newQuery(ShiftDifferentialRule.class, root);
70 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
71
72 if (c != null) {
73 list.addAll(c);
74 }
75
76 return list;
77 }
78
79 public void saveOrUpdate(ShiftDifferentialRule shiftDifferentialRule) {
80 this.getPersistenceBrokerTemplate().store(shiftDifferentialRule);
81 }
82
83 public void saveOrUpdate(List<ShiftDifferentialRule> shiftDifferentialRules) {
84 for (ShiftDifferentialRule sdr : shiftDifferentialRules) {
85 saveOrUpdate(sdr);
86 }
87 }
88
89 @Override
90 @SuppressWarnings("unchecked")
91 public List<ShiftDifferentialRule> getShiftDifferentialRules(String location, String hrSalGroup, String payGrade, LocalDate fromEffdt, LocalDate toEffdt,
92 String active, String showHistory) {
93
94 List<ShiftDifferentialRule> results = new ArrayList<ShiftDifferentialRule>();
95
96 Criteria root = new Criteria();
97
98 if (StringUtils.isNotBlank(location)) {
99 root.addLike("UPPER(location)", location.toUpperCase());
100 }
101
102 if (StringUtils.isNotBlank(hrSalGroup)) {
103 root.addLike("UPPER(hrSalGroup)", hrSalGroup.toUpperCase());
104 }
105
106 if (StringUtils.isNotBlank(payGrade)) {
107 root.addLike("UPPER(payGrade)", payGrade.toUpperCase());
108 }
109
110 Criteria effectiveDateFilter = new Criteria();
111 if (fromEffdt != null) {
112 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
113 }
114 if (toEffdt != null) {
115 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
116 }
117 if (fromEffdt == null && toEffdt == null) {
118 effectiveDateFilter.addLessOrEqualThan("effectiveDate", DateTime.now().toDate());
119 }
120
121
122 if (StringUtils.isNotBlank(active)) {
123 Criteria activeFilter = new Criteria();
124 if (StringUtils.equals(active, "Y")) {
125 activeFilter.addEqualTo("active", true);
126 } else if (StringUtils.equals(active, "N")) {
127 activeFilter.addEqualTo("active", false);
128 }
129 root.addAndCriteria(activeFilter);
130 }
131
132 if (StringUtils.equals(showHistory, "N")) {
133 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(ShiftDifferentialRule.class, effectiveDateFilter, ShiftDifferentialRule.EQUAL_TO_FIELDS, false));
134 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(ShiftDifferentialRule.class, ShiftDifferentialRule.EQUAL_TO_FIELDS, false));
135 }
136
137 Query query = QueryFactory.newQuery(ShiftDifferentialRule.class, root);
138 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
139
140 return results;
141 }
142
143 }