You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/03/19 17:19:48 UTC

[22/50] incubator-usergrid git commit: [USERGRID-386] Changed over to new method em.getAllEntityFromFields. Added unsupported messages to EntityManagerImpl Changed type of getAllEntityFromFields Added new method to CpEntityManager that converts a CpEntit

[USERGRID-386] Changed over to new method em.getAllEntityFromFields.
Added unsupported messages to EntityManagerImpl
Changed type of getAllEntityFromFields
Added new method to CpEntityManager that converts a CpEntity to a regular Entity.
Then adds method to use the getAllEntities method that repairs the entity incase it was deleted.


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

Branch: refs/heads/USERGRID-405
Commit: c872b694ed7f9b77220bad81813161ac11b9890f
Parents: a60d6aa
Author: GERey <gr...@apigee.com>
Authored: Wed Mar 11 16:52:04 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Wed Mar 11 16:52:04 2015 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 49 ++++++++++++++------
 .../usergrid/persistence/EntityManager.java     |  3 +-
 .../cassandra/EntityManagerImpl.java            | 13 ++++--
 .../services/AbstractCollectionService.java     |  4 +-
 4 files changed, 46 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c872b694/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 4ed37e5..b7272f1 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
@@ -340,6 +340,17 @@ public class CpEntityManager implements EntityManager {
         return entity;
     }
 
+    public Entity convertMvccEntityToEntity( org.apache.usergrid.persistence.model.entity.Entity entity){
+        if(entity == null) {
+            return null;
+        }
+        Class clazz = Schema.getDefaultSchema().getEntityClass( entity.getId().getType() );
+
+        Entity oldFormatEntity = EntityFactory.newEntity(entity.getId().getUuid(),entity.getId().getType(),clazz);
+        oldFormatEntity.setProperties( CpEntityMapUtils.toMap( entity ) );
+
+        return oldFormatEntity;
+    }
 
     @Override
     public Entity get( EntityRef entityRef ) throws Exception {
@@ -730,17 +741,33 @@ public class CpEntityManager implements EntityManager {
     }
 
     @Override
-    public Observable<FieldSet> getAllEntityFromFields(String aliasType,String aliasValue ){
-        return null;
-//        EntityCollectionManager ecm = managerCache.getEntityCollectionManager( aliasType );
-//
-//        Schema.
-//        return ecm.getAllEntities( aliasValue );
+    public Entity getAllEntityFromFields( String collectionType, String aliasType ){
+        String collName = Schema.defaultCollectionName( collectionType );
+
+        CollectionScope collectionScope = getCollectionScopeNameFromEntityType(
+            getApplicationScope().getApplication(), collName);
+
+        String propertyName = Schema.getDefaultSchema().aliasProperty( collName );
+
+
+        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?
+
+        StringField uniqueLookupRepairField =  new StringField( propertyName, aliasType.toString());
+
+        Observable<FieldSet> fieldSetObservable = ecm.getAllEntities( Arrays.<Field>asList( uniqueLookupRepairField) );
+
+        FieldSet fieldSet = fieldSetObservable.toBlocking().last();
+
+        if(fieldSet.isEmpty()) {
+            return null;
+        }
+
+        return convertMvccEntityToEntity( fieldSet.getEntity( uniqueLookupRepairField ).getEntity().get() );
     }
 
     @Override
     public Entity getEntityByAlias(String collectionType, String aliasType) throws Exception {
-
         EntityRef newEntityRef = getAlias(collectionType,aliasType);
 
         if(newEntityRef == null) {
@@ -748,9 +775,6 @@ public class CpEntityManager implements EntityManager {
         }
 
         return get( newEntityRef );
-
-
-
     }
 
 
@@ -2157,11 +2181,6 @@ public class CpEntityManager implements EntityManager {
         //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/c872b694/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 4b85c0d..eb6379b 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
@@ -19,6 +19,7 @@ package org.apache.usergrid.persistence;
 
 import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.FieldSet;
+import org.apache.usergrid.persistence.collection.MvccEntity;
 import org.apache.usergrid.persistence.index.query.Query;
 import java.nio.ByteBuffer;
 import java.util.Collection;
@@ -719,6 +720,6 @@ public interface EntityManager {
      */
     public Health getIndexHealth();
 
-    public Observable<FieldSet> getAllEntityFromFields(String aliasType,String aliasValue );
+    public Entity getAllEntityFromFields( String aliasType, String aliasValue );
 
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c872b694/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 42a588c..a019e86 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.FieldSet;
 import org.apache.usergrid.persistence.entities.Application;
 import org.apache.usergrid.persistence.entities.Event;
 import org.apache.usergrid.persistence.entities.Group;
@@ -108,7 +107,6 @@ import me.prettyprint.hector.api.mutation.Mutator;
 import me.prettyprint.hector.api.query.MultigetSliceCounterQuery;
 import me.prettyprint.hector.api.query.QueryResult;
 import me.prettyprint.hector.api.query.SliceCounterQuery;
-import rx.Observable;
 
 import static java.lang.String.CASE_INSENSITIVE_ORDER;
 import static java.util.Arrays.asList;
@@ -538,7 +536,7 @@ public class EntityManagerImpl implements EntityManager {
     /**
      * Return all UUIDs that have this unique value
      *
-     * @param ownerEntityId The entity id that owns this entity collection
+     * @param ownerEntityRef The entity id that owns this entity collection
      * @param collectionName The entity collection name
      * @param propertyName The name of the unique property
      * @param propertyValue The value of the unique property
@@ -1775,6 +1773,12 @@ public class EntityManagerImpl implements EntityManager {
 
 
     @Override
+    public Entity getEntityByAlias( final String collectionType, final String aliasType ) throws Exception {
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+
+    @Override
     public EntityRef getAlias( String aliasType, String alias ) throws Exception {
         return getAlias( new SimpleEntityRef(Application.ENTITY_TYPE, applicationId), aliasType, alias );
     }
@@ -2952,8 +2956,7 @@ public class EntityManagerImpl implements EntityManager {
 
 
     @Override
-    public Observable<FieldSet> getAllEntityFromFields( final String aliasType,
-                                                        final String aliasValue ) {
+    public Entity getAllEntityFromFields( final String aliasType, final String aliasValue ) {
         throw new UnsupportedOperationException( "Not supported." );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c872b694/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 1117fbc..26eb6b9 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,7 +76,7 @@ public class AbstractCollectionService extends AbstractService {
             nameProperty = "name";
         }
 
-        Entity entity = em.getEntityByAlias( getEntityType(), name );
+        Entity entity = em.getAllEntityFromFields( getEntityType(), name );
         if ( entity != null ) {
             entity = importEntity( request, entity );
         }
@@ -148,7 +148,7 @@ public class AbstractCollectionService extends AbstractService {
             nameProperty = "name";
         }
 
-        EntityRef entity = em.get( getEntityType(), name );
+        EntityRef entity = em.getAlias( getEntityType(), name );
 
         if ( entity == null ) {
             logger.info( "miss on entityType: {} with name: {}", getEntityType(), name );