usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [3/5] git commit: fix device removal, remove devices
Date Tue, 14 Oct 2014 22:44:18 GMT
fix device removal, remove 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/72fc2bda
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/72fc2bda
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/72fc2bda

Branch: refs/heads/delete-device-connections
Commit: 72fc2bda35fe689168242c21bbcf6c086c470f3f
Parents: d3cce6e
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Tue Oct 14 16:17:37 2014 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Tue Oct 14 16:17:37 2014 -0600

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      | 10 +++--
 .../services/devices/DevicesService.java        | 42 ++++++++++----------
 2 files changed, 27 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/72fc2bda/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index 49477e2..2a790ab 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -18,6 +18,7 @@ package org.apache.usergrid.corepersistence;
 
 import static me.prettyprint.hector.api.factory.HFactory.createMutator;
 
+import com.clearspring.analytics.hash.MurmurHash;
 import com.yammer.metrics.annotation.Metered;
 import java.nio.ByteBuffer;
 import java.util.AbstractMap;
@@ -306,7 +307,7 @@ public class CpRelationManager implements RelationManager {
         GraphManager gm = managerCache.getGraphManager(applicationScope);
 
         Iterator<String> edgeTypes = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType(

-            cpHeadEntity.getId(), edgeType, null) ).toBlockingObservable().getIterator();
+            cpHeadEntity.getId(), edgeType, null) ).toBlocking().getIterator();
 
         logger.debug("getContainers(): "
                 + "Searched for edges of type {}\n   to target {}:{}\n   in scope {}\n  
found: {}", 
@@ -809,8 +810,9 @@ public class CpRelationManager implements RelationManager {
         Edge collectionToItemEdge = new SimpleEdge( 
             cpHeadEntity.getId(),
              CpNamingUtils.getEdgeTypeFromCollectionName( collName),
-            memberEntity.getId(), 
-            memberEntity.getId().getUuid().timestamp() );
+            memberEntity.getId(),
+                UUIDUtils.getUUIDLong(memberEntity.getId().getUuid())
+            );
         gm.deleteEdge(collectionToItemEdge).toBlockingObservable().last();
 
         // remove edge from item to collection
@@ -819,7 +821,7 @@ public class CpRelationManager implements RelationManager {
                 CpNamingUtils
                         .getEdgeTypeFromCollectionName( Schema.defaultCollectionName( cpHeadEntity.getId().getType()
)),
             cpHeadEntity.getId(),
-            cpHeadEntity.getId().getUuid().timestamp() );
+            UUIDUtils.getUUIDLong(cpHeadEntity.getId().getUuid()));
         gm.deleteEdge(itemToCollectionEdge).toBlockingObservable().last();
 
         // special handling for roles collection of a group

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/72fc2bda/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 93e895f..d1bb3db 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
@@ -22,10 +22,7 @@ import java.util.List;
 import java.util.UUID;
 
 import org.apache.shiro.SecurityUtils;
-import org.apache.usergrid.persistence.ConnectionRef;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.persistence.entities.Device;
 import org.apache.usergrid.persistence.entities.User;
 import org.apache.usergrid.persistence.index.query.Identifier;
@@ -34,6 +31,7 @@ import org.apache.usergrid.security.shiro.utils.SubjectUtils;
 import org.apache.usergrid.services.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import rx.Observable;
 import rx.Scheduler;
 import rx.functions.Func1;
 import rx.schedulers.Schedulers;
@@ -63,27 +61,29 @@ public class DevicesService extends AbstractCollectionService {
         return super.postItemById( context, id );
     }
 
-    protected void deleteEntityConnection(EntityRef entityRef){
+    protected void deleteEntityConnection(final EntityRef entityRef){
         if(entityRef == null) {
             return;
         }
         try {
-            List<ConnectionRef> connections = new ArrayList<ConnectionRef>();
-            List<ConnectionRef> refs = em.getConnectedEntities(entityRef, "devices",
"users", Query.Level.IDS).getConnections();
-            if(refs!=null) {
-                connections.addAll(refs);
-            }
-            refs = em.getConnectingEntities(entityRef,"users","devices", Query.Level.IDS).getConnections();
-            if(refs!=null) {
-                connections.addAll(refs);
-            }
-            for(ConnectionRef connectionRef : connections) {
-                try {
-                    em.deleteConnection(connectionRef);
-                } catch (Exception e) {
-                    logger.error("Failed to delete connection " + connectionRef.toString(),
e);
-                }
-            }
+            Results entities = em.getCollection(entityRef,"users",null,100, Query.Level.REFS,false);
+            Observable.from(entities.getEntities())
+                    .map(new Func1<Entity, Entity>() {
+                        @Override
+                        public Entity call(Entity user) {
+                            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);
+                                }
+                                em.removeFromCollection(entityRef, "users",user);
+                            } catch (Exception e) {
+                                logger.error("Failed to delete connection " + user.toString(),
e);
+                            }
+                            return user;
+                        }
+                    }).toBlocking().lastOrDefault(null);
         }catch (Exception e){
             logger.error("failed to get connection",e);
         }


Mime
View raw message