You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/06/13 20:54:08 UTC
[29/50] [abbrv] git commit: Fix to getContainers() in
CpRelationManager.
Fix to getContainers() in CpRelationManager.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/8e999504
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/8e999504
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/8e999504
Branch: refs/heads/two-dot-o
Commit: 8e999504f052554f0a84f21a256b695ea5f91206
Parents: 10f6e00
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Jun 12 10:46:05 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Jun 12 10:46:05 2014 -0400
----------------------------------------------------------------------
.../corepersistence/CpRelationManager.java | 103 +++++++++++--------
.../persistence/EntityConnectionsIT.java | 22 +++-
2 files changed, 78 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8e999504/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 e1594ac..f9dcd43 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
@@ -311,7 +311,9 @@ public class CpRelationManager implements RelationManager {
@Override
public Map<String, Map<UUID, Set<String>>> getOwners() throws Exception {
- Map<EntityRef, Set<String>> containerEntities = getContainingCollections();
+ // TODO: do we need to restrict this to edges prefixed with owns?
+ //Map<EntityRef, Set<String>> containerEntities = getContainers(-1, "owns", null);
+ Map<EntityRef, Set<String>> containerEntities = getContainers();
Map<String, Map<UUID, Set<String>>> owners =
new LinkedHashMap<String, Map<UUID, Set<String>>>();
@@ -327,44 +329,49 @@ public class CpRelationManager implements RelationManager {
}
- private Map<EntityRef, Set<String>> getContainingCollections() {
- return getContainingCollections( -1, null );
+ private Map<EntityRef, Set<String>> getContainers() {
+ return getContainers( -1, null, null );
}
- private Map<EntityRef, Set<String>> getContainingCollections( int limit, String containingEntityType ) {
+ /**
+ * Gets containing collections and/or connections depending on the edge type you pass in
+ * @param limit Max number to return
+ * @param edgeType Edge type, edge type prefix or null to allow any edge type
+ * @param fromEntityType Only consider edges from entities of this type
+ */
+ private Map<EntityRef, Set<String>> getContainers( int limit, String edgeType, String fromEntityType ) {
Map<EntityRef, Set<String>> results = new LinkedHashMap<EntityRef, Set<String>>();
GraphManager gm = managerCache.getGraphManager(applicationScope);
Iterator<String> edgeTypes = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType(
- cpHeadEntity.getId(), null, null) ).toBlockingObservable().getIterator();
+ cpHeadEntity.getId(), edgeType, null) ).toBlockingObservable().getIterator();
- logger.debug("getContainingCollections(): Searching for edges to target {}:{} found: {}",
+ logger.debug("getContainers(): "
+ + "Searched for edges of type {}\n to target {}:{}\n in scope {}\n found: {}",
new Object[] {
+ edgeType,
cpHeadEntity.getId().getType(),
cpHeadEntity.getId().getUuid(),
+ applicationScope.getApplication(),
edgeTypes.hasNext()
});
while ( edgeTypes.hasNext() ) {
- String edgeType = edgeTypes.next();
+ String etype = edgeTypes.next();
Observable<Edge> edges = gm.loadEdgesToTarget( new SimpleSearchByEdgeType(
- cpHeadEntity.getId(), edgeType, Long.MAX_VALUE, null ));
+ cpHeadEntity.getId(), etype, Long.MAX_VALUE, null ));
Iterator<Edge> iter = edges.toBlockingObservable().getIterator();
while ( iter.hasNext() ) {
Edge edge = iter.next();
- if ( !isConnectionEdgeType( edge.getType()) ) {
- continue;
- }
-
- if ( containingEntityType != null
- && !containingEntityType.equals( edge.getSourceNode().getType() )) {
+ if ( fromEntityType != null && !fromEntityType.equals( edge.getSourceNode().getType() )) {
+ logger.debug("Ignoring edge from entity type {}", edge.getSourceNode().getType());
continue;
}
@@ -383,15 +390,16 @@ public class CpRelationManager implements RelationManager {
}
}
- if ( containingEntityType == null ) {
-
- EntityRef applicationRef = new SimpleEntityRef( TYPE_APPLICATION, applicationId );
- if ( !results.containsKey( applicationRef ) ) {
-
- addMapSet( results, applicationRef,
- CpEntityManager.getCollectionScopeNameFromEntityType( headEntity.getType() ) );
- }
- }
+ // should not need to do this
+// if ( connType == null ) {
+//
+// EntityRef applicationRef = new SimpleEntityRef( TYPE_APPLICATION, applicationId );
+// if ( !results.containsKey( applicationRef ) ) {
+//
+// addMapSet( results, applicationRef,
+// CpEntityManager.getCollectionScopeNameFromEntityType( headEntity.getType() ) );
+// }
+// }
return results;
}
@@ -541,7 +549,8 @@ public class CpRelationManager implements RelationManager {
return null;
}
- return addToCollection( collName, itemRef, collection.getLinkedCollection() != null );
+ return addToCollection( collName, itemRef,
+ (collection != null && collection.getLinkedCollection() != null) );
}
public Entity addToCollection(String collName, EntityRef itemRef, boolean connectBack ) throws Exception {
@@ -595,7 +604,7 @@ public class CpRelationManager implements RelationManager {
// create graph edge connection from head entity to member entity
Edge edge = new SimpleEdge(
cpHeadEntity.getId(),
- getEdgeTypeFromCollectionName( collName, memberEntity.getId().getType() ),
+ edgeType,
memberEntity.getId(),
memberEntity.getId().getUuid().timestamp() );
GraphManager gm = managerCache.getGraphManager(applicationScope);
@@ -633,9 +642,9 @@ public class CpRelationManager implements RelationManager {
headEntityScope.getOwner().toString(),
headEntityScope.getName()});
- if ( connectBack ) {
+ if ( connectBack && collection != null && collection.getLinkedCollection() != null ) {
getRelationManager( itemEntity )
- .addToCollection( collection.getLinkedCollection(), headEntity, false );
+ .addToCollection( collection.getLinkedCollection(), headEntity, false );
}
return itemEntity;
@@ -695,7 +704,7 @@ public class CpRelationManager implements RelationManager {
addToCollection( collName, itemEntity );
- if ( collection.getLinkedCollection() != null ) {
+ if ( collection != null && collection.getLinkedCollection() != null ) {
getRelationManager( getHeadEntity() )
.addToCollection( collection.getLinkedCollection(),itemEntity);
}
@@ -848,9 +857,9 @@ public class CpRelationManager implements RelationManager {
EntityCollectionManager targetEcm = managerCache.getEntityCollectionManager(targetScope);
if ( logger.isDebugEnabled() ) {
- logger.debug("Creating connection '{}' from source {}:{}]\n"
- + " to target {}:{}"
- + " from scope\n app {}\n owner {}\n name {}",
+ logger.debug("createConnection(): "
+ + "Indexing connection type '{}'\n from source {}:{}]\n"
+ + " to target {}:{}\n from scope\n app {}\n owner {}\n name {}",
new Object[] {
connectionType,
headEntity.getType(),
@@ -870,11 +879,16 @@ public class CpRelationManager implements RelationManager {
String edgeType = CpRelationManager
.getEdgeTypeFromConnectionType( connectionType, connectedEntityRef.getType() );
- logger.debug("createConnection(): Creating edge type {} from {}:{} to {}:{}",
- new Object[] {
- edgeType,
- headEntity.getType(), headEntity.getUuid(),
- connectedEntityRef.getType(), connectedEntityRef.getUuid() });
+ if ( logger.isDebugEnabled() ) {
+ logger.debug("createConnection(): "
+ + "Creating edge type {} \n from {}:{}\n to {}:{}\n in scope {}",
+ new Object[] {
+ edgeType,
+ headEntity.getType(), headEntity.getUuid(),
+ connectedEntityRef.getType(), connectedEntityRef.getUuid(),
+ applicationScope.getApplication()
+ });
+ }
// create graph edge connection from head entity to member entity
Edge edge = new SimpleEdge(
@@ -1213,17 +1227,22 @@ public class CpRelationManager implements RelationManager {
@Override
- public Results getConnectingEntities(String connectionType, String connectedEntityType,
- Level resultsLevel) throws Exception {
+ public Results getConnectingEntities(
+ String connType, String fromEntityType, Level resultsLevel) throws Exception {
- return getConnectingEntities( connectionType, connectedEntityType, resultsLevel, -1 );
+ return getConnectingEntities( connType, fromEntityType, resultsLevel, -1 );
}
@Override
public Results getConnectingEntities(
- String connectionType, String entityType, Level level, int count) throws Exception {
+ String connType, String fromEntityType, Level level, int count) throws Exception {
+
+ // looking for edges to the head entity
+ String edgeType =
+ CpRelationManager.getEdgeTypeFromConnectionType( connType, headEntity.getType() );
- Map<EntityRef, Set<String>> containers = getContainingCollections( count, entityType );
+ Map<EntityRef, Set<String>> containers =
+ getContainers( count, edgeType, fromEntityType );
if ( Level.REFS.equals(level ) ) {
List<EntityRef> refList = new ArrayList<EntityRef>( containers.keySet() );
@@ -1531,7 +1550,7 @@ public class CpRelationManager implements RelationManager {
getDefaultSchema().getContainersIndexingDictionary( entity.getType(), setName );
if ( containers != null ) {
- Map<EntityRef, Set<String>> containerEntities = getContainingCollections();
+ Map<EntityRef, Set<String>> containerEntities = getContainers();
for ( EntityRef containerEntity : containerEntities.keySet() ) {
if ( containerEntity.getType().equals( TYPE_APPLICATION ) && Schema
.isAssociatedEntityType( entity.getType() ) ) {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8e999504/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java
index 073185d..9c5ca8f 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java
@@ -329,10 +329,22 @@ public class EntityConnectionsIT extends AbstractCoreIT {
em.refreshIndex();
- assertEquals( 1,
- em.getConnectedEntities( fredEntity, "likes", null, Level.IDS ).connections.size() );
-
- assertEquals( 1,
- em.getConnectingEntities( wilmaEntity, "likes", "user", Level.ALL_PROPERTIES ).size() );
+// // search for "likes" edges from fred
+// assertEquals( 1,
+// em.getConnectedEntities( fredEntity, "likes", null, Level.IDS ).size());
+//
+// // search for any type of edges from fred
+// assertEquals( 1,
+// em.getConnectedEntities( fredEntity, null, null, Level.IDS ).size());
+
+ // search for "likes" edges to wilman from any type of object
+ Results res = em.getConnectingEntities( wilmaEntity, "likes", null, Level.ALL_PROPERTIES);
+ assertEquals( 1, res.size() );
+ assertEquals( "user", res.getEntity().getType() ); // fred is a user
+
+ // search for "likes" edges to wilman from user type object
+ res = em.getConnectingEntities( wilmaEntity, "likes", "user", Level.ALL_PROPERTIES);
+ assertEquals( 1, res.size() );
+ assertEquals( "user", res.getEntity().getType() );
}
}