001    /*
002     * Copyright 2011 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.kfs.module.endow.dataaccess.impl;
017    
018    import java.util.ArrayList;
019    import java.util.Collection;
020    import java.util.List;
021    
022    import org.apache.ojb.broker.query.Criteria;
023    import org.apache.ojb.broker.query.QueryByCriteria;
024    import org.apache.ojb.broker.query.QueryFactory;
025    import org.kuali.kfs.module.endow.EndowPropertyConstants;
026    import org.kuali.kfs.module.endow.businessobject.KemidHistoricalCash;
027    import org.kuali.kfs.module.endow.dataaccess.KemidHistoricalCashDao;
028    import org.kuali.kfs.sys.KFSConstants;
029    import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb;
030    import org.kuali.rice.kns.util.KualiInteger;
031    
032    public class KemidHistoricalCashDaoOjb extends PlatformAwareDaoBaseOjb implements KemidHistoricalCashDao {
033        
034        /**
035         * 
036         * @see org.kuali.kfs.module.endow.dataaccess.KemidHistoricalCashDao#getHistoricalCashRecords(java.util.List, org.kuali.rice.kns.util.KualiInteger)
037         */
038        public List<KemidHistoricalCash> getHistoricalCashRecords(List<String> kemids, KualiInteger medId) {
039            Criteria criteria = new Criteria();
040            criteria.addIn(EndowPropertyConstants.ENDOWMENT_HIST_CASH_KEMID, kemids);
041            criteria.addEqualTo(EndowPropertyConstants.ENDOWMENT_HIST_CASH_MED_ID, medId);
042            QueryByCriteria qbc = QueryFactory.newQuery(KemidHistoricalCash.class, criteria);
043            qbc.addOrderByAscending(EndowPropertyConstants.ENDOWMENT_HIST_CASH_KEMID);
044            
045            return (List<KemidHistoricalCash>) getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
046        }
047    
048        /**
049         * @see org.kuali.kfs.module.endow.dataaccess.KemidHistoricalCashDao#getHistoricalCashRecords(java.util.List, org.kuali.rice.kns.util.KualiInteger, org.kuali.rice.kns.util.KualiInteger)
050         */
051        public List<KemidHistoricalCash> getHistoricalCashRecords(List<String> kemids, KualiInteger beginningMed, KualiInteger endingMed) {
052            Criteria criteria = new Criteria();
053            Collection<KualiInteger> monthEndIds = new ArrayList<KualiInteger>();
054            
055            monthEndIds.add(beginningMed);
056            monthEndIds.add(endingMed);
057            
058            if (kemids != null) {
059                for (String kemid : kemids) {
060                    Criteria c = new Criteria();
061                    if (kemid.contains(KFSConstants.WILDCARD_CHARACTER)) {
062                        c.addLike(EndowPropertyConstants.KEMID, kemid.trim().replace(KFSConstants.WILDCARD_CHARACTER, KFSConstants.PERCENTAGE_SIGN));
063                    } else {
064                        c.addEqualTo(EndowPropertyConstants.KEMID, kemid.trim());
065                    }
066                    criteria.addOrCriteria(c);
067                }
068            }
069            
070            criteria.addIn(EndowPropertyConstants.ENDOWMENT_HIST_CASH_MED_ID, monthEndIds);
071            QueryByCriteria qbc = QueryFactory.newQuery(KemidHistoricalCash.class, criteria);
072            qbc.addOrderByAscending(EndowPropertyConstants.ENDOWMENT_HIST_CASH_KEMID);
073            
074            return (List<KemidHistoricalCash>) getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
075        }
076        
077        /**
078         * 
079         * @see org.kuali.kfs.module.endow.dataaccess.KemidHistoricalCashDao#getKemidsFromHistoryCash(org.kuali.rice.kns.util.KualiInteger, org.kuali.rice.kns.util.KualiInteger)
080         */
081        public List<KemidHistoricalCash> getKemidsFromHistoryCash(KualiInteger beginningMed, KualiInteger endingMed) {
082            return getKemidsFromHistoryCash("", beginningMed, endingMed);
083        }
084       
085        /**
086         * 
087         * @see org.kuali.kfs.module.endow.dataaccess.KemidHistoricalCashDao#getKemidsFromHistoryCash(java.lang.String, org.kuali.rice.kns.util.KualiInteger, org.kuali.rice.kns.util.KualiInteger)
088         */
089        public List<KemidHistoricalCash> getKemidsFromHistoryCash(String kemid, KualiInteger beginningMed, KualiInteger endingMed) {
090            Criteria criteria = new Criteria();
091            if (kemid != null && !kemid.isEmpty()) {
092                criteria.addGreaterOrEqualThanField(EndowPropertyConstants.KEMID, kemid);
093            }
094            criteria.addGreaterOrEqualThanField(EndowPropertyConstants.ENDOWMENT_HIST_CASH_MED_ID, beginningMed);
095            criteria.addLessOrEqualThan(EndowPropertyConstants.ENDOWMENT_HIST_CASH_MED_ID, endingMed);
096            QueryByCriteria qbc = QueryFactory.newQuery(KemidHistoricalCash.class, criteria);
097            qbc.addOrderByAscending(EndowPropertyConstants.ENDOWMENT_HIST_CASH_KEMID);        
098            return (List<KemidHistoricalCash>) getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
099        }
100    }