usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject usergrid git commit: USERGRID-1124
Date Wed, 17 Feb 2016 21:04:44 GMT
Repository: usergrid
Updated Branches:
  refs/heads/master 91d2a9123 -> d4c7a3ca8


USERGRID-1124


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

Branch: refs/heads/master
Commit: d4c7a3ca861752cb953076dc27b8cb46baf2c8f2
Parents: 91d2a91
Author: Michael Russo <michaelarusso@gmail.com>
Authored: Wed Feb 17 13:04:21 2016 -0800
Committer: Michael Russo <michaelarusso@gmail.com>
Committed: Wed Feb 17 13:04:21 2016 -0800

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 27 +++++++++++++++
 .../usergrid/persistence/EntityManager.java     |  2 ++
 .../services/AbstractCollectionService.java     | 36 +++-----------------
 .../usergrid/services/CollectionServiceIT.java  | 16 +++++++++
 4 files changed, 49 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/d4c7a3ca/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index a7cb8f4..6c2ef0b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -825,6 +825,33 @@ public class CpEntityManager implements EntityManager {
         return convertMvccEntityToEntity( fieldSet.getEntity( uniqueLookupRepairField ).getEntity().get()
);
     }
 
+    @Override
+    public UUID getUniqueIdFromAlias( String collectionType, String aliasType ){
+
+        String collName = Schema.defaultCollectionName( collectionType );
+        String propertyName = Schema.getDefaultSchema().aliasProperty( collName );
+        StringField uniqueLookupRepairField =  new StringField( propertyName, aliasType);
+
+        Observable<FieldSet> fieldSetObservable = ecm.getEntitiesFromFields(
+            Inflector.getInstance().singularize( collectionType ), Collections.singletonList(uniqueLookupRepairField));
+
+        if(fieldSetObservable == null){
+
+            if (logger.isDebugEnabled()) {
+                logger.debug("Couldn't return the observable based on unique entities.");
+            }
+
+            return null;
+        }
+
+        FieldSet fieldSet = fieldSetObservable.toBlocking().last();
+        if(fieldSet.isEmpty()) {
+            return null;
+        }
+
+        return fieldSet.getEntity( uniqueLookupRepairField ).getEntity().get().getId().getUuid();
+    }
+
 
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/d4c7a3ca/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 7725202..1a844f6 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -704,6 +704,8 @@ public interface EntityManager {
 
     public Entity getUniqueEntityFromAlias( String aliasType, String aliasValue );
 
+    public UUID getUniqueIdFromAlias( String aliasType, String aliasValue );
+
 
     /**
      * Get the outgoing edge types where the entity ref is the source in the graph

http://git-wip-us.apache.org/repos/asf/usergrid/blob/d4c7a3ca/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
index fbb4cc6..0ad751a 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
@@ -144,14 +144,10 @@ public class AbstractCollectionService extends AbstractService {
     @Override
     public ServiceResults getItemByName( ServiceContext context, String name ) throws Exception
{
 
-        String nameProperty = Schema.getDefaultSchema().aliasProperty( getEntityType() );
-        if ( nameProperty == null ) {
-            nameProperty = "name";
-        }
-
-        Entity entity = em.getUniqueEntityFromAlias( getEntityType(), name );
+        // just get the UUID and then getItemById such that same results are being returned
in both cases
+        UUID entityId = em.getUniqueIdFromAlias( getEntityType(), name );
 
-        if ( entity == null ) {
+        if ( entityId == null ) {
 
             if (logger.isTraceEnabled()) {
                 logger.trace("miss on entityType: {} with name: {}", getEntityType(), name);
@@ -159,35 +155,11 @@ public class AbstractCollectionService extends AbstractService {
 
             String msg = "Cannot find entity with name: "+name;
             throw new EntityNotFoundException( msg );
-        }
-
-        // the context of the entity they're trying to load isn't owned by the owner
-        // in the path, don't return it
-        if ( !em.isCollectionMember( context.getOwner(), context.getCollectionName(), entity
) ) {
-            logger.info( "Someone tried to GET entity {} they don't own. Entity name {} with
owner {}",
-                    getEntityType(), name, context.getOwner()
-            );
-            throw new ServiceResourceNotFoundException( context );
-        }
 
-        if ( !context.moreParameters() ) {
-            entity = importEntity( context, entity );
         }
 
-        checkPermissionsForEntity( context, entity );
-
-    /*
-     * Level level = Level.REFS; if (isEmpty(parameters)) {
-     * level = Level.ALL_PROPERTIES; }
-     *
-     * Results results = em.searchCollectionForProperty(owner,
-     * getCollectionName(), null, nameProperty, name, null, null, 1, level);
-     * EntityRef entity = results.getRef();
-     */
-
-        List<ServiceRequest> nextRequests = context.getNextServiceRequests( entity
);
+        return getItemById( context, entityId, false);
 
-        return new ServiceResults( this, context, Type.COLLECTION, Results.fromRef( entity
), null, nextRequests );
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/d4c7a3ca/stack/services/src/test/java/org/apache/usergrid/services/CollectionServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/CollectionServiceIT.java
b/stack/services/src/test/java/org/apache/usergrid/services/CollectionServiceIT.java
index b9f7105..c071d1f 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/CollectionServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/CollectionServiceIT.java
@@ -144,6 +144,22 @@ public class CollectionServiceIT extends AbstractServiceIT {
         }
     }
 
+    @Test
+    public void testSizeReturnedInMetadata() throws Exception {
+
+        app.put( "name", "Tom" );
+        Entity cat = app.testRequest( ServiceAction.POST, 1, "cats" ).getEntity();
+        assertNotNull( cat );
+
+        Entity getEntityByName = app.testRequest( ServiceAction.GET, 1, "cats", cat.getName()
).getEntity();
+        Entity getEntityByUUID = app.testRequest( ServiceAction.GET, 1, "cats", cat.getUuid()
).getEntity();
+
+        assertNotNull(getEntityByName.getSize());
+        assertNotNull(getEntityByUUID.getSize());
+
+        app.clear();
+
+    }
 
     @Test
     public void testGenericEntityCollectionWithIdName() throws Exception {


Mime
View raw message