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 com.google.common.collect.ImmutableList;
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.ojb.broker.query.Criteria;
25 import org.apache.ojb.broker.query.Query;
26 import org.apache.ojb.broker.query.QueryFactory;
27 import org.apache.ojb.broker.query.ReportQueryByCriteria;
28 import org.kuali.hr.core.util.OjbSubQueryUtil;
29 import org.kuali.hr.time.position.Position;
30 import org.kuali.hr.time.util.TKUtils;
31 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
32
33 public class PositionDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements PositionDao {
34 private static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
35 .add("positionNumber")
36 .build();
37
38 @Override
39 public Position getPosition(String hrPositionId) {
40 Criteria crit = new Criteria();
41 crit.addEqualTo("hrPositionId", hrPositionId);
42
43 Query query = QueryFactory.newQuery(Position.class, crit);
44 return (Position) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
45 }
46
47
48 @Override
49 public Position getPosition(String positionNumber, Date effectiveDate) {
50 Criteria root = new Criteria();
51
52 root.addEqualTo("positionNumber", positionNumber);
53 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(Position.class, effectiveDate, EQUAL_TO_FIELDS, false));
54 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(Position.class, EQUAL_TO_FIELDS, false));
55
56 Criteria activeFilter = new Criteria();
57 activeFilter.addEqualTo("active", true);
58 root.addAndCriteria(activeFilter);
59
60 Query query = QueryFactory.newQuery(Position.class, root);
61 return (Position) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
62 }
63
64 @Override
65 @SuppressWarnings("unchecked")
66 public List<Position> getPositions(String positionNum, String workArea, String description, Date fromEffdt, Date toEffdt,
67 String active, String showHistory) {
68
69 List<Position> results = new ArrayList<Position>();
70
71 Criteria root = new Criteria();
72
73 if (StringUtils.isNotBlank(positionNum)) {
74 root.addLike("positionNumber", positionNum);
75 }
76
77 if (StringUtils.isNotBlank(workArea)) {
78 root.addLike("workArea", workArea);
79 }
80
81 if (StringUtils.isNotBlank(description)) {
82 root.addLike("description", description);
83 }
84
85 Criteria effectiveDateFilter = new Criteria();
86 if (fromEffdt != null) {
87 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt);
88 }
89 if (toEffdt != null) {
90 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt);
91 }
92 if (fromEffdt == null && toEffdt == null) {
93 effectiveDateFilter.addLessOrEqualThan("effectiveDate", TKUtils.getCurrentDate());
94 }
95 root.addAndCriteria(effectiveDateFilter);
96
97 if (StringUtils.isNotBlank(active)) {
98 Criteria activeFilter = new Criteria();
99 if (StringUtils.equals(active, "Y")) {
100 activeFilter.addEqualTo("active", true);
101 } else if (StringUtils.equals(active, "N")) {
102 activeFilter.addEqualTo("active", false);
103 }
104 root.addAndCriteria(activeFilter);
105 }
106
107 if (StringUtils.equals(showHistory, "N")) {
108 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(Position.class, effectiveDateFilter, EQUAL_TO_FIELDS, false));
109 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(Position.class, EQUAL_TO_FIELDS, false));
110 }
111
112 Query query = QueryFactory.newQuery(Position.class, root);
113 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
114
115 return results;
116 }
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 }