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.core.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.position.PositionBaseBo;
27  import org.kuali.kpme.core.util.OjbSubQueryUtil;
28  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29  
30  public class PositionBaseDaoOjbImpl extends PlatformAwareDaoBaseOjb implements PositionBaseDao {
31      
32      @Override
33      public PositionBaseBo getPosition(String hrPositionId) {
34          Criteria crit = new Criteria();
35          crit.addEqualTo("hrPositionId", hrPositionId);
36  
37          Query query = QueryFactory.newQuery(PositionBaseBo.class, crit);
38          return (PositionBaseBo) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
39      }
40  
41  
42      @Override
43      public PositionBaseBo getPosition(String positionNumber, LocalDate effectiveDate) {
44          Criteria root = new Criteria();
45  
46          root.addEqualTo("positionNumber", positionNumber);
47          root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PositionBaseBo.class, effectiveDate, PositionBaseBo.BUSINESS_KEYS, false));
48          root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionBaseBo.class, PositionBaseBo.BUSINESS_KEYS, false));
49  
50          Criteria activeFilter = new Criteria(); // Inner Join For Activity
51          activeFilter.addEqualTo("active", true);
52          root.addAndCriteria(activeFilter);
53  
54          Query query = QueryFactory.newQuery(PositionBaseBo.class, root);
55          return (PositionBaseBo) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
56      }
57  
58  	@Override
59      @SuppressWarnings("unchecked")
60      public List<PositionBaseBo> getPositions(String positionNum, String description, LocalDate fromEffdt, LocalDate toEffdt, String active, String showHistory) {
61          List<PositionBaseBo> results = new ArrayList<PositionBaseBo>();
62          
63      	Criteria root = new Criteria();
64  
65          if (StringUtils.isNotBlank(positionNum)) {
66              root.addLike("positionNumber", positionNum);
67          }
68  
69          if (StringUtils.isNotBlank(description)) {
70              root.addLike("UPPER(description)", description.toUpperCase()); // KPME-2695
71          }
72          
73          Criteria effectiveDateFilter = new Criteria();
74          if (fromEffdt != null) {
75              effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
76          }
77          if (toEffdt != null) {
78              effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
79          }
80          if (fromEffdt == null && toEffdt == null) {
81              effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
82          }
83          root.addAndCriteria(effectiveDateFilter);
84          
85          if (StringUtils.isNotBlank(active)) {
86          	Criteria activeFilter = new Criteria();
87              if (StringUtils.equals(active, "Y")) {
88                  activeFilter.addEqualTo("active", true);
89              } else if (StringUtils.equals(active, "N")) {
90                  activeFilter.addEqualTo("active", false);
91              }
92              root.addAndCriteria(activeFilter);
93          }
94  
95          if (StringUtils.equals(showHistory, "N")) {
96              root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(PositionBaseBo.class, effectiveDateFilter, PositionBaseBo.BUSINESS_KEYS, false));
97              root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionBaseBo.class, PositionBaseBo.BUSINESS_KEYS, false));
98          }
99          
100         Query query = QueryFactory.newQuery(PositionBaseBo.class, root);
101         results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
102 
103         return results;
104     }
105 
106     /*@Override
107     public PositionNumber getNextUniquePositionNumber() {
108         Criteria crit = new Criteria();
109         ReportQueryByCriteria query = QueryFactory.newReportQuery(PositionNumber.class, crit);
110         query.setAttributes(new String[]{"max(id)"});
111         return (PositionNumber) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
112     }
113 
114     @Override
115     public void saveOrUpdate(PositionNumber positionNumber) {
116         this.getPersistenceBrokerTemplate().store(positionNumber);
117     }*/
118 
119 }