@Override public void sendNotification(String providerId, Object payload, Notification notification, TaskTracker tracker) throws Exception { Map<String,Object> map = (Map<String, Object>) payload; if(!map.containsKey(ttlKey) && notification.getExpire() != null){ // ttl provided to GCM is in seconds. calculate the difference from now long ttlSeconds = notification.getExpireTTLSeconds(); // max ttl for gcm is 4 weeks - https://developers.google.com/cloud-messaging/http-server-ref ttlSeconds = ttlSeconds <= 2419200 ? ttlSeconds : 2419200; map.put(ttlKey, (int)ttlSeconds);//needs to be int } if(!map.containsKey(priorityKey) && notification.getPriority() != null){ map.put(priorityKey, notification.getPriority()); } Batch batch = getBatch( map ); batch.add(providerId, tracker); }
@Test public void singlePushNotificationHighPriority() 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("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time app.put("priority", "high"); 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); assertEquals("high", notification.getPriority()); checkReceipts(notification, 1); }
@Test public void singlePushNotificationWithInvalidPriority() 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("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time app.put("priority", "not_a_priority"); 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); // if priority is invalid, it should default to normal assertEquals("normal", notification.getPriority()); checkReceipts(notification, 1); }