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.Collection;
019    import java.util.List;
020    
021    import org.apache.ojb.broker.query.Criteria;
022    import org.apache.ojb.broker.query.QueryFactory;
023    import org.kuali.kfs.module.endow.EndowPropertyConstants;
024    import org.kuali.kfs.module.endow.businessobject.Security;
025    import org.kuali.kfs.module.endow.dataaccess.SecurityDao;
026    import org.kuali.kfs.module.endow.document.service.KEMService;
027    import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb;
028    
029    public class SecurityDaoOjb extends PlatformAwareDaoBaseOjb implements SecurityDao {
030        private KEMService kemService;
031    
032        /**
033         * @see org.kuali.kfs.module.endow.dataaccess.SecurityDao#getAllSecuritiesWithNextPayDateEqualCurrentDate()
034         */
035        public List<Security> getAllSecuritiesWithNextPayDateEqualCurrentDate() {
036            Criteria criteria = new Criteria();
037            criteria.addEqualTo(EndowPropertyConstants.SECURITY_INCOME_NEXT_PAY_DATE, kemService.getCurrentDate());
038            return (List<Security>) getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(Security.class, criteria));
039        }
040    
041        /**
042         * @see org.kuali.kfs.module.endow.dataaccess.SecurityDao#getAllSecuritiesWithNextPayDateEquaTolCurrentDate()
043         */
044        public List<Security> getSecuritiesWithNextPayDateEqualToCurrentDate() {
045            Criteria criteria = new Criteria();
046            criteria.addEqualTo(EndowPropertyConstants.SECURITY_INCOME_NEXT_PAY_DATE, kemService.getCurrentDate());
047            criteria.addEqualTo(EndowPropertyConstants.SECURITY_ACTIVE_INDICATOR, true);
048            return (List<Security>) getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(Security.class, criteria));
049        }
050    
051        /**
052         * @see org.kuali.kfs.module.endow.dataaccess.SecurityDao#getSecuritiesByClassCodeWithUnitsGreaterThanZero(java.lang.String[])
053         */
054        public List<Security> getSecuritiesByClassCodeWithUnitsGreaterThanZero(List<String> classCodes) {
055            Criteria criteria = new Criteria();
056            criteria.addIn(EndowPropertyConstants.SECURITY_CLASS_CODE, classCodes);
057            criteria.addGreaterThan(EndowPropertyConstants.SECURITY_UNITS_HELD, 0);
058            return (List<Security>) getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(Security.class, criteria));
059        }
060    
061        /**
062         * @see org.kuali.kfs.module.endow.dataaccess.SecurityDao#getSecuritiesBySecurityClassCode(String)
063         */
064        public Collection<Security> getSecuritiesBySecurityClassCode(String securityClassCode) {
065            Criteria criteria = new Criteria();
066            criteria.addEqualTo(EndowPropertyConstants.SECURITY_CLASS_CODE, securityClassCode);
067            return (Collection<Security>) getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(Security.class, criteria));
068            
069        }
070        
071        /**
072         * Sets the kemService.
073         * 
074         * @param kemService
075         */
076        public void setKemService(KEMService kemService) {
077            this.kemService = kemService;
078        }
079    
080    }