usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [05/12] incubator-usergrid git commit: Shorted to just get the Entity by Alias. Corrected spelling Added test that does a get, delete, get to make sure entities are removed. Refactored entities to getEntityByAlias Added getEntityByAlias that works based of
Date Mon, 16 Mar 2015 23:35:48 GMT
Shorted to just get the Entity by Alias.
Corrected spelling
Added test that does a get,delete,get to make sure entities are removed.
Refactored entities to getEntityByAlias
Added getEntityByAlias that works based off of existing entities.


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

Branch: refs/heads/USERGRID-466
Commit: a60d6aa31f089a8b63be7b66f1aed0224837c22b
Parents: d4eb288
Author: GERey <greyes@apigee.com>
Authored: Wed Mar 11 15:36:11 2015 -0700
Committer: GERey <greyes@apigee.com>
Committed: Wed Mar 11 15:36:11 2015 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 30 ++++++++++++++++++--
 .../usergrid/persistence/EntityManager.java     |  4 ++-
 .../cassandra/EntityManagerImpl.java            |  6 ++--
 .../usergrid/persistence/EntityManagerIT.java   | 24 ++++++++++++++++
 .../UniqueValueSerializationStrategyImpl.java   |  2 +-
 .../services/AbstractCollectionService.java     | 14 ++++-----
 6 files changed, 62 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a60d6aa3/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 4b62fbe..4ed37e5 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
@@ -730,11 +730,30 @@ public class CpEntityManager implements EntityManager {
     }
 
     @Override
-    public Observable<FieldSet> getAllEntityFromFields(CollectionScope collectionScope,Collection<Field>
fields){
-        EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope
);
-        return ecm.getAllEntities( fields );
+    public Observable<FieldSet> getAllEntityFromFields(String aliasType,String aliasValue
){
+        return null;
+//        EntityCollectionManager ecm = managerCache.getEntityCollectionManager( aliasType
);
+//
+//        Schema.
+//        return ecm.getAllEntities( aliasValue );
+    }
+
+    @Override
+    public Entity getEntityByAlias(String collectionType, String aliasType) throws Exception
{
+
+        EntityRef newEntityRef = getAlias(collectionType,aliasType);
+
+        if(newEntityRef == null) {
+            return null;
+        }
+
+        return get( newEntityRef );
+
+
+
     }
 
+
     @Override
     public EntityRef getAlias( String aliasType, String alias ) throws Exception {
 
@@ -2133,11 +2152,16 @@ public class CpEntityManager implements EntityManager {
             getApplicationScope().getApplication(), collectionName);
 
         final EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope
);
+//TODO: can't we just sub in the getEntityRepair method here so for every read of a uniqueEntityField
we can verify it is correct?
 
         //convert to a string, that's what we store
         final Id results = ecm.getIdField( new StringField(
                 propertyName, propertyValue.toString() ) ).toBlocking() .lastOrDefault( null
);
 
+        Observable<FieldSet> fieldSetObservable = ecm.getAllEntities( Arrays.<Field>asList(
new StringField( propertyName, propertyValue.toString() ) );
+
+        FieldSet fieldSet = fieldSetObservable.toBlocking().last();
+        fieldSet.
         return results;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a60d6aa3/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 459032c..4b85c0d 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
@@ -98,6 +98,8 @@ public interface EntityManager {
 
     public void createApplicationCollection( String entityType ) throws Exception;
 
+    Entity getEntityByAlias( String collectionType, String aliasType ) throws Exception;
+
     public EntityRef getAlias( String aliasType, String alias ) throws Exception;
 
     /**
@@ -717,6 +719,6 @@ public interface EntityManager {
      */
     public Health getIndexHealth();
 
-    public Observable<FieldSet> getAllEntityFromFields(CollectionScope collectionScope,Collection<Field>
fields);
+    public Observable<FieldSet> getAllEntityFromFields(String aliasType,String aliasValue
);
 
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a60d6aa3/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index adf106a..42a588c 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -69,7 +69,6 @@ import org.apache.usergrid.persistence.SimpleRoleRef;
 import org.apache.usergrid.persistence.TypedEntity;
 import org.apache.usergrid.persistence.cassandra.CounterUtils.AggregateCounterSelection;
 import org.apache.usergrid.persistence.cassandra.util.TraceParticipant;
-import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.FieldSet;
 import org.apache.usergrid.persistence.entities.Application;
 import org.apache.usergrid.persistence.entities.Event;
@@ -85,7 +84,6 @@ import org.apache.usergrid.persistence.index.query.Identifier;
 import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.persistence.index.query.Query.CounterFilterPredicate;
 import org.apache.usergrid.persistence.index.query.Query.Level;
-import org.apache.usergrid.persistence.model.field.Field;
 import org.apache.usergrid.persistence.schema.CollectionInfo;
 import org.apache.usergrid.utils.ClassUtils;
 import org.apache.usergrid.utils.CompositeUtils;
@@ -2954,8 +2952,8 @@ public class EntityManagerImpl implements EntityManager {
 
 
     @Override
-    public Observable<FieldSet> getAllEntityFromFields( final CollectionScope collectionScope,
-                                                        final Collection<Field> fields
) {
+    public Observable<FieldSet> getAllEntityFromFields( final String aliasType,
+                                                        final String aliasValue ) {
         throw new UnsupportedOperationException( "Not supported." );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a60d6aa3/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
index f8c667d..cd08607 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
@@ -44,6 +44,7 @@ import org.apache.usergrid.utils.UUIDUtils;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 
@@ -578,4 +579,27 @@ public class EntityManagerIT extends AbstractCoreIT {
 
         assertNotNull( em.get( user.getUuid() ));
     }
+
+    @Test
+    public void testInvalidNameRepair() throws Exception {
+        LOG.info("EntityManagerIT.testInvalidNameReapir");
+
+        EntityManager em = app.getEntityManager();
+
+        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+        properties.put( "name", "XR-51B" );
+        properties.put( "fuel", "Nutrinox" );
+
+        Entity user = em.create( "robot", properties );
+        assertNotNull( user );
+
+        em.refreshIndex();
+
+        assertNotNull( em.get( user.getUuid() ));
+
+        em.delete( user );
+
+        assertNull( em.get( user.getUuid() ));
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a60d6aa3/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
index be95b08..cf84215 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
@@ -176,7 +176,7 @@ public class UniqueValueSerializationStrategyImpl implements UniqueValueSerializ
             throws ConnectionException {
 
         Preconditions.checkNotNull( fields, "fields are required" );
-        Preconditions.checkArgument( fields.size() > 0, "More than 1 field msut be specified"
);
+        Preconditions.checkArgument( fields.size() > 0, "More than 1 field must be specified"
);
 
 
         final List<ScopedRowKey<CollectionPrefixedKey<Field>>> keys = new
ArrayList<>( fields.size() );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a60d6aa3/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 c3be45f..1117fbc 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
@@ -76,11 +76,7 @@ public class AbstractCollectionService extends AbstractService {
             nameProperty = "name";
         }
 
-        EntityRef entityRef = em.getAlias( getEntityType(), name );
-        if ( entityRef == null ) {
-            return null;
-        }
-        Entity entity = em.get( entityRef );
+        Entity entity = em.getEntityByAlias( getEntityType(), name );
         if ( entity != null ) {
             entity = importEntity( request, entity );
         }
@@ -152,7 +148,7 @@ public class AbstractCollectionService extends AbstractService {
             nameProperty = "name";
         }
 
-        EntityRef entity = em.getAlias( getEntityType(), name );
+        EntityRef entity = em.get( getEntityType(), name );
 
         if ( entity == null ) {
             logger.info( "miss on entityType: {} with name: {}", getEntityType(), name );
@@ -178,7 +174,7 @@ public class AbstractCollectionService extends AbstractService {
     /*
      * 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();
@@ -248,9 +244,9 @@ public class AbstractCollectionService extends AbstractService {
         }
 
         logger.debug("Limiting collection to " + Query.DEFAULT_LIMIT);
-        int count = Query.DEFAULT_LIMIT; 
+        int count = Query.DEFAULT_LIMIT;
 
-        Results r = em.getCollection( context.getOwner(), context.getCollectionName(), 
+        Results r = em.getCollection( context.getOwner(), context.getCollectionName(),
             null, count, Level.ALL_PROPERTIES, isCollectionReversed( context ) );
 
         importEntities( context, r );


Mime
View raw message