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