usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [12/31] incubator-usergrid git commit: windows push raw notifications
Date Mon, 09 Mar 2015 15:25:25 GMT
windows push raw notifications


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

Branch: refs/heads/USERGRID-405
Commit: 44bbd6b97546aeb9e29699cabab8e6f384f79914
Parents: 1c0f4f1
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Fri Mar 6 14:16:10 2015 -0700
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Fri Mar 6 14:16:10 2015 -0700

----------------------------------------------------------------------
 .../services/notifications/wns/WNSAdapter.java  | 39 ++++++++++++++++++++
 1 file changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44bbd6b9/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
b/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
index 9030fdd..34ae63f 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
@@ -22,6 +22,7 @@ package org.apache.usergrid.services.notifications.wns;
 
 import ar.com.fernandospr.wns.WnsService;
 import ar.com.fernandospr.wns.model.WnsBadge;
+import ar.com.fernandospr.wns.model.WnsRaw;
 import ar.com.fernandospr.wns.model.WnsToast;
 import ar.com.fernandospr.wns.model.builders.WnsBadgeBuilder;
 import ar.com.fernandospr.wns.model.builders.WnsToastBuilder;
@@ -36,6 +37,7 @@ import org.apache.usergrid.services.notifications.TaskTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.*;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -87,6 +89,11 @@ public class WNSAdapter implements ProviderAdapter {
                         }
                         service.pushBadge(providerId, badge);
                         break;
+                    case "raw" :
+                        WnsRaw raw = new WnsRaw();
+                        raw.stream = toBytes( translatedNotification.getMessage() ) ;
+                        service.pushRaw(providerId, raw);
+                        break;
                     default : throw new IllegalArgumentException(translatedNotification.getType()+"
does not match a valid notification type (toast,badge).");
                 }
             }
@@ -97,6 +104,35 @@ public class WNSAdapter implements ProviderAdapter {
         }
     }
 
+    private byte[] toBytes(Object message) {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        ObjectOutput out = null;
+        try {
+            if(message instanceof Serializable) {
+                out = new ObjectOutputStream(bos);
+                out.writeObject(message);
+                byte[] yourBytes = bos.toByteArray();
+                return yourBytes;
+            }else{
+                throw new RuntimeException("message is not serializable");
+            }
+        }catch (IOException e){
+            throw new RuntimeException(e);
+        } finally {
+            try {
+                if (out != null) {
+                    out.close();
+                }
+            } catch (IOException ex) {
+                // ignore close exception
+            }
+            try {
+                bos.close();
+            } catch (IOException ex) {
+                // ignore close exception
+            }
+        }
+    }
     @Override
     public void doneSendingNotifications() throws Exception {
 
@@ -120,6 +156,9 @@ public class WNSAdapter implements ProviderAdapter {
             if (map.containsKey("badge")) {
                 translatedNotifications.add(new TranslatedNotification(map.get("badge"),
"badge"));
             }
+            if (map.containsKey("raw")) {
+                translatedNotifications.add(new TranslatedNotification(map.get("raw"), "raw"));
+            }
 
         } else {
             //{payloads:{winphone:"mymessage"}}


Mime
View raw message