1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.override.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.LocalDate;
27 import org.kuali.kpme.core.util.OjbSubQueryUtil;
28 import org.kuali.kpme.tklm.leave.override.EmployeeOverride;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31 public class EmployeeOverrideDaoOjbImpl extends PlatformAwareDaoBaseOjb implements EmployeeOverrideDao{
32
33 @SuppressWarnings("unchecked")
34 @Override
35 public List<EmployeeOverride> getEmployeeOverrides(String principalId, LocalDate asOfDate) {
36 List<EmployeeOverride> employeeOverrides = new ArrayList<EmployeeOverride>();
37 Criteria root = new Criteria();
38
39 root.addEqualTo("principalId", principalId);
40 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EmployeeOverride.class, asOfDate, EmployeeOverride.EQUAL_TO_FIELDS, false));
41 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EmployeeOverride.class, EmployeeOverride.EQUAL_TO_FIELDS, false));
42
43 Criteria activeFilter = new Criteria();
44 activeFilter.addEqualTo("active", true);
45 root.addAndCriteria(activeFilter);
46
47 Query query = QueryFactory.newQuery(EmployeeOverride.class, root);
48 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
49
50 if (c != null) {
51 employeeOverrides.addAll(c);
52 }
53 return employeeOverrides;
54 }
55
56 @Override
57 public EmployeeOverride getEmployeeOverride(String principalId, String leavePlan, String accrualCategory, String overrideType, LocalDate asOfDate) {
58 Criteria root = new Criteria();
59
60 root.addEqualTo("principalId", principalId);
61 root.addEqualTo("leavePlan", leavePlan);
62 root.addEqualTo("accrualCategory", accrualCategory);
63 root.addEqualTo("overrideType", overrideType);
64
65 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EmployeeOverride.class, asOfDate, EmployeeOverride.EQUAL_TO_FIELDS, false));
66 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EmployeeOverride.class, EmployeeOverride.EQUAL_TO_FIELDS, false));
67
68 Criteria activeFilter = new Criteria();
69 activeFilter.addEqualTo("active", true);
70 root.addAndCriteria(activeFilter);
71
72 Query query = QueryFactory.newQuery(EmployeeOverride.class, root);
73 return (EmployeeOverride) getPersistenceBrokerTemplate().getObjectByQuery(query);
74 }
75
76 @Override
77 public EmployeeOverride getEmployeeOverride(String lmEmployeeOverrideId) {
78 Criteria crit = new Criteria();
79 crit.addEqualTo("lmEmployeeOverrideId", lmEmployeeOverrideId);
80 Query query = QueryFactory.newQuery(EmployeeOverride.class, crit);
81 return (EmployeeOverride) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
82 }
83
84 @Override
85 @SuppressWarnings("unchecked")
86 public List<EmployeeOverride> getEmployeeOverrides(String principalId, String leavePlan, String accrualCategory, String overrideType,
87 LocalDate fromEffdt, LocalDate toEffdt, String active) {
88
89 List<EmployeeOverride> results = new ArrayList<EmployeeOverride>();
90
91 Criteria root = new Criteria();
92
93 if (StringUtils.isNotBlank(principalId)) {
94 root.addLike("UPPER(`principal_id`)",principalId.toUpperCase());
95 }
96
97 if (StringUtils.isNotBlank(leavePlan)) {
98 root.addEqualTo("UPPER(`leave_plan`)",leavePlan.toUpperCase());
99 }
100
101 if (StringUtils.isNotBlank(accrualCategory)) {
102 root.addLike("UPPER(`accrual_cat`)",accrualCategory.toUpperCase());
103 }
104
105 if (StringUtils.isNotBlank(overrideType)) {
106 root.addEqualTo("overrideType",overrideType);
107 }
108
109 Criteria effectiveDateFilter = new Criteria();
110 if (fromEffdt != null) {
111 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
112 }
113 if (toEffdt != null) {
114 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
115 }
116 if (fromEffdt == null && toEffdt == null) {
117 effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
118 }
119 root.addAndCriteria(effectiveDateFilter);
120
121 if (StringUtils.isNotBlank(active)) {
122 Criteria activeFilter = new Criteria();
123 if (StringUtils.equals(active, "Y")) {
124 activeFilter.addEqualTo("active", true);
125 } else if (StringUtils.equals(active, "N")) {
126 activeFilter.addEqualTo("active", false);
127 }
128 root.addAndCriteria(activeFilter);
129 }
130
131 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(EmployeeOverride.class, effectiveDateFilter, EmployeeOverride.EQUAL_TO_FIELDS, false));
132 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EmployeeOverride.class, EmployeeOverride.EQUAL_TO_FIELDS, false));
133
134 Query query = QueryFactory.newQuery(EmployeeOverride.class, root);
135 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
136
137 return results;
138 }
139
140 }