usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject [2/5] usergrid git commit: Added test for google and apple to make sure that the receipts flag is honored. Allow people to input strings and boolean values to the receipts flag in order to save receipts. Added receipts flag to notifications.
Date Thu, 14 Apr 2016 23:01:20 GMT
Added test for google and apple to make sure that the receipts flag is honored.
Allow people to input strings and boolean values to the receipts flag in order to save receipts.
Added receipts flag to notifications.


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

Branch: refs/heads/release-2.1.1
Commit: 491aa084f0c633f318dbe67cc566a6be81491b2e
Parents: 2e576f3
Author: George Reyes <grey@apache.org>
Authored: Thu Apr 14 14:43:05 2016 -0700
Committer: George Reyes <grey@apache.org>
Committed: Thu Apr 14 14:43:05 2016 -0700

----------------------------------------------------------------------
 .../services/notifications/TaskManager.java     | 18 ++++++------
 .../impl/ApplicationQueueManagerImpl.java       | 30 ++++++++++++++++++--
 .../apns/NotificationsServiceIT.java            | 26 +++++++++++++++++
 .../gcm/NotificationsServiceIT.java             | 27 +++++++++++++++++-
 4 files changed, 90 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/491aa084/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
index 954724f..ce2b82c 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
@@ -104,14 +104,16 @@ public class TaskManager {
             }
 
             failures.incrementAndGet();
-            if (receipt.getUuid() != null) {
-                successes.decrementAndGet();
-            }
-            receipt.setErrorCode(code);
-            receipt.setErrorMessage(message);
-            this.saveReceipt(notification, new SimpleEntityRef(Device.ENTITY_TYPE, deviceUUID),
receipt,true);
-            if (logger.isDebugEnabled()) {
-                logger.debug("notification {} receipt saved for device {}", notification.getUuid(),
deviceUUID);
+            if(receipt!=null) {
+                if ( receipt.getUuid() != null ) {
+                    successes.decrementAndGet();
+                }
+                receipt.setErrorCode( code );
+                receipt.setErrorMessage( message );
+                this.saveReceipt( notification, new SimpleEntityRef( Device.ENTITY_TYPE,
deviceUUID ), receipt, true );
+                if ( logger.isDebugEnabled() ) {
+                    logger.debug( "notification {} receipt saved for device {}", notification.getUuid(),
deviceUUID );
+                }
             }
         } finally {
             completed(notifier, deviceUUID);

http://git-wip-us.apache.org/repos/asf/usergrid/blob/491aa084/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
b/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
index 0b0432d..8b908ee 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
@@ -329,8 +329,34 @@ public class ApplicationQueueManagerImpl implements ApplicationQueueManager
{
                     String notifierName = message.getNotifierKey().toLowerCase();
                     ProviderAdapter providerAdapter = notifierMap.get(notifierName.toLowerCase());
                     Object payload = translatedPayloads.get(notifierName);
-                    Receipt receipt = new Receipt(notification.getUuid(), message.getNotifierId(),
payload, deviceUUID);
-                    TaskTracker tracker = new TaskTracker(providerAdapter.getNotifier(),
taskManager, receipt, deviceUUID);
+                    Map dynamicNotificationProperties =notification.getDynamicProperties();
+                    //do additional error checking to make sure other values will work.
+                    Boolean receiptsField = true;
+
+                    Object typelessReceiptsField = dynamicNotificationProperties.getOrDefault(
"receipts",true );
+                    if(typelessReceiptsField instanceof Boolean) {
+                        receiptsField = ( boolean ) typelessReceiptsField;
+                    }
+                    else if(typelessReceiptsField instanceof String){
+                        String booleanString = ( String ) typelessReceiptsField;
+                        if(booleanString.toLowerCase().equals( "false" )){
+                            receiptsField=false;
+                        }
+                    }
+
+                    TaskTracker tracker = null;
+                    if(receiptsField==false){
+//                        Receipt receipt =
+//                            new Receipt( notification.getUuid(), message.getNotifierId(),
payload, deviceUUID );
+                        tracker =
+                            new TaskTracker( providerAdapter.getNotifier(), taskManager,
null, deviceUUID );
+                    }
+                    else {
+                        Receipt receipt =
+                            new Receipt( notification.getUuid(), message.getNotifierId(),
payload, deviceUUID );
+                        tracker =
+                            new TaskTracker( providerAdapter.getNotifier(), taskManager,
receipt, deviceUUID );
+                    }
                     if (!isOkToSend(notification)) {
                         tracker.failed(0, "Notification is duplicate/expired/cancelled.");
                     } else {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/491aa084/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 3923827..0ef5fe4 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
@@ -163,6 +163,32 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT
{
     }
 
     @Test
+    public void singlePushNotificationNoReceipts() throws Exception {
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+        app.put("debug", true);
+        app.put("receipts",false );
+        app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current
time
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
+        assertEquals(
+            notification.getPayloads().get(notifier.getUuid().toString()),
+            payload);
+
+        // perform push //
+        notification = notificationWaitForComplete(notification);
+        checkReceipts(notification, 0);
+    }
+
+    @Test
     public void pushWithNoValidDevicesShouldComplete() throws Exception {
 
         // create unrelated notifier

http://git-wip-us.apache.org/repos/asf/usergrid/blob/491aa084/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
index 1c7915a..13b2887 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
@@ -150,7 +150,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT
{
         payloads.put(notifier.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
-        app.put("debug", true);
+        app.put("debug", false);
         app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current
time
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity();
@@ -166,6 +166,31 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT
{
         checkReceipts(notification, 1);
     }
 
+    @Test
+    public void singlePushNotificationNoReceipts() throws Exception {
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+        app.put("debug", true);
+        app.put("receipts",false );
+        app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current
time
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
+        assertEquals(
+            notification.getPayloads().get(notifier.getUuid().toString()),
+            payload);
+
+        // perform push //
+        notification = notificationWaitForComplete(notification);
+        checkReceipts(notification, 0);
+    }
 
     @Test
     public void singlePushNotificationHighPriority() throws Exception {


Mime
View raw message