1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.position.dao;
17
18 import java.sql.Date;
19 import java.util.ArrayList;
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.apache.ojb.broker.query.ReportQueryByCriteria;
27 import org.kuali.hr.time.position.Position;
28 import org.kuali.hr.time.util.TKUtils;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31 public class PositionDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements PositionDao {
32
33 @Override
34 public Position getPosition(String hrPositionId) {
35 Criteria crit = new Criteria();
36 crit.addEqualTo("hrPositionId", hrPositionId);
37
38 Query query = QueryFactory.newQuery(Position.class, crit);
39 return (Position) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
40 }
41
42
43 @Override
44 public Position getPositionByPositionNumber(String hrPositionNbr) {
45 Criteria crit = new Criteria();
46 crit.addEqualTo("position_nbr", hrPositionNbr);
47
48 Query query = QueryFactory.newQuery(Position.class, crit);
49 return (Position) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
50 }
51
52 @Override
53 @SuppressWarnings("unchecked")
54 public List<Position> getPositions(String positionNum, String workArea, String description, Date fromEffdt, Date toEffdt,
55 String active, String showHistory) {
56
57 List<Position> results = new ArrayList<Position>();
58
59 Criteria root = new Criteria();
60
61 if (StringUtils.isNotBlank(positionNum)) {
62 root.addLike("positionNumber", positionNum);
63 }
64
65 if (StringUtils.isNotBlank(workArea)) {
66 root.addLike("workArea", workArea);
67 }
68
69 if (StringUtils.isNotBlank(description)) {
70 root.addLike("description", description);
71 }
72
73 Criteria effectiveDateFilter = new Criteria();
74 if (fromEffdt != null) {
75 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt);
76 }
77 if (toEffdt != null) {
78 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt);
79 }
80 if (fromEffdt == null && toEffdt == null) {
81 effectiveDateFilter.addLessOrEqualThan("effectiveDate", TKUtils.getCurrentDate());
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 Criteria effdt = new Criteria();
97 effdt.addEqualToField("positionNumber", Criteria.PARENT_QUERY_PREFIX + "positionNumber");
98 effdt.addAndCriteria(effectiveDateFilter);
99 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(Position.class, effdt);
100 effdtSubQuery.setAttributes(new String[]{"max(effectiveDate)"});
101 root.addEqualTo("effectiveDate", effdtSubQuery);
102
103 Criteria timestamp = new Criteria();
104 timestamp.addEqualToField("positionNumber", Criteria.PARENT_QUERY_PREFIX + "positionNumber");
105 timestamp.addAndCriteria(effectiveDateFilter);
106 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(Position.class, timestamp);
107 timestampSubQuery.setAttributes(new String[]{"max(timestamp)"});
108 root.addEqualTo("timestamp", timestampSubQuery);
109 }
110
111 Query query = QueryFactory.newQuery(Position.class, root);
112 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
113
114 return results;
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 }