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.criteria.QueryByCriteria;
020import org.kuali.rice.ken.bo.NotificationMessageDelivery;
021import org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao;
022import org.kuali.rice.ken.util.NotificationConstants;
023import org.kuali.rice.krad.data.DataObjectService;
024
025import java.sql.Timestamp;
026import java.util.Collection;
027
028import static org.kuali.rice.core.api.criteria.PredicateFactory.*;
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 */
036public class NotificationMessegeDeliveryDaoJpa implements NotificationMessegeDeliveryDao{
037
038    private static final Logger LOG = Logger.getLogger(NotificationMessegeDeliveryDaoJpa.class);
039
040    /**
041     * This overridden method ...
042     *
043     * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getUndeliveredMessageDelivers()
044     */
045    @Override
046    public Collection getUndeliveredMessageDelivers(DataObjectService dataObjectService) {
047
048        //LOG.info("************************calling OJBNotificationMessegeDeliveryDao.getUndeliveredMessageDelivers************************ ");
049
050        QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
051        criteria.setPredicates(
052                equal(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.UNDELIVERED),
053                isNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE)
054        );
055
056        return dataObjectService.findMatching(NotificationMessageDelivery.class, criteria.build()).getResults();
057    }
058
059    /**
060     * This overridden method ...
061     *
062     * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getMessageDeliveriesForAutoRemoval(org.kuali.rice.core.framework.persistence.dao.GenericDao)
063     */
064    @Override
065    public Collection<NotificationMessageDelivery> getMessageDeliveriesForAutoRemoval(Timestamp tm, DataObjectService dataObjectService) {
066
067        //LOG.info("************************calling OJBNotificationMessegeDeliveryDao.getMessageDeliveriesForAutoRemoval************************ ");
068
069        // get all UNDELIVERED/DELIVERED notification notification message delivery records with associated notifications that have and autoRemovalDateTime <= current
070        QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
071        criteria.setPredicates(
072            and(
073                or(
074                    equal(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.DELIVERED),
075                    equal(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.UNDELIVERED)
076                ),
077                isNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE),
078                lessThanOrEqual(NotificationConstants.BO_PROPERTY_NAMES.NOTIFICATION_AUTO_REMOVE_DATE_TIME, new Timestamp(System.currentTimeMillis()))
079            )
080        );
081
082        Collection<NotificationMessageDelivery> messageDeliveries = dataObjectService.findMatching(NotificationMessageDelivery.class, criteria.build()).getResults();
083
084        return messageDeliveries;
085    }
086
087    /**
088     * This overridden method ...
089     *
090     * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getLockedDeliveries(java.lang.Class, org.kuali.rice.core.framework.persistence.dao.GenericDao)
091     */
092    @Override
093    public Collection<NotificationMessageDelivery> getLockedDeliveries(Class clazz, DataObjectService dataObjectService) {
094        QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
095        criteria.setPredicates(isNotNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE));
096        return dataObjectService.findMatching(clazz, criteria.build()).getResults();
097    }
098
099
100}