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