You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2014/10/16 17:14:09 UTC

[1/2] git commit: fix bug if you have other devices

Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o dbdba300d -> 96f48e4da


fix bug if you have other devices


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

Branch: refs/heads/two-dot-o
Commit: 5b1c06ac88b3b46a93b399bcbfae53285364c978
Parents: d52ad4c
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Oct 16 09:13:31 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Oct 16 09:13:31 2014 -0600

----------------------------------------------------------------------
 .../services/devices/DevicesService.java        | 30 +++++++++++++-------
 .../services/users/devices/DevicesService.java  |  8 +++---
 .../apns/NotificationsServiceIT.java            |  5 +++-
 3 files changed, 27 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5b1c06ac/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java b/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java
index d1bb3db..0911865 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java
@@ -61,27 +61,35 @@ public class DevicesService extends AbstractCollectionService {
         return super.postItemById( context, id );
     }
 
-    protected void deleteEntityConnection(final EntityRef entityRef){
-        if(entityRef == null) {
+    protected void deleteEntityConnection(final EntityRef deviceRef, final EntityRef owner){
+        if(deviceRef == null) {
             return;
         }
         try {
-            Results entities = em.getCollection(entityRef,"users",null,100, Query.Level.REFS,false);
+            Results entities = em.getCollection(deviceRef,"users",null,100, Query.Level.REFS,false);
             Observable.from(entities.getEntities())
-                    .map(new Func1<Entity, Entity>() {
+                    .map(new Func1<Entity, Boolean>() {
                         @Override
-                        public Entity call(Entity user) {
+                        public Boolean call(Entity user) {
+                            boolean removed = false;
                             try {
-                                Results devicesResults = em.getCollection(user,"devices",null,100,Query.Level.REFS,false);
-                                List<Entity> devices = devicesResults.getEntities();
-                                for(EntityRef device : devices){
-                                    em.removeFromCollection(user, "devices",device);
+                                if(!user.getUuid().equals(owner.getUuid())) { //skip current user
+                                    Results devicesResults = em.getCollection(user, "devices", null, 100, Query.Level.REFS, false);
+                                    List<Entity> userDevices = devicesResults.getEntities();
+                                    for (EntityRef userDevice : userDevices) {
+                                        if(userDevice.getUuid().equals(deviceRef.getUuid())) { //only remove the current device from user
+                                            em.removeFromCollection(user, "devices", userDevice);
+                                        }
+                                    }
+                                    em.removeFromCollection(deviceRef, "users", user);
+                                    removed = true;
+                                }else{
+                                    removed = false;
                                 }
-                                em.removeFromCollection(entityRef, "users",user);
                             } catch (Exception e) {
                                 logger.error("Failed to delete connection " + user.toString(), e);
                             }
-                            return user;
+                            return removed;
                         }
                     }).toBlocking().lastOrDefault(null);
         }catch (Exception e){

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5b1c06ac/stack/services/src/main/java/org/apache/usergrid/services/users/devices/DevicesService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/users/devices/DevicesService.java b/stack/services/src/main/java/org/apache/usergrid/services/users/devices/DevicesService.java
index bdcd574..4556eaa 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/users/devices/DevicesService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/users/devices/DevicesService.java
@@ -40,7 +40,7 @@ public class DevicesService extends org.apache.usergrid.services.devices.Devices
     @Override
     public ServiceResults putItemById( ServiceContext context, UUID id ) throws Exception {
         logger.debug("Registering device {}", id);
-        unregisterDeviceToUsers(id);
+        unregisterDeviceToUsers(id,context.getOwner());
         ServiceResults results = super.putItemById( context, id );
         return results;
     }
@@ -49,15 +49,15 @@ public class DevicesService extends org.apache.usergrid.services.devices.Devices
     @Override
     public ServiceResults postItemById( ServiceContext context, UUID id ) throws Exception {
         logger.info( "Attempting to connect an entity to device {}", id );
-        unregisterDeviceToUsers(id);
+        unregisterDeviceToUsers(id,context.getOwner());
         ServiceResults results = super.postItemById( context, id );
         return results;
     }
 
-    protected void unregisterDeviceToUsers(UUID deviceId){
+    protected void unregisterDeviceToUsers(UUID deviceId, EntityRef owner){
         try {
             EntityRef device = new SimpleEntityRef("device",deviceId);
-            deleteEntityConnection(device);
+            deleteEntityConnection(device,owner);
         } catch (Exception e) {
             logger.error("Failed to delete connection for " + deviceId.toString(), e);
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5b1c06ac/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 8805b93..a834400 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
@@ -751,7 +751,10 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         assertEquals(device1Users.size(),1);
         List user1Devices = app.getEm().getCollection(user1,"devices",null,100, Query.Level.REFS,false).getEntities();
         assertEquals(user1Devices.size(),2);
-
+        app.clear();
+        e = app.testRequest(ServiceAction.POST, 1, "users",user1.getUuid(),"devices",device2.getUuid()).getEntity();
+        user1Devices = app.getEm().getCollection(user1,"devices",null,100, Query.Level.REFS,false).getEntities();
+        assertEquals(user1Devices.size(),2);
         // create push notification //
 
         app.getEm().refreshIndex();


[2/2] git commit: Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o

Posted by sf...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o


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

Branch: refs/heads/two-dot-o
Commit: 96f48e4da9d91b2de2afd57c400926e0cf5414c3
Parents: 5b1c06a dbdba30
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Oct 16 09:13:50 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Oct 16 09:13:50 2014 -0600

----------------------------------------------------------------------
 .../main/java/org/apache/usergrid/corepersistence/CpSetup.java    | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------