1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.position.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.position.PositionBaseBo;
27 import org.kuali.kpme.core.util.OjbSubQueryUtil;
28 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29
30 public class PositionBaseDaoOjbImpl extends PlatformAwareDaoBaseOjb implements PositionBaseDao {
31
32 @Override
33 public PositionBaseBo getPosition(String hrPositionId) {
34 Criteria crit = new Criteria();
35 crit.addEqualTo("hrPositionId", hrPositionId);
36
37 Query query = QueryFactory.newQuery(PositionBaseBo.class, crit);
38 return (PositionBaseBo) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
39 }
40
41
42 @Override
43 public PositionBaseBo getPosition(String positionNumber, LocalDate effectiveDate) {
44 Criteria root = new Criteria();
45
46 root.addEqualTo("positionNumber", positionNumber);
47 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PositionBaseBo.class, effectiveDate, PositionBaseBo.BUSINESS_KEYS, false));
48 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionBaseBo.class, PositionBaseBo.BUSINESS_KEYS, false));
49
50 Criteria activeFilter = new Criteria();
51 activeFilter.addEqualTo("active", true);
52 root.addAndCriteria(activeFilter);
53
54 Query query = QueryFactory.newQuery(PositionBaseBo.class, root);
55 return (PositionBaseBo) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
56 }
57
58 @Override
59 @SuppressWarnings("unchecked")
60 public List<PositionBaseBo> getPositions(String positionNum, String description, LocalDate fromEffdt, LocalDate toEffdt, String active, String showHistory) {
61 List<PositionBaseBo> results = new ArrayList<PositionBaseBo>();
62
63 Criteria root = new Criteria();
64
65 if (StringUtils.isNotBlank(positionNum)) {
66 root.addLike("positionNumber", positionNum);
67 }
68
69 if (StringUtils.isNotBlank(description)) {
70 root.addLike("UPPER(description)", description.toUpperCase());
71 }
72
73 Criteria effectiveDateFilter = new Criteria();
74 if (fromEffdt != null) {
75 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
76 }
77 if (toEffdt != null) {
78 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
79 }
80 if (fromEffdt == null && toEffdt == null) {
81 effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
82 }
83 root.addAndCriteria(effectiveDateFilter);
84
85 if (StringUtils.isNotBlank(active)) {
86 Criteria activeFilter = new Criteria();
87 if (StringUtils.equals(active, "Y")) {
88 activeFilter.addEqualTo("active", true);
89 } else if (StringUtils.equals(active, "N")) {
90 activeFilter.addEqualTo("active", false);
91 }
92 root.addAndCriteria(activeFilter);
93 }
94
95 if (StringUtils.equals(showHistory, "N")) {
96 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(PositionBaseBo.class, effectiveDateFilter, PositionBaseBo.BUSINESS_KEYS, false));
97 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionBaseBo.class, PositionBaseBo.BUSINESS_KEYS, false));
98 }
99
100 Query query = QueryFactory.newQuery(PositionBaseBo.class, root);
101 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
102
103 return results;
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 }