001/**
002 * Copyright 2005-2014 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.NotificationBo;
021import org.kuali.rice.ken.dao.NotificationDao;
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.and;
029import static org.kuali.rice.core.api.criteria.PredicateFactory.lessThanOrEqual;
030import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
031import static org.kuali.rice.core.api.criteria.PredicateFactory.isNull;
032
033/**
034 * This is a description of what this class does - g1zhang don't forget to fill this in. 
035 * 
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 *
038 */
039public class NotificationDaoJpa implements NotificationDao{
040
041        private static final Logger LOG = Logger.getLogger(NotificationDaoJpa.class);
042
043        /**
044         * This overridden method ...
045         * 
046         * @see NotificationDao#findMatchedNotificationsForResolution(java.sql.Timestamp, org.kuali.rice.krad.data.DataObjectService)
047         */
048        @Override
049        public Collection findMatchedNotificationsForResolution(Timestamp tm, DataObjectService dataObjectService) {
050
051                //LOG.info("************************calling JPANotificationDao.findMatchedNotificationsForResolution(************************ ");
052
053        QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
054        criteria.setPredicates(
055            and(
056                equal(NotificationConstants.BO_PROPERTY_NAMES.PROCESSING_FLAG, NotificationConstants.PROCESSING_FLAGS.UNRESOLVED),
057                lessThanOrEqual(NotificationConstants.BO_PROPERTY_NAMES.SEND_DATE_TIME, new Timestamp(System.currentTimeMillis())),
058                isNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE)
059            )
060        );
061
062        return dataObjectService.findMatching(NotificationBo.class, criteria.build()).getResults();
063        }
064
065        /**
066         * This overridden method ...
067         * 
068         * @see NotificationDao#findMatchedNotificationsForUnlock(org.kuali.rice.ken.bo.NotificationBo, org.kuali.rice.krad.data.DataObjectService)
069         */
070        @Override
071        public Collection findMatchedNotificationsForUnlock(NotificationBo not, DataObjectService dataObjectService) {
072
073                //LOG.info("************************calling JPANotificationDao.findMatchedNotificationsForForUnlock************************ ");
074
075                QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
076        criteria.setPredicates(equal(NotificationConstants.BO_PROPERTY_NAMES.ID, not.getId()));
077
078        Collection<NotificationBo> notifications = dataObjectService.findMatching(NotificationBo.class, criteria.build()).getResults();
079
080                return notifications;
081        }
082}
083