View Javadoc

1   /**
2    * Copyright 2004-2013 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.hr.paygrade.dao;
17  
18  import java.sql.Date;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import com.google.common.collect.ImmutableList;
23  import org.apache.commons.lang.StringUtils;
24  import org.apache.ojb.broker.query.Criteria;
25  import org.apache.ojb.broker.query.Query;
26  import org.apache.ojb.broker.query.QueryFactory;
27  import org.apache.ojb.broker.query.ReportQueryByCriteria;
28  import org.kuali.hr.core.util.OjbSubQueryUtil;
29  import org.kuali.hr.paygrade.PayGrade;
30  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
31  
32  public class PayGradeDaoSpringObjImpl  extends PlatformAwareDaoBaseOjb implements PayGradeDao {
33      private static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
34              .add("payGrade")
35              .add("salGroup")
36              .build();
37  
38  	@Override
39  	public PayGrade getPayGrade(String payGrade, String salGroup, Date asOfDate) {
40  		Criteria root = new Criteria();
41  
42  		root.addEqualTo("payGrade", payGrade);
43  		root.addEqualTo("salGroup", salGroup);
44          root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PayGrade.class, new java.sql.Date(asOfDate.getTime()), EQUAL_TO_FIELDS, false));
45          root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PayGrade.class, EQUAL_TO_FIELDS, false));
46  
47  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
48  		activeFilter.addEqualTo("active", true);
49  		root.addAndCriteria(activeFilter);
50  
51  		
52  		Query query = QueryFactory.newQuery(PayGrade.class, root);
53  		
54  		PayGrade pg = (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
55  		
56  		return pg;
57  	}
58  
59  	@Override
60  	public PayGrade getPayGrade(String hrPayGradeId) {
61  		Criteria crit = new Criteria();
62  		crit.addEqualTo("hrPayGradeId", hrPayGradeId);
63  		
64  		Query query = QueryFactory.newQuery(PayGrade.class, crit);
65  		
66  		return (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
67  	}
68  	
69  	public int getPayGradeCount(String payGrade) {
70  		Criteria crit = new Criteria();
71  		crit.addEqualTo("payGrade", payGrade);
72  		Query query = QueryFactory.newQuery(PayGrade.class, crit);
73  		return this.getPersistenceBrokerTemplate().getCount(query);
74  	}
75  
76  	@Override
77      @SuppressWarnings("unchecked")
78      public List<PayGrade> getPayGrades(String payGrade, String payGradeDescr, String active, String showHistory) {
79          List<PayGrade> results = new ArrayList<PayGrade>();
80      	
81      	Criteria root = new Criteria();
82  
83          if (StringUtils.isNotBlank(payGrade)) {
84              root.addLike("payGrade", payGrade);
85          }
86          
87          if (StringUtils.isNotBlank(payGradeDescr)) {
88              root.addLike("description", payGradeDescr);
89          }
90          
91          if (StringUtils.isNotBlank(active)) {
92          	Criteria activeFilter = new Criteria();
93              if (StringUtils.equals(active, "Y")) {
94                  activeFilter.addEqualTo("active", true);
95              } else if (StringUtils.equals(active, "N")) {
96                  activeFilter.addEqualTo("active", false);
97              }
98              root.addAndCriteria(activeFilter);
99          }
100 
101         if (StringUtils.equals(showHistory, "N")) {
102             root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithoutFilter(PayGrade.class, EQUAL_TO_FIELDS, false));
103             root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PayGrade.class, EQUAL_TO_FIELDS, false));
104         }
105         
106         Query query = QueryFactory.newQuery(PayGrade.class, root);
107         results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
108 
109         return results;
110     }
111 
112 }