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.authz.expression.GroupExpression;
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
29 /**
30 * PurgePushNotificationDaoImpl class is implementation of PurgePushNotificationDao interface and it provides a
31 * method namely purgePushNotification to purge push notification data from the database based on the status provided.
32 *
33 * @author Kuali Mobility Team (mobility.collab@kuali.org)
34 */
35 public class PurgePushNotificationDaoImpl implements PurgePushNotificationDao {
36
37 /** A reference to a logger */
38 private static final Logger LOG = Logger.getLogger(PurgePushNotificationDaoImpl.class);
39
40 /** A reference to the <code>EntityManger</code> */
41 @PersistenceContext
42 private EntityManager entityManager;
43
44 /** A reference to the <code>PushDeviceTupleService</code> */
45 @Autowired
46 private PushDeviceTupleService pdtService;
47
48
49 /**
50 * Creates a new instance of a <code>PurgePushNotificationDaoImpl</code>
51 */
52 public PurgePushNotificationDaoImpl(){}
53
54 public boolean purgePushNotification(HttpServletRequest request, int status){
55 boolean success = false;
56 User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
57
58 // Only if the user belongs to group KME-ADMINISTRATOR can the user delete pushes
59 if(new GroupExpression("KME-ADMINISTRATOR").evaluate(user)) {
60 entityManager.createNamedQuery("PushDeviceTuple.deleteForStatus").setParameter("status", status).executeUpdate();
61 success = true;
62 }
63 return success;
64 }
65
66 /**
67 * Return the <code>EntityManager</code> for this DaoImpl..
68 * @return
69 */
70 public EntityManager getEntityManager() {
71 return entityManager;
72 }
73
74 /**
75 * Set the <code>EntityMAnager</code> for this DaoImpl.
76 * @param entityManager
77 */
78 public void setEntityManager(EntityManager entityManager) {
79 this.entityManager = entityManager;
80 }
81
82 }