View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.mobility.push.dao;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.mobility.push.service.PushDeviceTupleService;
20  import org.kuali.mobility.security.group.api.Group;
21  import org.kuali.mobility.security.user.api.User;
22  import org.kuali.mobility.shared.Constants;
23  import org.springframework.beans.factory.annotation.Autowired;
24  
25  import javax.persistence.EntityManager;
26  import javax.persistence.PersistenceContext;
27  import javax.servlet.http.HttpServletRequest;
28  import java.util.Iterator;
29  import java.util.List;
30  
31  /**
32   * PurgePushNotificationDaoImpl class is implementation of PurgePushNotificationDao interface and it provides a
33   * method namely purgePushNotification to purge push notification data from the database based on the status provided.
34   *
35   * @author Kuali Mobility Team (mobility.collab@kuali.org)
36   */
37  public class PurgePushNotificationDaoImpl implements  PurgePushNotificationDao {
38  
39      /** A reference to a logger */
40      private static final Logger LOG = Logger.getLogger(PurgePushNotificationDaoImpl.class);
41  
42      /** A reference to the <code>EntityManger</code> */
43      @PersistenceContext
44      private EntityManager entityManager;
45  
46      @Autowired
47      private PushDeviceTupleService pdtService;
48  
49  
50      /**
51       * Creates a new instance of a <code>PurgePushNotificationDaoImpl</code>
52       */
53      public PurgePushNotificationDaoImpl(){}
54  
55      public boolean purgePushNotification(HttpServletRequest request, int status){
56          boolean success = false;
57          String isAdmin = "no";
58          int result = 0;
59          User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
60          List<Group> groups = user.getGroups();
61          Iterator<Group> it = groups.iterator();
62          while(it.hasNext()){
63              Group group = it.next();
64              if("KME-ADMINISTRATOR".equals(group.getName())){
65                  isAdmin = "yes";
66              }
67          }
68          if("yes".equalsIgnoreCase(isAdmin)) {
69              String hql = "DELETE PushDeviceTuple t WHERE t.status = :status";
70              result = entityManager.createQuery(hql).setParameter("status", status).executeUpdate();
71              success = true;
72          }
73          return success;
74      }
75  
76      /**
77       * Return the <code>EntityManager</code> for this DaoImpl..
78       * @return
79       */
80      public EntityManager getEntityManager() {
81          return entityManager;
82      }
83  
84      /**
85       * Set the <code>EntityMAnager</code> for this DaoImpl.
86       * @param entityManager
87       */
88      public void setEntityManager(EntityManager entityManager) {
89          this.entityManager = entityManager;
90      }
91  
92  }