usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject usergrid git commit: Allow notification entities to be deleted if they are not currently in progress.
Date Fri, 18 Dec 2015 02:00:40 GMT
Repository: usergrid
Updated Branches:
  refs/heads/master f7a82ba81 -> db26ba723


Allow notification entities to be deleted if they are not currently in progress.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/db26ba72
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/db26ba72
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/db26ba72

Branch: refs/heads/master
Commit: db26ba723dbdc91ffb5a6fade1339032e31de9b3
Parents: f7a82ba
Author: Michael Russo <michaelarusso@gmail.com>
Authored: Thu Dec 17 18:00:36 2015 -0800
Committer: Michael Russo <michaelarusso@gmail.com>
Committed: Thu Dec 17 18:00:36 2015 -0800

----------------------------------------------------------------------
 .../notifications/NotificationsService.java     |  4 +-
 .../apns/NotificationsServiceIT.java            | 50 ++++++++++++++++++++
 2 files changed, 53 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/db26ba72/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
index 2a72a01..202971d 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
@@ -231,7 +231,9 @@ public class NotificationsService extends AbstractCollectionService {
     @Override
     protected boolean isDeleteAllowed(ServiceContext context, Entity entity) {
         Notification notification = (Notification) entity;
-        return (notification.getStarted() == null);
+        Notification.State state = notification.getState();
+        return !(state.equals(Notification.State.CREATED) || state.equals(Notification.State.STARTED)
||
+            state.equals(Notification.State.SCHEDULED));
     }
 
     // validate payloads

http://git-wip-us.apache.org/repos/asf/usergrid/blob/db26ba72/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
index 60b02a6..daf73d6 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -22,6 +22,7 @@ import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.persistence.entities.*;
 import org.apache.usergrid.persistence.Query;
 import org.apache.usergrid.persistence.queue.LocalQueueManager;
+import org.apache.usergrid.services.exceptions.ForbiddenServiceOperationException;
 import org.apache.usergrid.services.notifications.*;
 import org.junit.*;
 import org.slf4j.Logger;
@@ -816,6 +817,55 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT
{
 //        checkStatistics(notification, NUM_DEVICES, 0);
     }
 
+    @Test
+    public void testDeleteNotification() throws Exception {
+
+        // create push notification //
+        setup.getEntityIndex().refresh(app.getId());
+        app.clear();
+
+        String payload = getPayload();
+
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getName().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+        app.put("debug", true);
+        app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current
time
+
+        Entity sentNotification = app.testRequest(ServiceAction.POST, 1, "notifications")
+            .getEntity();
+
+        Entity fetchedNotification = app.testRequest(ServiceAction.GET, 1, "notifications",
+            sentNotification.getUuid()).getEntity();
+
+
+        // can't delete before it's finished
+        try {
+            app.testRequest(ServiceAction.DELETE, 1, "notifications", fetchedNotification.getUuid());
+        } catch (Exception e) {
+            assertEquals(e.getClass(), ForbiddenServiceOperationException.class);
+        }
+
+
+        Notification notification = app.getEntityManager().get(fetchedNotification.getUuid(),
+            Notification.class);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        setup.getEntityIndex().refresh(app.getId());
+
+        try {
+            notification = app.getEntityManager().get(notification.getUuid(), Notification.class);
+            assertEquals(Notification.State.FINISHED, notification.getState());
+
+            //try to delete again after it is in the FINISHED STATE
+            app.testRequest(ServiceAction.DELETE, 1, "notifications", notification.getUuid());
+        } catch (Exception e) {
+            fail("Delete should be successful after notification has finished.");
+        }
+    }
+
     private String getPayload(){
         ApnsPayloadBuilder builder = new ApnsPayloadBuilder();
         builder.setAlertBody("Hello, World!");


Mime
View raw message