1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.pm.positionappointment.dao;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
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.joda.time.LocalDate;
27 import org.kuali.kpme.core.util.OjbSubQueryUtil;
28 import org.kuali.kpme.core.util.ValidationUtils;
29 import org.kuali.kpme.pm.positionappointment.PositionAppointmentBo;
30 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
31
32 import com.google.common.collect.ImmutableList;
33
34 public class PositionAppointmentDaoObjImpl extends PlatformAwareDaoBaseOjb implements PositionAppointmentDao {
35
36 private static final ImmutableList<String> PRG_BUSINESS_KEYS = new ImmutableList.Builder<String>()
37 .add("positionAppointment").add("institution").add("location")
38 .build();
39
40 public PositionAppointmentBo getPositionAppointmentById(String pmPositionAppointmentId) {
41
42 Criteria crit = new Criteria();
43 crit.addEqualTo("pmPositionAppointmentId", pmPositionAppointmentId);
44
45 Query query = QueryFactory.newQuery(PositionAppointmentBo.class, crit);
46 return (PositionAppointmentBo) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
47 }
48
49 public List<PositionAppointmentBo> getPositionAppointmentList(String positionAppointment, String description, String groupKeyCode,
50 LocalDate fromEffdt, LocalDate toEffdt, String active, String showHistory) {
51
52 List<PositionAppointmentBo> prgList = new ArrayList<PositionAppointmentBo>();
53 Criteria root = new Criteria();
54
55 if (StringUtils.isNotEmpty(positionAppointment)
56 && !ValidationUtils.isWildCard(positionAppointment)) {
57 root.addLike("UPPER(positionAppointment)", positionAppointment.toUpperCase());
58 }
59
60 if (StringUtils.isNotEmpty(description)
61 && !ValidationUtils.isWildCard(description)) {
62 root.addLike("UPPER(description)", description.toUpperCase());
63 }
64
65 if (StringUtils.isNotEmpty(groupKeyCode)) {
66 root.addLike("UPPER(groupKeyCode)", groupKeyCode.toUpperCase());
67 }
68
69 Criteria effectiveDateFilter = new Criteria();
70 if (fromEffdt != null) {
71 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
72 }
73 if (toEffdt != null) {
74 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
75 }
76 if (fromEffdt == null && toEffdt == null) {
77 effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
78 }
79 root.addAndCriteria(effectiveDateFilter);
80
81 if (StringUtils.isNotBlank(active)) {
82 Criteria activeFilter = new Criteria();
83 if (StringUtils.equals(active, "Y")) {
84 activeFilter.addEqualTo("active", true);
85 } else if (StringUtils.equals(active, "N")) {
86 activeFilter.addEqualTo("active", false);
87 }
88 root.addAndCriteria(activeFilter);
89 }
90
91
92
93 if (StringUtils.equals(showHistory, "N")) {
94 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(PositionAppointmentBo.class, effectiveDateFilter, PRG_BUSINESS_KEYS , false));
95 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionAppointmentBo.class, PRG_BUSINESS_KEYS , false));
96 }
97
98
99 Query query = QueryFactory.newQuery(PositionAppointmentBo.class, root);
100
101 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
102
103 if (!c.isEmpty())
104 prgList.addAll(c);
105
106 return prgList;
107 }
108
109 public List<PositionAppointmentBo> getPositionAppointmentList(String positionAppointment, String groupKeyCode, LocalDate asOfDate) {
110
111 List<PositionAppointmentBo> prgList = new ArrayList<PositionAppointmentBo>();
112 Criteria root = new Criteria();
113
114 if (StringUtils.isNotEmpty(positionAppointment)
115 && !ValidationUtils.isWildCard(positionAppointment)) {
116 root.addLike("UPPER(`pstn_appointment`)", positionAppointment.toUpperCase());
117 }
118
119 if (StringUtils.isNotEmpty(groupKeyCode)) {
120 root.addLike("UPPER(groupKeyCode)", groupKeyCode.toUpperCase());
121 }
122
123 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PositionAppointmentBo.class, asOfDate, PositionAppointmentBo.BUSINESS_KEYS, false));
124 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionAppointmentBo.class, PositionAppointmentBo.BUSINESS_KEYS, false));
125
126 Criteria activeFilter = new Criteria();
127 activeFilter.addEqualTo("active", true);
128 root.addAndCriteria(activeFilter);
129
130 Query query = QueryFactory.newQuery(PositionAppointmentBo.class, root);
131
132 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
133
134 if (!c.isEmpty())
135 prgList.addAll(c);
136
137 return prgList;
138 }
139 }