Return-Path: X-Original-To: apmail-usergrid-commits-archive@minotaur.apache.org Delivered-To: apmail-usergrid-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C603E17C2E for ; Tue, 14 Oct 2014 22:44:16 +0000 (UTC) Received: (qmail 34293 invoked by uid 500); 14 Oct 2014 22:44:16 -0000 Delivered-To: apmail-usergrid-commits-archive@usergrid.apache.org Received: (qmail 34235 invoked by uid 500); 14 Oct 2014 22:44:16 -0000 Mailing-List: contact commits-help@usergrid.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@usergrid.incubator.apache.org Delivered-To: mailing list commits@usergrid.incubator.apache.org Received: (qmail 34185 invoked by uid 99); 14 Oct 2014 22:44:16 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Oct 2014 22:44:16 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5F282822C34; Tue, 14 Oct 2014 22:44:16 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sfeldman@apache.org To: commits@usergrid.apache.org Date: Tue, 14 Oct 2014 22:44:18 -0000 Message-Id: In-Reply-To: <2fc492b52a9a4a839ecd7b1d655b90ce@git.apache.org> References: <2fc492b52a9a4a839ecd7b1d655b90ce@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/5] git commit: fix device removal, remove devices 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 Authored: Tue Oct 14 16:17:37 2014 -0600 Committer: Shawn Feldman 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 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 connections = new ArrayList(); - List 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() { + @Override + public Entity call(Entity user) { + try { + Results devicesResults = em.getCollection(user,"devices",null,100,Query.Level.REFS,false); + List 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); }