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