1
2
3
4
5
6
7
8
9
10
11
12
13
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
33
34
35
36
37 public class PurgePushNotificationDaoImpl implements PurgePushNotificationDao {
38
39
40 private static final Logger LOG = Logger.getLogger(PurgePushNotificationDaoImpl.class);
41
42
43 @PersistenceContext
44 private EntityManager entityManager;
45
46 @Autowired
47 private PushDeviceTupleService pdtService;
48
49
50
51
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
78
79
80 public EntityManager getEntityManager() {
81 return entityManager;
82 }
83
84
85
86
87
88 public void setEntityManager(EntityManager entityManager) {
89 this.entityManager = entityManager;
90 }
91
92 }