1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.salarygroup.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.DateTime;
26 import org.joda.time.LocalDate;
27 import org.kuali.kpme.core.salarygroup.SalaryGroupBo;
28 import org.kuali.kpme.core.util.OjbSubQueryUtil;
29 import org.kuali.rice.core.api.util.Truth;
30 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
31
32 public class SalaryGroupDaoOjbImpl extends PlatformAwareDaoBaseOjb implements SalaryGroupDao {
33 @Override
34 public void saveOrUpdate(SalaryGroupBo salaryGroup) {
35 this.getPersistenceBrokerTemplate().store(salaryGroup);
36 }
37
38 @Override
39 public SalaryGroupBo getSalaryGroup(String salGroup, LocalDate asOfDate) {
40 Criteria root = new Criteria();
41
42 root.addEqualTo("hrSalGroup", salGroup);
43 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(SalaryGroupBo.class, asOfDate, SalaryGroupBo.BUSINESS_KEYS, false));
44 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(SalaryGroupBo.class, SalaryGroupBo.BUSINESS_KEYS, false));
45 Criteria activeFilter = new Criteria();
46 activeFilter.addEqualTo("active", true);
47 root.addAndCriteria(activeFilter);
48
49 Query query = QueryFactory.newQuery(SalaryGroupBo.class, root);
50 SalaryGroupBo s = (SalaryGroupBo)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
51
52 return s;
53 }
54
55 @Override
56 public SalaryGroupBo getSalaryGroup(String hrSalGroupId) {
57 Criteria crit = new Criteria();
58 crit.addEqualTo("hrSalGroupId", hrSalGroupId);
59
60 Query query = QueryFactory.newQuery(SalaryGroupBo.class, crit);
61 return (SalaryGroupBo)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
62 }
63 @Override
64 public int getSalGroupCount(String salGroup) {
65 Criteria crit = new Criteria();
66 crit.addEqualTo("hrSalGroup", salGroup);
67 Query query = QueryFactory.newQuery(SalaryGroupBo.class, crit);
68 return this.getPersistenceBrokerTemplate().getCount(query);
69 }
70
71 @Override
72 @SuppressWarnings("unchecked")
73 public List<SalaryGroupBo> getSalaryGroups(String hrSalGroup, String institution, String location, String leavePlan, LocalDate fromEffdt, LocalDate toEffdt, String active, String showHistory, String benefitEligible, String leaveEligible, String percentTime) {
74 List<SalaryGroupBo> results = new ArrayList<SalaryGroupBo>();
75
76 Criteria root = new Criteria();
77
78 if (StringUtils.isNotBlank(hrSalGroup)) {
79 root.addLike("UPPER(hrSalGroup)", hrSalGroup.toUpperCase());
80 }
81
82
83 if (StringUtils.isNotBlank(institution)) {
84 root.addLike("UPPER(institution)", institution.toUpperCase());
85 }
86 if (StringUtils.isNotBlank(location)) {
87 root.addLike("UPPER(location)", location.toUpperCase());
88 }
89 if (StringUtils.isNotBlank(leavePlan)) {
90 root.addLike("UPPER(leavePlan)", leavePlan.toUpperCase());
91 }
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", DateTime.now().toDate());
103 }
104 root.addAndCriteria(effectiveDateFilter);
105
106 if (StringUtils.isNotBlank(active)) {
107 Criteria activeFilter = new Criteria();
108 if (Truth.strToBooleanIgnoreCase(active)) {
109 activeFilter.addEqualTo("active", true);
110 } else {
111 activeFilter.addEqualTo("active", false);
112 }
113 root.addAndCriteria(activeFilter);
114 }
115
116 if (StringUtils.isNotBlank(benefitEligible)) {
117 Criteria benefitEligibleFilter = new Criteria();
118 benefitEligibleFilter.addEqualTo("benefitsEligible", benefitEligible);
119 root.addAndCriteria(benefitEligibleFilter);
120 }
121
122 if (StringUtils.isNotBlank(leaveEligible)) {
123 Criteria leaveEligibleFilter = new Criteria();
124 leaveEligibleFilter.addEqualTo("leaveEligible", leaveEligible);
125 root.addAndCriteria(leaveEligibleFilter);
126 }
127
128 if (StringUtils.isNotBlank(percentTime)) {
129 Criteria percentTimeFilter = new Criteria();
130 percentTimeFilter.addEqualTo("percentTime", percentTime);
131 root.addAndCriteria(percentTimeFilter);
132 }
133
134 if (StringUtils.equals(showHistory, "N")) {
135 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(SalaryGroupBo.class, effectiveDateFilter, SalaryGroupBo.BUSINESS_KEYS, false));
136 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(SalaryGroupBo.class, SalaryGroupBo.BUSINESS_KEYS, false));
137 }
138
139 Query query = QueryFactory.newQuery(SalaryGroupBo.class, root);
140 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
141
142 return results;
143 }
144
145 }