usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject incubator-usergrid git commit: changes so far
Date Wed, 01 Apr 2015 14:44:02 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-526 0c1b33b80 -> f54efe845


changes so far


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

Branch: refs/heads/USERGRID-526
Commit: f54efe8457454f8f6bdd5018ab51bb18080e3656
Parents: 0c1b33b
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Wed Apr 1 08:43:52 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Wed Apr 1 08:43:52 2015 -0600

----------------------------------------------------------------------
 .../index/impl/EntityToMapConverter.java        | 110 ++++++++-----------
 .../persistence/index/impl/EntityIndexTest.java |   2 +-
 2 files changed, 47 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f54efe84/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
index bc6455b..7fdf0aa 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
@@ -37,7 +37,7 @@ public class EntityToMapConverter {
      * @param context The context this entity appears in
      */
     public static Map convert(ApplicationScope applicationScope, final Entity entity, final
String context ) {
-        final Map entityMap = entityToMap( entity, true );
+        final Map entityMap = entityToMap( entity );
 
         //add the context for filtering later
         entityMap.put( ENTITY_CONTEXT_FIELDNAME, context );
@@ -48,7 +48,6 @@ public class EntityToMapConverter {
 
         entityMap.put( APPLICATION_ID_FIELDNAME, idString(applicationScope.getApplication())
);
 
-
         return entityMap;
     }
 
@@ -62,106 +61,89 @@ public class EntityToMapConverter {
      * bu_ - Boolean field
      * </pre>
      */
-    private static Map entityToMap( EntityObject entity, boolean rootLevel ) {
+    private static Map entityToMap( EntityObject entity) {
 
         Map<String, Object> entityMap = new HashMap<String, Object>();
 
         for ( Object f : entity.getFields().toArray() ) {
 
             Field field = ( Field ) f;
+            String fieldName = getFieldName(field);
 
-
-            if ( f instanceof ListField) {
-                putList(entityMap, field, ( List ) field.getValue(),rootLevel);
+            if ( f instanceof ListField ) {
+                processList(entityMap, fieldName, (List) field.getValue());
             }
-            else if ( f instanceof EntityObjectField) {
+            else if ( f instanceof EntityObjectField ) {
                 EntityObject eo = ( EntityObject ) field.getValue();
-                entityMap.put(EO_PREFIX + field.getName().toLowerCase(), entityToMap(eo,false)
); // recursion
+                entityMap.put(EO_PREFIX + fieldName, entityToMap(eo)); // recursion
             }
             else if ( f instanceof StringField ) {
-
                 // index in lower case because Usergrid queries are case insensitive
-                entityMap.put( ANALYZED_STRING_PREFIX + field.getName().toLowerCase(),
+                entityMap.put( ANALYZED_STRING_PREFIX + fieldName,
                         ( ( String ) field.getValue() ).toLowerCase() );
-                entityMap.put( STRING_PREFIX + field.getName().toLowerCase(),
+                entityMap.put( STRING_PREFIX + fieldName,
                         ( ( String ) field.getValue() ).toLowerCase() );
             }
-            else if ( f instanceof LocationField ) {
+            else if ( f instanceof LocationField) {
                 LocationField locField = ( LocationField ) f;
                 Map<String, Object> locMap = new HashMap<String, Object>();
 
                 // field names lat and lon trigger ElasticSearch geo location
                 locMap.put( "lat", locField.getValue().getLatitude() );
                 locMap.put( "lon", locField.getValue().getLongitude() );
-                entityMap.put( GEO_PREFIX + field.getName().toLowerCase(), locMap );
+                entityMap.put( GEO_PREFIX + fieldName, locMap );
             }
             else if( f instanceof DoubleField ){
-                entityMap.put( DOUBLE_PREFIX + field.getName().toLowerCase(), field.getValue()
);
+                entityMap.put( DOUBLE_PREFIX + fieldName, field.getValue() );
             }
-            else if( f instanceof LongField || f instanceof IntegerField){
-                entityMap.put( LONG_PREFIX + field.getName().toLowerCase(), field.getValue()
);
+            else if( f instanceof LongField || f instanceof IntegerField ){
+                entityMap.put( LONG_PREFIX + fieldName, field.getValue() );
             }
             else if ( f instanceof BooleanField ) {
-
-                entityMap.put( BOOLEAN_PREFIX + field.getName().toLowerCase(), field.getValue()
);
+                entityMap.put( BOOLEAN_PREFIX + fieldName, field.getValue() );
             }
             else if ( f instanceof UUIDField ) {
-
-                entityMap.put( STRING_PREFIX + field.getName().toLowerCase(),
+                entityMap.put( STRING_PREFIX + fieldName,
                         field.getValue().toString().toLowerCase() );
             }
             else {
-                entityMap.put( field.getName().toLowerCase(), field.getValue() );
+                entityMap.put( fieldName, field.getValue() );
             }
         }
 
         return entityMap;
     }
 
-    private static void putList(Map<String, Object> entityMap, Field field, List list,
boolean isRootLevel) {
-        if ( !list.isEmpty() ) {
-            if(isRootLevel) {
-                Object o = list.get(0);
-
-                if (o instanceof String) {
-                    entityMap.put(ANALYZED_STRING_PREFIX + field.getName().toLowerCase(),
-                        new ArrayList(processCollectionForMap(list)));
-                    return;
-                }
-                if (o instanceof Boolean) {
-                    entityMap.put(BOOLEAN_PREFIX + field.getName().toLowerCase(),
-                        new ArrayList(processCollectionForMap(list)));
-                    return;
-                }
-                if (o instanceof Long || o instanceof Integer) {
-                    entityMap.put(LONG_PREFIX + field.getName().toLowerCase(),
-                        new ArrayList(processCollectionForMap(list)));
-                    return;
-                }
-
-                if (o instanceof Double || o instanceof Float) {
-                    entityMap.put(DOUBLE_PREFIX + field.getName().toLowerCase(),
-                        new ArrayList(processCollectionForMap(list)));
-                    return;
-                }
-
-                if (o instanceof String) {
-                    entityMap.put(ANALYZED_STRING_PREFIX + field.getName().toLowerCase(),
-                        new ArrayList(processCollectionForMap(list)));
-                    return;
-                }
-
-                if (o instanceof Entity) {
-                    entityMap.put(field.getName().toLowerCase(),
-                        new ArrayList(processCollectionForMap(list)));
-                    return;
-                }
-            }
-            //else
-            entityMap.put(field.getName().toLowerCase(), new ArrayList(processCollectionForMap(list)));
+    private static String getFieldName(Field field) {
+        return field.getName().toLowerCase();
+    }
 
-        }
+    private static void processList(Map<String, Object> entityMap, String fieldName,
List list) {
+        if (!list.isEmpty()) {
+            Object o = list.get(0);
+            List processedList = new ArrayList(processCollectionForMap(list));
+            if (o instanceof String) {
+                entityMap.put(ANALYZED_STRING_PREFIX + fieldName, processedList);
+                entityMap.put(STRING_PREFIX + fieldName, processedList);
+            }
+            else if (o instanceof Boolean) {
+                entityMap.put(BOOLEAN_PREFIX + fieldName, processedList);
+            }
+            else if (o instanceof Long || o instanceof Integer) {
+                entityMap.put(LONG_PREFIX + fieldName, processedList);
+            }
+
+            else if (o instanceof Double || o instanceof Float) {
+                entityMap.put(DOUBLE_PREFIX + fieldName, processedList);
+            }
 
+            else if (o instanceof Entity) {
+                entityMap.put(fieldName, processedList);
+            }
+            else {
+                entityMap.put(fieldName, processedList);
+            }
+        }
     }
 
 
@@ -175,7 +157,7 @@ public class EntityToMapConverter {
         if ( sample instanceof Entity ) {
             for ( Object o : c.toArray() ) {
                 Entity e = ( Entity ) o;
-                processed.add( entityToMap( e,false ) );
+                processed.add( entityToMap( e ) );
             }
         }
         else if ( sample instanceof List ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f54efe84/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
index 27f0b9d..436fbb4 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
@@ -417,7 +417,7 @@ public class EntityIndexTest extends BaseIT {
         testQuery(scope,  searchTypes,entityIndex, "not (friends.name = 'Jack the Ripper')",
totalUsers );
 
         // one person has a friend named Shari Hahn
-        testQuery(scope, searchTypes, entityIndex, "friends.name = 'Wendy Moody'", 1 );
+        testQuery(scope, searchTypes, entityIndex, "eo_friends.name = 'Wendy Moody'", 1 );
 
         // everybody but 1 doesn't have a friend named Shari Hahh
         testQuery(scope, searchTypes, entityIndex, "not (friends.name = 'Shari Hahn')", totalUsers
- 1);


Mime
View raw message