View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ken.dao.impl;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.rice.core.api.criteria.QueryByCriteria;
20  import org.kuali.rice.ken.bo.NotificationMessageDelivery;
21  import org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao;
22  import org.kuali.rice.ken.util.NotificationConstants;
23  import org.kuali.rice.krad.data.DataObjectService;
24  
25  import java.sql.Timestamp;
26  import java.util.Collection;
27  
28  import static org.kuali.rice.core.api.criteria.PredicateFactory.*;
29  
30  /**
31   * This is a description of what this class does - g1zhang don't forget to fill this in.
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   *
35   */
36  public class NotificationMessegeDeliveryDaoJpa implements NotificationMessegeDeliveryDao{
37  
38      private static final Logger LOG = Logger.getLogger(NotificationMessegeDeliveryDaoJpa.class);
39  
40      /**
41       * This overridden method ...
42       *
43       * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getUndeliveredMessageDelivers()
44       */
45      @Override
46      public Collection getUndeliveredMessageDelivers(DataObjectService dataObjectService) {
47  
48          //LOG.info("************************calling OJBNotificationMessegeDeliveryDao.getUndeliveredMessageDelivers************************ ");
49  
50          QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
51          criteria.setPredicates(
52                  equal(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.UNDELIVERED),
53                  isNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE)
54          );
55  
56          return dataObjectService.findMatching(NotificationMessageDelivery.class, criteria.build()).getResults();
57      }
58  
59      /**
60       * This overridden method ...
61       *
62       * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getMessageDeliveriesForAutoRemoval(org.kuali.rice.core.framework.persistence.dao.GenericDao)
63       */
64      @Override
65      public Collection<NotificationMessageDelivery> getMessageDeliveriesForAutoRemoval(Timestamp tm, DataObjectService dataObjectService) {
66  
67          //LOG.info("************************calling OJBNotificationMessegeDeliveryDao.getMessageDeliveriesForAutoRemoval************************ ");
68  
69          // get all UNDELIVERED/DELIVERED notification notification message delivery records with associated notifications that have and autoRemovalDateTime <= current
70          QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
71          criteria.setPredicates(
72              and(
73                  or(
74                      equal(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.DELIVERED),
75                      equal(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.UNDELIVERED)
76                  ),
77                  isNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE),
78                  lessThanOrEqual(NotificationConstants.BO_PROPERTY_NAMES.NOTIFICATION_AUTO_REMOVE_DATE_TIME, new Timestamp(System.currentTimeMillis()))
79              )
80          );
81  
82          Collection<NotificationMessageDelivery> messageDeliveries = dataObjectService.findMatching(NotificationMessageDelivery.class, criteria.build()).getResults();
83  
84          return messageDeliveries;
85      }
86  
87      /**
88       * This overridden method ...
89       *
90       * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getLockedDeliveries(java.lang.Class, org.kuali.rice.core.framework.persistence.dao.GenericDao)
91       */
92      @Override
93      public Collection<NotificationMessageDelivery> getLockedDeliveries(Class clazz, DataObjectService dataObjectService) {
94          QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
95          criteria.setPredicates(isNotNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE));
96          return dataObjectService.findMatching(clazz, criteria.build()).getResults();
97      }
98  
99  
100 }