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.time.overtime.weekly.rule.dao;
17  
18  import java.sql.Date;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.List;
22  
23  import com.google.common.collect.ImmutableList;
24  import org.apache.ojb.broker.query.Criteria;
25  import org.apache.ojb.broker.query.Query;
26  import org.apache.ojb.broker.query.QueryByCriteria;
27  import org.apache.ojb.broker.query.QueryFactory;
28  import org.apache.ojb.broker.query.ReportQueryByCriteria;
29  import org.kuali.hr.core.util.OjbSubQueryUtil;
30  import org.kuali.hr.lm.timeoff.SystemScheduledTimeOff;
31  import org.kuali.hr.time.overtime.weekly.rule.WeeklyOvertimeRule;
32  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
33  
34  public class WeeklyOvertimeRuleDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements WeeklyOvertimeRuleDao {
35  
36  	@SuppressWarnings("unchecked")
37  	@Override
38  	public List<WeeklyOvertimeRule> findWeeklyOvertimeRules(Date asOfDate) {
39  		List<WeeklyOvertimeRule> list = new ArrayList<WeeklyOvertimeRule>();
40  
41  		Criteria root = new Criteria();
42  
43          ImmutableList<String> fields = new ImmutableList.Builder<String>()
44                  .add("convertFromEarnGroup")
45                  .add("convertToEarnCode")
46                  .add("maxHoursEarnGroup")
47                  .build();
48          root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(WeeklyOvertimeRule.class, asOfDate, fields, false));
49          root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(WeeklyOvertimeRule.class, fields, false));
50  //		root.addEqualTo("active", true);
51  
52  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
53  		activeFilter.addEqualTo("active", true);
54  		root.addAndCriteria(activeFilter);
55  		
56  		QueryByCriteria query = new QueryByCriteria(WeeklyOvertimeRule.class, root);
57  		query.addOrderByAscending("step");
58  
59  		Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
60  		
61  		if (c != null) {
62  			list.addAll(c);
63  		}
64  				
65  		return list;
66  	}
67  
68  	@Override
69  	public void saveOrUpdate(WeeklyOvertimeRule weeklyOvertimeRule) {
70  		this.getPersistenceBrokerTemplate().store(weeklyOvertimeRule);
71  	}
72  
73  	@Override
74  	public void saveOrUpdate(List<WeeklyOvertimeRule> weeklyOvertimeRules) {
75  		for (WeeklyOvertimeRule wor : weeklyOvertimeRules) {
76  			saveOrUpdate(wor);
77  		}
78  	}
79  
80  	@Override
81  	public WeeklyOvertimeRule getWeeklyOvertimeRule(String tkWeeklyOvertimeRuleId) {
82  		Criteria crit = new Criteria();
83  		crit.addEqualTo("tkWeeklyOvertimeRuleId", tkWeeklyOvertimeRuleId);
84  		
85  		Query query = QueryFactory.newQuery(WeeklyOvertimeRule.class, crit);
86  		return (WeeklyOvertimeRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
87  	}
88  
89  }