001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.earncodegroup.dao;
017
018 import java.sql.Date;
019
020 import com.google.common.collect.ImmutableList;
021 import org.apache.ojb.broker.query.Criteria;
022 import org.apache.ojb.broker.query.Query;
023 import org.apache.ojb.broker.query.QueryFactory;
024 import org.apache.ojb.broker.query.ReportQueryByCriteria;
025 import org.kuali.hr.core.util.OjbSubQueryUtil;
026 import org.kuali.hr.time.earncode.EarnCode;
027 import org.kuali.hr.time.earncodegroup.EarnCodeGroup;
028 import org.kuali.hr.time.earncodegroup.EarnCodeGroupDefinition;
029 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
030
031 public class EarnCodeGroupDaoServiceImpl extends PlatformAwareDaoBaseOjb implements EarnCodeGroupDaoService {
032 private static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
033 .add("earnCodeGroup")
034 .build();
035
036 @Override
037 public EarnCodeGroup getEarnCodeGroup(String earnGroup, Date asOfDate) {
038 Criteria root = new Criteria();
039
040 root.addEqualTo("earnCodeGroup", earnGroup);
041 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EarnCodeGroup.class, asOfDate, EQUAL_TO_FIELDS, false));
042 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCodeGroup.class, EQUAL_TO_FIELDS, false));
043 // root.addEqualTo("active", true);
044 //do not include the summary setup earn groups
045
046 Criteria activeFilter = new Criteria(); // Inner Join For Activity
047 activeFilter.addEqualTo("active", true);
048 root.addAndCriteria(activeFilter);
049
050 Query query = QueryFactory.newQuery(EarnCodeGroup.class, root);
051 EarnCodeGroup earnGroupObj = (EarnCodeGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
052 return earnGroupObj;
053 }
054
055 @Override
056 public EarnCodeGroup getEarnCodeGroupSummaryForEarnCode(String earnCode, Date asOfDate) {
057 Criteria root = new Criteria();
058 Criteria earnCodeJoin = new Criteria();
059
060 earnCodeJoin.addEqualToField("hrEarnCodeGroupId", Criteria.PARENT_QUERY_PREFIX + "hrEarnCodeGroupId");
061 earnCodeJoin.addEqualTo("earnCode", earnCode);
062 ReportQueryByCriteria earnCodeSubQuery = QueryFactory.newReportQuery(EarnCodeGroupDefinition.class, earnCodeJoin);
063 earnCodeSubQuery.setAttributes(new String[]{"hr_earn_code_group_id"});
064
065 root.addEqualTo("hrEarnCodeGroupId",earnCodeSubQuery);
066 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EarnCodeGroup.class, asOfDate, EQUAL_TO_FIELDS, false));
067 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCodeGroup.class, EQUAL_TO_FIELDS, false));
068 // root.addEqualTo("active", true);
069 root.addEqualTo("showSummary", true);
070
071 Criteria activeFilter = new Criteria(); // Inner Join For Activity
072 activeFilter.addEqualTo("active", true);
073 root.addAndCriteria(activeFilter);
074
075 Query query = QueryFactory.newQuery(EarnCodeGroup.class, root);
076 EarnCodeGroup earnGroupObj = (EarnCodeGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
077 return earnGroupObj;
078 }
079
080 @Override
081 public EarnCodeGroup getEarnCodeGroupForEarnCode(String earnCode, Date asOfDate) {
082 Criteria root = new Criteria();
083 Criteria earnCodeJoin = new Criteria();
084
085 earnCodeJoin.addEqualToField("hrEarnCodeGroupId", Criteria.PARENT_QUERY_PREFIX + "hrEarnCodeGroupId");
086 earnCodeJoin.addEqualTo("earnCode", earnCode);
087 ReportQueryByCriteria earnCodeSubQuery = QueryFactory.newReportQuery(EarnCodeGroupDefinition.class, earnCodeJoin);
088 earnCodeSubQuery.setAttributes(new String[]{"hr_earn_code_group_id"});
089
090 root.addEqualTo("hrEarnCodeGroupId",earnCodeSubQuery);
091 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EarnCodeGroup.class, asOfDate, EQUAL_TO_FIELDS, false));
092 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCodeGroup.class, EQUAL_TO_FIELDS, false));
093 // root.addEqualTo("active", true);
094
095 Criteria activeFilter = new Criteria(); // Inner Join For Activity
096 activeFilter.addEqualTo("active", true);
097 root.addAndCriteria(activeFilter);
098
099 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 }