1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.pm.positionflag.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.positionflag.PositionFlag;
30 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
31
32 public class PositionFlagDaoObjImpl extends PlatformAwareDaoBaseOjb implements PositionFlagDao {
33
34 @Override
35 public PositionFlag getPositionFlagById(String pmPositionFlagId) {
36 Criteria crit = new Criteria();
37 crit.addEqualTo("pmPositionFlagId", pmPositionFlagId);
38
39 Query query = QueryFactory.newQuery(PositionFlag.class, crit);
40 return (PositionFlag) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
41 }
42
43 @Override
44 public List<PositionFlag> getAllActivePositionFlags(String category, String name, LocalDate effDate) {
45 List<PositionFlag> pfList = new ArrayList<PositionFlag>();
46 Criteria root = new Criteria();
47
48 if(StringUtils.isNotEmpty(category)
49 && !ValidationUtils.isWildCard(category)) {
50 root.addEqualTo("category", category);
51 }
52 if(StringUtils.isNotEmpty(name)
53 && !ValidationUtils.isWildCard(name)) {
54 root.addEqualTo("positionFlagName", name);
55 }
56
57 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PositionFlag.class, effDate, PositionFlag.EQUAL_TO_FIELDS, false));
58 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionFlag.class, PositionFlag.EQUAL_TO_FIELDS, false));
59
60 Criteria activeFilter = new Criteria();
61 activeFilter.addEqualTo("active", true);
62 root.addAndCriteria(activeFilter);
63
64 Query query = QueryFactory.newQuery(PositionFlag.class, root);
65
66 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
67 if(!c.isEmpty())
68 pfList.addAll(c);
69
70 return pfList;
71 }
72
73 @Override
74 public List<String> getAllActiveFlagCategories() {
75 List<String> categoryList = new ArrayList<String>();
76 Criteria root = new Criteria();
77 root.addEqualTo("active", true);
78 Query query = QueryFactory.newQuery(PositionFlag.class, root);
79
80 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
81 List<PositionFlag> pfList = new ArrayList<PositionFlag>();
82 if(!c.isEmpty())
83 pfList.addAll(c);
84
85 for(PositionFlag aFlag : pfList) {
86 if(aFlag != null && StringUtils.isNotEmpty(aFlag.getCategory())
87 && !categoryList.contains(aFlag.getCategory())) {
88 categoryList.add(aFlag.getCategory());
89 }
90 }
91 return categoryList;
92 }
93
94 @Override
95 public List<PositionFlag> getAllActivePositionFlagsWithCategory(String category, LocalDate effDate) {
96 List<PositionFlag> pfList = new ArrayList<PositionFlag>();
97 Criteria root = new Criteria();
98 if(StringUtils.isEmpty(category)) {
99 return pfList;
100 }
101 root.addEqualTo("category", category);
102
103 if(effDate != null) {
104 root.addLessOrEqualThan("effectiveDate", effDate.toDate());
105 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PositionFlag.class, effDate, PositionFlag.EQUAL_TO_FIELDS, false));
106 }
107 Criteria activeFilter = new Criteria();
108 activeFilter.addEqualTo("active", true);
109 root.addAndCriteria(activeFilter);
110
111 Query query = QueryFactory.newQuery(PositionFlag.class, root);
112
113 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
114 if(!c.isEmpty())
115 pfList.addAll(c);
116
117 return pfList;
118 }
119
120 }