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.paystep.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.kuali.kpme.core.paystep.PayStepBo;
26  import org.kuali.kpme.core.util.HrConstants;
27  import org.kuali.kpme.core.util.OjbSubQueryUtil;
28  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29  
30  public class PayStepDaoOjbImpl extends PlatformAwareDaoBaseOjb implements
31  		PayStepDao {
32  
33  	
34  	@Override
35  	public PayStepBo getPayStepById(String payStepId) {
36  		Criteria crit = new Criteria();
37          crit.addEqualTo("pmPayStepId", payStepId);
38  
39          Query query = QueryFactory.newQuery(PayStepBo.class, crit);
40          return (PayStepBo) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
41  
42  	}
43  
44  	@SuppressWarnings("unchecked")
45  	@Override
46  	public List<PayStepBo> getPaySteps(String payStep, 
47  			String salaryGroup, String payGrade, String history, String active) {
48  		List<PayStepBo> results = new ArrayList<PayStepBo>();
49  
50  		Criteria crit = new Criteria();
51  		
52  		// KPME-2695
53  		// Also, changed addEqualTo to addLike
54  		if(StringUtils.isNotBlank(payStep))
55  			crit.addLike("UPPER(payStep)", payStep.toUpperCase());
56  		if(StringUtils.isNotBlank(salaryGroup))
57  			crit.addLike("UPPER(salaryGroup)", salaryGroup.toUpperCase());
58  		if(StringUtils.isNotBlank(payGrade))
59  			crit.addLike("UPPER(payGrade)", payGrade.toUpperCase());
60  		
61  		Criteria activeFilter = new Criteria();
62  		if(StringUtils.isNotBlank(active)) {
63  			activeFilter.addEqualTo("active",active);
64  		} else {
65  			activeFilter.addNotNull("active");
66          }
67  
68  		crit.addAndCriteria(activeFilter);
69  		
70          if (StringUtils.equals(history, "N")) {
71              crit.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithoutFilter(PayStepBo.class, PayStepBo.BUSINESS_KEYS, false));
72              crit.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PayStepBo.class, PayStepBo.BUSINESS_KEYS, false));
73          }
74  		
75  		Query query = QueryFactory.newQuery(PayStepBo.class, crit);
76  		
77  		results.addAll(this.getPersistenceBrokerTemplate().getCollectionByQuery(query));
78  		
79  		return results;
80  	}
81  
82  }