1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.pm.positionreportsubcat.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.HrConstants;
28 import org.kuali.kpme.core.util.OjbSubQueryUtil;
29 import org.kuali.kpme.core.util.ValidationUtils;
30 import org.kuali.kpme.pm.positionreportsubcat.PositionReportSubCategory;
31 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
32
33 public class PositionReportSubCatDaoObjImpl extends PlatformAwareDaoBaseOjb implements PositionReportSubCatDao {
34 public PositionReportSubCategory getPositionReportSubCatById(
35 String pmPositionReportSubCatId) {
36 Criteria crit = new Criteria();
37 crit.addEqualTo("pmPositionReportSubCatId", pmPositionReportSubCatId);
38
39 Query query = QueryFactory.newQuery(PositionReportSubCategory.class, crit);
40 return (PositionReportSubCategory) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
41 }
42
43 public List<PositionReportSubCategory> getPositionReportSubCat(String pstnRptSubCat, String institution, String location, LocalDate asOfDate) {
44 List<PositionReportSubCategory> prscList = new ArrayList<PositionReportSubCategory>();
45 Criteria root = new Criteria();
46 if(StringUtils.isNotEmpty(pstnRptSubCat)
47 && !ValidationUtils.isWildCard(pstnRptSubCat)) {
48 root.addEqualTo("positionReportSubCat", pstnRptSubCat);
49 }
50 if(StringUtils.isNotEmpty(institution)
51 && !ValidationUtils.isWildCard(institution)) {
52 root.addEqualTo("institution", institution);
53 }
54 if(StringUtils.isNotEmpty(location)
55 && !ValidationUtils.isWildCard(location)) {
56 root.addEqualTo("location", location);
57 }
58 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PositionReportSubCategory.class, asOfDate, PositionReportSubCategory.EQUAL_TO_FIELDS, false));
59 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionReportSubCategory.class, PositionReportSubCategory.EQUAL_TO_FIELDS, false));
60
61 Criteria activeFilter = new Criteria();
62 activeFilter.addEqualTo("active", true);
63 root.addAndCriteria(activeFilter);
64 Query query = QueryFactory.newQuery(PositionReportSubCategory.class, root);
65
66 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
67 if(!c.isEmpty())
68 prscList.addAll(c);
69
70 return prscList;
71 }
72
73 @Override
74 public PositionReportSubCategory getPositionReportSubCat(String pstnRptSubCat, LocalDate asOfDate) {
75 Criteria root = new Criteria();
76 root.addEqualTo("positionReportSubCat", pstnRptSubCat);
77 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PositionReportSubCategory.class, asOfDate, PositionReportSubCategory.EQUAL_TO_FIELDS, false));
78 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionReportSubCategory.class, PositionReportSubCategory.EQUAL_TO_FIELDS, false));
79 Criteria activeFilter = new Criteria();
80 activeFilter.addEqualTo("active", true);
81 root.addAndCriteria(activeFilter);
82
83 Query query = QueryFactory.newQuery(PositionReportSubCategory.class, root);
84 return (PositionReportSubCategory) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
85 }
86
87 }