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.lm.balancetransfer.dao; 017 018 import java.sql.Date; 019 import java.util.ArrayList; 020 import java.util.Collection; 021 import java.util.List; 022 023 import org.apache.log4j.Logger; 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 028 import org.kuali.hr.core.util.OjbSubQueryUtil; 029 import org.kuali.hr.lm.balancetransfer.BalanceTransfer; 030 import org.kuali.hr.lm.workflow.LeaveCalendarDocumentHeader; 031 import org.kuali.hr.time.util.TkConstants; 032 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; 033 034 public class BalanceTransferDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements 035 BalanceTransferDao { 036 037 private static final Logger LOG = Logger.getLogger(BalanceTransfer.class); 038 039 @Override 040 public List<BalanceTransfer> getAllBalanceTransfersForPrincipalId( 041 String principalId) { 042 Criteria crit = new Criteria(); 043 List<BalanceTransfer> balanceTransfers = new ArrayList<BalanceTransfer>(); 044 crit.addEqualTo("principalId",principalId); 045 Query query = QueryFactory.newQuery(BalanceTransfer.class,crit); 046 047 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query); 048 049 if(c != null) 050 balanceTransfers.addAll(c); 051 052 return balanceTransfers; 053 } 054 055 @Override 056 public List<BalanceTransfer> getAllBalanceTransferForPrincipalIdAsOfDate( 057 String principalId, Date effectiveDate) { 058 List<BalanceTransfer> balanceTransfers = new ArrayList<BalanceTransfer>(); 059 Criteria crit = new Criteria(); 060 crit.addEqualTo("principalId",principalId); 061 Criteria effDate = new Criteria(); 062 effDate.addGreaterOrEqualThan("effectiveDate", effectiveDate); 063 crit.addAndCriteria(effDate); 064 Query query = QueryFactory.newQuery(BalanceTransfer.class,crit); 065 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query); 066 067 if(c != null) 068 balanceTransfers.addAll(c); 069 070 return balanceTransfers; 071 } 072 073 @Override 074 public List<BalanceTransfer> getAllBalanceTransferByEffectiveDate( 075 Date effectiveDate) { 076 List<BalanceTransfer> balanceTransfers = new ArrayList<BalanceTransfer>(); 077 Criteria effDate = new Criteria(); 078 effDate.addGreaterOrEqualThan("effectiveDate", effectiveDate); 079 Query query = QueryFactory.newQuery(BalanceTransfer.class,effDate); 080 081 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query); 082 083 if(c != null) 084 balanceTransfers.addAll(c); 085 086 return balanceTransfers; 087 } 088 089 @Override 090 public BalanceTransfer getBalanceTransferById(String balanceTransferId) { 091 Criteria crit = new Criteria(); 092 crit.addEqualTo("balanceTransferId",balanceTransferId); 093 Query query = QueryFactory.newQuery(BalanceTransfer.class,crit); 094 return (BalanceTransfer) this.getPersistenceBrokerTemplate().getObjectByQuery(query); 095 } 096 097 @Override 098 public List<BalanceTransfer> getAllBalanceTransfersMarkedPayoutForPrincipalId( 099 String principalId) { 100 Criteria crit = new Criteria(); 101 List<BalanceTransfer> balanceTransfers = new ArrayList<BalanceTransfer>(); 102 crit.addEqualTo("principalId",principalId); 103 Criteria payoutCrit = new Criteria(); 104 payoutCrit.addNotNull("earnCode"); 105 crit.addAndCriteria(payoutCrit); 106 Query query = QueryFactory.newQuery(BalanceTransfer.class,crit); 107 108 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query); 109 110 if(c != null) 111 balanceTransfers.addAll(c); 112 113 return balanceTransfers; 114 } 115 116 @Override 117 public List<BalanceTransfer> getAllBalanceTransfersForAccrualCategoryRuleByDate( 118 String accrualRuleId, Date asOfDate) { 119 Criteria crit = new Criteria(); 120 List<BalanceTransfer> balanceTransfers = new ArrayList<BalanceTransfer>(); 121 crit.addGreaterOrEqualThan("effectiveDate",asOfDate); 122 Criteria accrualCategory = new Criteria(); 123 accrualCategory.addEqualTo("accrualCategoryRule", accrualRuleId); 124 crit.addAndCriteria(accrualCategory); 125 Query query = QueryFactory.newQuery(BalanceTransfer.class,crit); 126 127 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query); 128 129 if(c != null) 130 balanceTransfers.addAll(c); 131 132 return balanceTransfers; 133 } 134 135 @Override 136 public List<BalanceTransfer> getBalanceTransfers(String viewPrincipal, Date beginPeriodDate, Date endPeriodDate) { 137 // TODO Auto-generated method stub 138 List<BalanceTransfer> balanceTransfers = new ArrayList<BalanceTransfer>(); 139 Criteria crit = new Criteria(); 140 crit.addEqualTo("principalId",viewPrincipal); 141 142 Criteria effDate = new Criteria(); 143 effDate.addGreaterOrEqualThan("effectiveDate", beginPeriodDate); 144 effDate.addLessOrEqualThan("effectiveDate", endPeriodDate); 145 146 crit.addAndCriteria(effDate); 147 148 Query query = QueryFactory.newQuery(BalanceTransfer.class,crit); 149 150 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query); 151 152 if(c != null) 153 balanceTransfers.addAll(c); 154 155 return balanceTransfers; 156 } 157 158 @Override 159 public void saveOrUpdate(BalanceTransfer balanceTransfer) { 160 this.getPersistenceBrokerTemplate().store(balanceTransfer); 161 } 162 }