You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@usergrid.apache.org by shawnfeldman <gi...@git.apache.org> on 2015/01/22 00:37:06 UTC

[GitHub] incubator-usergrid pull request: Usergrid 323 win phone - review b...

GitHub user shawnfeldman opened a pull request:

    https://github.com/apache/incubator-usergrid/pull/153

    Usergrid 323 win phone - review but don't merge yet

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/apache/incubator-usergrid USERGRID-323-Win-phone

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-usergrid/pull/153.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #153
    
----
commit 6e01907dcd6cc7f8f1e50d0e7704361fd2dc27a1
Author: Shawn Feldman <sf...@apache.org>
Date:   2015-01-15T22:55:13Z

    add initial windows adapter

commit 74ea17e7072f45064f83eeed6142bd7b9c464681
Author: Shawn Feldman <sf...@apache.org>
Date:   2015-01-21T23:35:56Z

    Working windows phone toasts

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Usergrid 323 windows phone notifi...

Posted by tnine <gi...@git.apache.org>.
Github user tnine commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/153#discussion_r23487657
  
    --- Diff: stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java ---
    @@ -0,0 +1,162 @@
    +/*
    + *
    + *  * Licensed to the Apache Software Foundation (ASF) under one or more
    + *  *  contributor license agreements.  The ASF licenses this file to You
    + *  * under the Apache License, Version 2.0 (the "License"); you may not
    + *  * use this file except in compliance with the License.
    + *  * You may obtain a copy of the License at
    + *  *
    + *  *     http://www.apache.org/licenses/LICENSE-2.0
    + *  *
    + *  * Unless required by applicable law or agreed to in writing, software
    + *  * distributed under the License is distributed on an "AS IS" BASIS,
    + *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + *  * See the License for the specific language governing permissions and
    + *  * limitations under the License.  For additional information regarding
    + *  * copyright in this work, please see the NOTICE file in the top level
    + *  * directory of this distribution.
    + *
    + */
    +
    +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.WnsToast;
    +import ar.com.fernandospr.wns.model.builders.WnsBadgeBuilder;
    +import ar.com.fernandospr.wns.model.builders.WnsToastBuilder;
    +import com.sun.jersey.api.client.ClientHandlerException;
    +import org.apache.usergrid.persistence.EntityManager;
    +import org.apache.usergrid.persistence.entities.Notification;
    +import org.apache.usergrid.persistence.entities.Notifier;
    +import org.apache.usergrid.services.ServicePayload;
    +import org.apache.usergrid.services.notifications.ConnectionException;
    +import org.apache.usergrid.services.notifications.ProviderAdapter;
    +import org.apache.usergrid.services.notifications.TaskTracker;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.Map;
    +
    +/**
    + * Windows Notifications Service adapter to send windows notifications
    + */
    +public class WNSAdapter implements ProviderAdapter {
    +
    +    private static final Logger LOG = LoggerFactory.getLogger(WNSAdapter.class);
    +
    +    private final EntityManager entityManager;
    +    private final Notifier notifier;
    +    private final WnsService service;
    +
    +    public WNSAdapter(EntityManager entityManager, Notifier notifier) {
    +        this.entityManager = entityManager;
    +        this.notifier = notifier;
    +        this.service = new WnsService(notifier.getSid(), notifier.getApiKey(), notifier.getLogging());
    +    }
    +
    +    @Override
    +    public void testConnection() throws ConnectionException {
    +        WnsToast toast = new WnsToastBuilder().bindingTemplateToastText01("test").build();
    +        try{
    +            //this fails every time due to jax error which is ok
    +            service.pushToast("s-1-15-2-2411381248-444863693-3819932088-4077691928-1194867744-112853457-373132695",toast);
    +        }catch (ClientHandlerException e){
    +            LOG.info("Windows Phone notifier added: "+e.toString());
    +        }
    +    }
    +
    +    @Override
    +    public void sendNotification(String providerId, Object payload, Notification notification, TaskTracker tracker) throws Exception {
    +        try {
    +            List<TranslatedNotification> translatedNotifications = ( List<TranslatedNotification>) payload;
    +            for(TranslatedNotification translatedNotification : translatedNotifications) {
    +                switch (translatedNotification.getType()) {
    +                    case "toast":
    +                        WnsToast toast = new WnsToastBuilder().bindingTemplateToastText01(translatedNotification.getMessage().toString()).build();
    +                        service.pushToast(providerId, toast);
    +                        break;
    +                    case "badge":
    +                        WnsBadge badge;
    +                        if (translatedNotification.getMessage() instanceof Integer) {
    +                            badge = new WnsBadgeBuilder().value((Integer) translatedNotification.getMessage()).build();
    +                        } else {
    +                            badge = new WnsBadgeBuilder().value(translatedNotification.getMessage().toString()).build();
    +                        }
    +                        service.pushBadge(providerId, badge);
    +                        break;
    --- End diff --
    
    Same thing here, do we want to throw/log an exception for when it's not a type we handle?  That would be helpful operationally if users are having problems and can't send.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Usergrid 323 windows phone notifi...

Posted by shawnfeldman <gi...@git.apache.org>.
Github user shawnfeldman commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/153#discussion_r23487827
  
    --- Diff: stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java ---
    @@ -0,0 +1,162 @@
    +/*
    + *
    + *  * Licensed to the Apache Software Foundation (ASF) under one or more
    + *  *  contributor license agreements.  The ASF licenses this file to You
    + *  * under the Apache License, Version 2.0 (the "License"); you may not
    + *  * use this file except in compliance with the License.
    + *  * You may obtain a copy of the License at
    + *  *
    + *  *     http://www.apache.org/licenses/LICENSE-2.0
    + *  *
    + *  * Unless required by applicable law or agreed to in writing, software
    + *  * distributed under the License is distributed on an "AS IS" BASIS,
    + *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + *  * See the License for the specific language governing permissions and
    + *  * limitations under the License.  For additional information regarding
    + *  * copyright in this work, please see the NOTICE file in the top level
    + *  * directory of this distribution.
    + *
    + */
    +
    +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.WnsToast;
    +import ar.com.fernandospr.wns.model.builders.WnsBadgeBuilder;
    +import ar.com.fernandospr.wns.model.builders.WnsToastBuilder;
    +import com.sun.jersey.api.client.ClientHandlerException;
    +import org.apache.usergrid.persistence.EntityManager;
    +import org.apache.usergrid.persistence.entities.Notification;
    +import org.apache.usergrid.persistence.entities.Notifier;
    +import org.apache.usergrid.services.ServicePayload;
    +import org.apache.usergrid.services.notifications.ConnectionException;
    +import org.apache.usergrid.services.notifications.ProviderAdapter;
    +import org.apache.usergrid.services.notifications.TaskTracker;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.Map;
    +
    +/**
    + * Windows Notifications Service adapter to send windows notifications
    + */
    +public class WNSAdapter implements ProviderAdapter {
    +
    +    private static final Logger LOG = LoggerFactory.getLogger(WNSAdapter.class);
    +
    +    private final EntityManager entityManager;
    +    private final Notifier notifier;
    +    private final WnsService service;
    +
    +    public WNSAdapter(EntityManager entityManager, Notifier notifier) {
    +        this.entityManager = entityManager;
    +        this.notifier = notifier;
    +        this.service = new WnsService(notifier.getSid(), notifier.getApiKey(), notifier.getLogging());
    +    }
    +
    +    @Override
    +    public void testConnection() throws ConnectionException {
    +        WnsToast toast = new WnsToastBuilder().bindingTemplateToastText01("test").build();
    +        try{
    +            //this fails every time due to jax error which is ok
    +            service.pushToast("s-1-15-2-2411381248-444863693-3819932088-4077691928-1194867744-112853457-373132695",toast);
    +        }catch (ClientHandlerException e){
    +            LOG.info("Windows Phone notifier added: "+e.toString());
    +        }
    +    }
    +
    +    @Override
    +    public void sendNotification(String providerId, Object payload, Notification notification, TaskTracker tracker) throws Exception {
    +        try {
    +            List<TranslatedNotification> translatedNotifications = ( List<TranslatedNotification>) payload;
    +            for(TranslatedNotification translatedNotification : translatedNotifications) {
    +                switch (translatedNotification.getType()) {
    +                    case "toast":
    +                        WnsToast toast = new WnsToastBuilder().bindingTemplateToastText01(translatedNotification.getMessage().toString()).build();
    +                        service.pushToast(providerId, toast);
    +                        break;
    +                    case "badge":
    +                        WnsBadge badge;
    +                        if (translatedNotification.getMessage() instanceof Integer) {
    +                            badge = new WnsBadgeBuilder().value((Integer) translatedNotification.getMessage()).build();
    +                        } else {
    +                            badge = new WnsBadgeBuilder().value(translatedNotification.getMessage().toString()).build();
    +                        }
    +                        service.pushBadge(providerId, badge);
    +                        break;
    --- End diff --
    
    fixed


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Usergrid 323 windows phone notifi...

Posted by shawnfeldman <gi...@git.apache.org>.
Github user shawnfeldman commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/153#discussion_r23487733
  
    --- Diff: stack/services/src/main/java/org/apache/usergrid/services/notifications/ProviderAdapterFactory.java ---
    @@ -37,6 +38,7 @@ public static ProviderAdapter getProviderAdapter(Notifier notifier, EntityManage
            switch(notifier.getProvider().toLowerCase()){
                case "apple" : adapter = new APNsAdapter(entityManager,notifier); break;
                case "google" : adapter = new GCMAdapter(entityManager ,notifier); break;
    +           case "windows" : adapter = new WNSAdapter(entityManager ,notifier); break;
                case "noop" : adapter = new TestAdapter(notifier); break;
    --- End diff --
    
    fixed



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Usergrid 323 windows phone notifi...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-usergrid/pull/153


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Usergrid 323 windows phone notifi...

Posted by tnine <gi...@git.apache.org>.
Github user tnine commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/153#discussion_r23487449
  
    --- Diff: stack/services/src/main/java/org/apache/usergrid/services/notifications/ProviderAdapterFactory.java ---
    @@ -37,6 +38,7 @@ public static ProviderAdapter getProviderAdapter(Notifier notifier, EntityManage
            switch(notifier.getProvider().toLowerCase()){
                case "apple" : adapter = new APNsAdapter(entityManager,notifier); break;
                case "google" : adapter = new GCMAdapter(entityManager ,notifier); break;
    +           case "windows" : adapter = new WNSAdapter(entityManager ,notifier); break;
                case "noop" : adapter = new TestAdapter(notifier); break;
    --- End diff --
    
    Seems silly, but I think our default case should be to throw an exception if it doesn't match any of the other cases.  That way we get some explicit feedback something was entered incorrectly into the payload.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-usergrid pull request: Usergrid 323 windows phone notifi...

Posted by tnine <gi...@git.apache.org>.
Github user tnine commented on the pull request:

    https://github.com/apache/incubator-usergrid/pull/153#issuecomment-71284058
  
    Looks good.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---