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.leavepayout.dao;
017    
018    
019    import java.sql.Date;
020    import java.util.ArrayList;
021    import java.util.Collection;
022    import java.util.List;
023    
024    import org.apache.log4j.Logger;
025    import org.apache.ojb.broker.query.Criteria;
026    import org.apache.ojb.broker.query.Query;
027    import org.apache.ojb.broker.query.QueryFactory;
028    
029    import org.kuali.hr.lm.balancetransfer.BalanceTransfer;
030    import org.kuali.hr.lm.leavepayout.LeavePayout;
031    import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
032    
033    
034    public class LeavePayoutDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements
035            LeavePayoutDao {
036    
037        private static final Logger LOG = Logger.getLogger(LeavePayout.class);
038    
039        @Override
040        public List<LeavePayout> getAllLeavePayoutsForPrincipalId(
041                String principalId) {
042            Criteria crit = new Criteria();
043            List<LeavePayout> leavePayouts = new ArrayList<LeavePayout>();
044            crit.addEqualTo("principalId",principalId);
045            Query query = QueryFactory.newQuery(LeavePayout.class,crit);
046    
047            Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
048    
049            if(c != null)
050                leavePayouts.addAll(c);
051    
052            return leavePayouts;
053        }
054    
055        @Override
056        public List<LeavePayout> getAllLeavePayoutsForPrincipalIdAsOfDate(
057                String principalId, Date effectiveDate) {
058            List<LeavePayout> leavePayouts = new ArrayList<LeavePayout>();
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(LeavePayout.class,crit);
065            Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
066    
067            if(c != null)
068                leavePayouts.addAll(c);
069    
070            return leavePayouts;
071        }
072    
073        @Override
074        public List<LeavePayout> getAllLeavePayoutsByEffectiveDate(
075                Date effectiveDate) {
076            List<LeavePayout> leavePayouts = new ArrayList<LeavePayout>();
077            Criteria effDate = new Criteria();
078            effDate.addGreaterOrEqualThan("effectiveDate", effectiveDate);
079            Query query = QueryFactory.newQuery(LeavePayout.class,effDate);
080    
081            Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
082    
083            if(c != null)
084                leavePayouts.addAll(c);
085    
086            return leavePayouts;
087        }
088    
089        @Override
090        public LeavePayout getLeavePayoutById(String lmLeavePayoutId) {
091            Criteria crit = new Criteria();
092            crit.addEqualTo("lmLeavePayoutId",lmLeavePayoutId);
093            Query query = QueryFactory.newQuery(LeavePayout.class,crit);
094            return (LeavePayout) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
095        }
096    
097        @Override
098        public List<LeavePayout> getAllLeavePayoutsMarkedPayoutForPrincipalId(
099                String principalId) {
100            Criteria crit = new Criteria();
101            List<LeavePayout> leavePayouts = new ArrayList<LeavePayout>();
102            crit.addEqualTo("principalId",principalId);
103            Criteria payoutCrit = new Criteria();
104            payoutCrit.addNotNull("earnCode");
105            crit.addAndCriteria(payoutCrit);
106            Query query = QueryFactory.newQuery(LeavePayout.class,crit);
107    
108            Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
109    
110            if(c != null)
111                leavePayouts.addAll(c);
112    
113            return leavePayouts;
114        }
115    
116            @Override
117            public List<LeavePayout> getLeavePayouts(String viewPrincipal,
118                            Date beginPeriodDate, Date endPeriodDate) {
119                    // TODO Auto-generated method stub
120                    List<LeavePayout> leavePayouts = new ArrayList<LeavePayout>();
121                    Criteria crit = new Criteria();
122                    crit.addEqualTo("principalId",viewPrincipal);
123                    
124                    Criteria effDate = new Criteria();
125                    effDate.addGreaterOrEqualThan("effectiveDate", beginPeriodDate);
126                    effDate.addLessOrEqualThan("effectiveDate", endPeriodDate);
127                    
128                    crit.addAndCriteria(effDate);
129                    
130                    Query query = QueryFactory.newQuery(LeavePayout.class,crit);
131                    
132                    Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
133                    
134                    if(c != null)
135                            leavePayouts.addAll(c);
136                    
137                    return leavePayouts;
138            }
139    
140            @Override
141            public void saveOrUpdate(LeavePayout payout) {
142                    this.getPersistenceBrokerTemplate().store(payout);
143            }
144    
145    }