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.earncodegroup.dao;
17  
18  import java.sql.Date;
19  
20  import com.google.common.collect.ImmutableList;
21  import org.apache.ojb.broker.query.Criteria;
22  import org.apache.ojb.broker.query.Query;
23  import org.apache.ojb.broker.query.QueryFactory;
24  import org.apache.ojb.broker.query.ReportQueryByCriteria;
25  import org.kuali.hr.core.util.OjbSubQueryUtil;
26  import org.kuali.hr.time.earncode.EarnCode;
27  import org.kuali.hr.time.earncodegroup.EarnCodeGroup;
28  import org.kuali.hr.time.earncodegroup.EarnCodeGroupDefinition;
29  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30  
31  public class EarnCodeGroupDaoServiceImpl extends PlatformAwareDaoBaseOjb implements EarnCodeGroupDaoService {
32      private static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
33              .add("earnCodeGroup")
34              .build();
35  
36  	@Override
37  	public EarnCodeGroup getEarnCodeGroup(String earnGroup, Date asOfDate) {
38  		Criteria root = new Criteria();
39  
40  		root.addEqualTo("earnCodeGroup", earnGroup);
41          root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EarnCodeGroup.class, asOfDate, EQUAL_TO_FIELDS, false));
42          root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCodeGroup.class, EQUAL_TO_FIELDS, false));
43  //		root.addEqualTo("active", true);
44  		//do not include the summary setup earn groups
45  
46  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
47  		activeFilter.addEqualTo("active", true);
48  		root.addAndCriteria(activeFilter);
49  				
50  		Query query = QueryFactory.newQuery(EarnCodeGroup.class, root);
51  		EarnCodeGroup earnGroupObj  = (EarnCodeGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
52  		return earnGroupObj;
53  	}
54  
55  	@Override
56  	public EarnCodeGroup getEarnCodeGroupSummaryForEarnCode(String earnCode, Date asOfDate) {
57  		Criteria root = new Criteria();
58  		Criteria earnCodeJoin = new Criteria();
59  		
60  		earnCodeJoin.addEqualToField("hrEarnCodeGroupId", Criteria.PARENT_QUERY_PREFIX + "hrEarnCodeGroupId");
61  		earnCodeJoin.addEqualTo("earnCode", earnCode);
62  		ReportQueryByCriteria earnCodeSubQuery = QueryFactory.newReportQuery(EarnCodeGroupDefinition.class, earnCodeJoin);
63  		earnCodeSubQuery.setAttributes(new String[]{"hr_earn_code_group_id"});
64  		
65  		root.addEqualTo("hrEarnCodeGroupId",earnCodeSubQuery);
66          root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EarnCodeGroup.class, asOfDate, EQUAL_TO_FIELDS, false));
67          root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCodeGroup.class, EQUAL_TO_FIELDS, false));
68  //		root.addEqualTo("active", true);
69  		root.addEqualTo("showSummary", true);
70  		
71  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
72  		activeFilter.addEqualTo("active", true);
73  		root.addAndCriteria(activeFilter);
74  
75  		Query query = QueryFactory.newQuery(EarnCodeGroup.class, root);
76  		EarnCodeGroup earnGroupObj  = (EarnCodeGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
77  		return earnGroupObj;
78  	}
79  
80  	@Override
81  	public EarnCodeGroup getEarnCodeGroupForEarnCode(String earnCode, Date asOfDate) {
82  		Criteria root = new Criteria();
83  		Criteria earnCodeJoin = new Criteria();
84  
85  		earnCodeJoin.addEqualToField("hrEarnCodeGroupId", Criteria.PARENT_QUERY_PREFIX + "hrEarnCodeGroupId");
86  		earnCodeJoin.addEqualTo("earnCode", earnCode);
87  		ReportQueryByCriteria earnCodeSubQuery = QueryFactory.newReportQuery(EarnCodeGroupDefinition.class, earnCodeJoin);
88  		earnCodeSubQuery.setAttributes(new String[]{"hr_earn_code_group_id"});
89  		
90  		root.addEqualTo("hrEarnCodeGroupId",earnCodeSubQuery);
91          root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EarnCodeGroup.class, asOfDate, EQUAL_TO_FIELDS, false));
92          root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCodeGroup.class, EQUAL_TO_FIELDS, false));
93  //		root.addEqualTo("active", true);
94  
95  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
96  		activeFilter.addEqualTo("active", true);
97  		root.addAndCriteria(activeFilter);
98  		
99  		Query query = QueryFactory.newQuery(EarnCodeGroup.class, root);
100 		EarnCodeGroup earnGroupObj  = (EarnCodeGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
101 		return earnGroupObj;
102 	}
103 
104 	@Override
105 	public EarnCodeGroup getEarnCodeGroup(String hrEarnCodeGroupId) {
106 		Criteria crit = new Criteria();
107 		crit.addEqualTo("hrEarnCodeGroupId", hrEarnCodeGroupId);
108 		
109 		Query query = QueryFactory.newQuery(EarnCodeGroup.class, crit);
110 		return (EarnCodeGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
111 	}
112 	
113 	@Override
114 	public int getEarnCodeGroupCount(String earnCodeGroup) {
115 		Criteria crit = new Criteria();
116 	    crit.addEqualTo("earnCodeGroup", earnCodeGroup);
117 	    Query query = QueryFactory.newQuery(EarnCodeGroup.class, crit);
118 	    return this.getPersistenceBrokerTemplate().getCount(query);
119 	}
120 	@Override
121 	public int getNewerEarnCodeGroupCount(String earnCodeGroup, Date effdt) {
122 		Criteria crit = new Criteria();
123 		crit.addEqualTo("earnCodeGroup", earnCodeGroup);
124 		crit.addEqualTo("active", "Y");
125 		crit.addGreaterThan("effectiveDate", effdt);
126 		Query query = QueryFactory.newQuery(EarnCodeGroup.class, crit);
127        	return this.getPersistenceBrokerTemplate().getCount(query);
128 	}
129 }