001    /*
002     * Copyright 2006-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    
017    package org.kuali.rice.ken.dao.impl;
018    
019    import org.apache.log4j.Logger;
020    import org.kuali.rice.core.framework.persistence.dao.GenericDao;
021    import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
022    import org.kuali.rice.core.util.RiceConstants;
023    import org.kuali.rice.ken.bo.NotificationMessageDelivery;
024    import org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao;
025    import org.kuali.rice.ken.util.NotificationConstants;
026    
027    import java.sql.Timestamp;
028    import java.util.Collection;
029    
030    /**
031     * This is a description of what this class does - g1zhang don't forget to fill this in. 
032     * 
033     * @author Kuali Rice Team (rice.collab@kuali.org)
034     *
035     */
036    public class NotificationMessegeDeliveryDaoJpa implements NotificationMessegeDeliveryDao{
037    
038            private static final Logger LOG = Logger.getLogger(NotificationDaoJpa.class);
039    
040            /**
041             * This overridden method ...
042             * 
043             * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getUndeliveredMessageDelivers()
044             */
045            @Override
046            public Collection getUndeliveredMessageDelivers(GenericDao businessObjectDao) {
047    
048                    //LOG.info("************************calling OJBNotificationMessegeDeliveryDao.getUndeliveredMessageDelivers************************ ");
049    
050                    Criteria criteria = new Criteria(NotificationMessageDelivery.class.getName());
051                    criteria.eq(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.UNDELIVERED);
052                    criteria.isNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE);
053                    Collection<NotificationMessageDelivery> messageDeliveries = businessObjectDao.findMatching(NotificationMessageDelivery.class, criteria, true, RiceConstants.NO_WAIT);
054    
055                    return messageDeliveries;
056            }
057    
058            /**
059             * This overridden method ...
060             * 
061             * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getMessageDeliveriesForAutoRemoval(org.kuali.rice.core.framework.persistence.dao.GenericDao)
062             */
063            @Override
064            public Collection<NotificationMessageDelivery> getMessageDeliveriesForAutoRemoval(Timestamp tm, GenericDao businessObjectDao) {
065    
066                    //LOG.info("************************calling OJBNotificationMessegeDeliveryDao.getMessageDeliveriesForAutoRemoval************************ ");
067    
068                    // get all UNDELIVERED/DELIVERED notification notification message delivery records with associated notifications that have and autoRemovalDateTime <= current
069    
070                    Criteria criteria_STATUS = new Criteria(NotificationMessageDelivery.class.getName());
071                    criteria_STATUS.eq(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.DELIVERED);
072    
073                    Criteria criteria_UNDELIVERED = new Criteria(NotificationMessageDelivery.class.getName());
074                    criteria_UNDELIVERED.eq(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.UNDELIVERED);
075    
076                    // now OR the above two together
077                    criteria_STATUS.or(criteria_UNDELIVERED);
078    
079                    Criteria fullQueryCriteria = new Criteria(NotificationMessageDelivery.class.getName());
080                    fullQueryCriteria.isNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE);
081    
082                    fullQueryCriteria.lte(NotificationConstants.BO_PROPERTY_NAMES.NOTIFICATION_AUTO_REMOVE_DATE_TIME, new Timestamp(System.currentTimeMillis()));
083    
084                    fullQueryCriteria.and(criteria_STATUS);
085    
086                    Collection<NotificationMessageDelivery> messageDeliveries = businessObjectDao.findMatching(NotificationMessageDelivery.class, fullQueryCriteria, true, RiceConstants.NO_WAIT);
087    
088                    return messageDeliveries;
089            }
090    
091            /**
092             * This overridden method ...
093             * 
094             * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getLockedDeliveries(java.lang.Class, org.kuali.rice.core.framework.persistence.dao.GenericDao)
095             */
096            @Override
097            public Collection<NotificationMessageDelivery> getLockedDeliveries(
098                            Class clazz, GenericDao dao) {
099            Criteria criteria = new Criteria(clazz.getName());
100            criteria.notNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE);
101            Collection<NotificationMessageDelivery> lockedDeliveries = dao.findMatching(clazz, criteria);
102                    return null;
103            }
104    
105    
106    }