View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.pm.position.dao;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.apache.ojb.broker.query.Criteria;
23  import org.apache.ojb.broker.query.Query;
24  import org.apache.ojb.broker.query.QueryFactory;
25  import org.joda.time.LocalDate;
26  import org.kuali.kpme.core.util.OjbSubQueryUtil;
27  import org.kuali.kpme.pm.position.Position;
28  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29  
30  public class PositionDaoObjImpl extends PlatformAwareDaoBaseOjb implements PositionDao {
31  
32  	@Override
33  	public Position getPosition(String id) {
34  		 Criteria crit = new Criteria();
35          crit.addEqualTo("hrPositionId", id);
36  
37          Query query = QueryFactory.newQuery(Position.class, crit);
38          return (Position) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
39  	}
40  
41  	@Override
42  	public List<Position> getPositions(String positionNum, String description, String workingPositionTitle, String campus,
43              String institution, String classificationTitle, String positionType, String poolEligible,
44  			LocalDate fromEffdt, LocalDate toEffdt, String active,
45  			String showHistory) {
46  		List<Position> results = new ArrayList<Position>();
47  	        
48      	Criteria root = new Criteria();
49  
50      	// KPME-2695
51          if (StringUtils.isNotBlank(positionNum)) {
52              root.addLike("UPPER(positionNumber)", positionNum.toUpperCase()); // just in case position number is not a number
53          }
54  
55          if (StringUtils.isNotBlank(description)) {
56              root.addLike("UPPER(description)", description.toUpperCase());
57          }
58  
59          if (StringUtils.isNotBlank(workingPositionTitle)) {
60              root.addLike("UPPER(workingPositionTitle)", workingPositionTitle.toUpperCase());
61          }
62  
63          if (StringUtils.isNotBlank(campus)) {
64              root.addLike("UPPER(campus)", campus.toUpperCase());
65          }
66  
67          if (StringUtils.isNotBlank(institution)) {
68              root.addLike("UPPER(institution)", institution.toUpperCase());
69          }
70  
71          if (StringUtils.isNotBlank(classificationTitle)) {
72              root.addLike("UPPER(classificationTitle)", classificationTitle.toUpperCase());
73          }
74  
75          if (StringUtils.isNotBlank(positionType)) {
76              root.addLike("UPPER(positionType)", positionType.toUpperCase());
77          }
78  
79          if (StringUtils.isNotBlank(poolEligible)) {
80              root.addEqualTo("poolEligible", poolEligible);
81  
82          }
83          Criteria effectiveDateFilter = new Criteria();
84          if (fromEffdt != null) {
85              effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
86          }
87          if (toEffdt != null) {
88              effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
89          }
90          if (fromEffdt == null && toEffdt == null) {
91              effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
92          }
93          root.addAndCriteria(effectiveDateFilter);
94          
95          if (StringUtils.isNotBlank(active)) {
96          	Criteria activeFilter = new Criteria();
97              if (StringUtils.equals(active, "Y")) {
98                  activeFilter.addEqualTo("active", true);
99              } else if (StringUtils.equals(active, "N")) {
100                 activeFilter.addEqualTo("active", false);
101             }
102             root.addAndCriteria(activeFilter);
103         }
104 
105         if (StringUtils.equals(showHistory, "N")) {
106             root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(Position.class, effectiveDateFilter, Position.EQUAL_TO_FIELDS, false));
107             root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(Position.class, Position.EQUAL_TO_FIELDS, false));
108         }
109         
110         Query query = QueryFactory.newQuery(Position.class, root);
111         results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
112 
113         return results;
114 	}
115 	
116 	
117 
118 	
119 }