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.graceperiod.dao; 017 018 import java.sql.Date; 019 import java.util.ArrayList; 020 import java.util.Collections; 021 import java.util.List; 022 023 import org.apache.commons.lang.StringUtils; 024 import org.apache.ojb.broker.query.Criteria; 025 import org.apache.ojb.broker.query.Query; 026 import org.apache.ojb.broker.query.QueryFactory; 027 import org.apache.ojb.broker.query.ReportQueryByCriteria; 028 import org.kuali.hr.core.util.OjbSubQueryUtil; 029 import org.kuali.hr.time.graceperiod.rule.GracePeriodRule; 030 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; 031 032 public class GracePeriodDaoImpl extends PlatformAwareDaoBaseOjb implements GracePeriodDao { 033 public GracePeriodRule getGracePeriodRule(Date asOfDate){ 034 GracePeriodRule gracePeriodRule = null; 035 036 Criteria root = new Criteria(); 037 038 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(GracePeriodRule.class, asOfDate, Collections.EMPTY_LIST, false)); 039 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(GracePeriodRule.class, Collections.EMPTY_LIST, false)); 040 041 Criteria activeFilter = new Criteria(); // Inner Join For Activity 042 activeFilter.addEqualTo("active", true); 043 root.addAndCriteria(activeFilter); 044 045 046 Query query = QueryFactory.newQuery(GracePeriodRule.class, root); 047 Object obj = this.getPersistenceBrokerTemplate().getObjectByQuery(query); 048 049 if (obj != null) { 050 gracePeriodRule = (GracePeriodRule) obj; 051 } 052 053 return gracePeriodRule; 054 } 055 056 @Override 057 public GracePeriodRule getGracePeriodRule(String tkGracePeriodId) { 058 Criteria crit = new Criteria(); 059 crit.addEqualTo("tkGracePeriodRuleId", tkGracePeriodId); 060 061 Query query = QueryFactory.newQuery(GracePeriodRule.class, crit); 062 return (GracePeriodRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query); 063 } 064 065 @Override 066 @SuppressWarnings("unchecked") 067 public List<GracePeriodRule> getGracePeriodRules(String hourFactor, String active) { 068 List<GracePeriodRule> results = new ArrayList<GracePeriodRule>(); 069 070 Criteria root = new Criteria(); 071 072 if (StringUtils.isNotBlank(hourFactor)) { 073 root.addLike("hourFactor", hourFactor); 074 } 075 076 if (StringUtils.isNotBlank(active)) { 077 Criteria activeFilter = new Criteria(); 078 if (StringUtils.equals(active, "Y")) { 079 activeFilter.addEqualTo("active", true); 080 } else if (StringUtils.equals(active, "N")) { 081 activeFilter.addEqualTo("active", false); 082 } 083 root.addAndCriteria(activeFilter); 084 } 085 086 Query query = QueryFactory.newQuery(GracePeriodRule.class, root); 087 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query)); 088 089 return results; 090 } 091 092 }