usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [3/4] incubator-usergrid git commit: Fixes querying by UUID
Date Fri, 10 Apr 2015 00:25:50 GMT
Fixes querying by UUID


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

Branch: refs/heads/USERGRID-536
Commit: b09804935ccf223fdf5844378caaac995d8dc57b
Parents: 3d036e1
Author: Todd Nine <tnine@apigee.com>
Authored: Thu Apr 9 17:26:24 2015 -0600
Committer: Todd Nine <tnine@apigee.com>
Committed: Thu Apr 9 17:26:24 2015 -0600

----------------------------------------------------------------------
 .../persistence/index/impl/EntityField.java     |  27 +-
 .../index/impl/EntityMappingParser.java         |  15 ++
 .../persistence/index/impl/EsQueryVistor.java   |  41 +--
 .../persistence/index/impl/IndexingUtils.java   |   6 +-
 .../persistence/index/usergrid-mappings.json    |   6 +-
 .../persistence/index/impl/EntityIndexTest.java |  45 ++++
 .../index/impl/EntityToMapConverterTest.java    | 249 +++++++++----------
 7 files changed, 233 insertions(+), 156 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0980493/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityField.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityField.java
index 7e7c610..a1eec91 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityField.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityField.java
@@ -26,6 +26,7 @@ package org.apache.usergrid.persistence.index.impl;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.UUID;
 
 
 /**
@@ -49,7 +50,7 @@ public class EntityField extends HashMap<String, Object> {
      */
     public static EntityField create( final String fieldName, final String value ) {
         EntityField field = new EntityField();
-        field.put( IndexingUtils.FIELD_NAME, fieldName );
+        field.put( IndexingUtils.FIELD_NAME, fieldName.toLowerCase() );
         field.put( IndexingUtils.FIELD_STRING, value );
 
         return field;
@@ -57,11 +58,23 @@ public class EntityField extends HashMap<String, Object> {
 
 
     /**
+     * Set a uuid value into the field
+     */
+    public static EntityField create( final String fieldName, final UUID value ) {
+        EntityField field = new EntityField();
+        field.put( IndexingUtils.FIELD_NAME, fieldName.toLowerCase() );
+        field.put( IndexingUtils.FIELD_UUID, value.toString() );
+
+        return field;
+    }
+
+
+    /**
      * Set a string value into the field
      */
     public static EntityField create( final String fieldName, final boolean value ) {
         EntityField field = new EntityField();
-        field.put( IndexingUtils.FIELD_NAME, fieldName );
+        field.put( IndexingUtils.FIELD_NAME, fieldName.toLowerCase() );
         field.put( IndexingUtils.FIELD_BOOLEAN, value );
 
         return field;
@@ -75,7 +88,7 @@ public class EntityField extends HashMap<String, Object> {
      */
     public static EntityField create( final String fieldName, final int value ) {
         EntityField field = new EntityField();
-        field.put( IndexingUtils.FIELD_NAME, fieldName );
+        field.put( IndexingUtils.FIELD_NAME, fieldName.toLowerCase() );
         field.put( IndexingUtils.FIELD_LONG, value );
 
         return field;
@@ -87,7 +100,7 @@ public class EntityField extends HashMap<String, Object> {
      */
     public static EntityField create( final String fieldName, final long value ) {
         EntityField field = new EntityField();
-        field.put( IndexingUtils.FIELD_NAME, fieldName );
+        field.put( IndexingUtils.FIELD_NAME, fieldName.toLowerCase() );
         field.put( IndexingUtils.FIELD_LONG, value );
 
         return field;
@@ -99,7 +112,7 @@ public class EntityField extends HashMap<String, Object> {
      */
     public static EntityField create( final String fieldName, final float value ) {
         EntityField field = new EntityField();
-        field.put( IndexingUtils.FIELD_NAME, fieldName );
+        field.put( IndexingUtils.FIELD_NAME, fieldName.toLowerCase() );
         field.put( IndexingUtils.FIELD_DOUBLE, value );
 
         return field;
@@ -111,7 +124,7 @@ public class EntityField extends HashMap<String, Object> {
      */
     public static EntityField create( final String fieldName, final double value ) {
         EntityField field = new EntityField();
-        field.put( IndexingUtils.FIELD_NAME, fieldName );
+        field.put( IndexingUtils.FIELD_NAME, fieldName.toLowerCase() );
         field.put( IndexingUtils.FIELD_DOUBLE, value );
 
         return field;
@@ -125,7 +138,7 @@ public class EntityField extends HashMap<String, Object> {
      */
     public static EntityField create( final String fieldName, final Map location) {
         EntityField field = new EntityField();
-        field.put( IndexingUtils.FIELD_NAME, fieldName );
+        field.put( IndexingUtils.FIELD_NAME, fieldName.toLowerCase() );
         field.put( IndexingUtils.FIELD_LOCATION, location );
 
         return field;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0980493/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
index 0369ff0..9adc35d 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
@@ -29,6 +29,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Stack;
+import java.util.UUID;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -71,6 +72,15 @@ public class EntityMappingParser implements FieldParser {
     }
 
 
+
+    /**
+     * Visit al the primitive values
+     */
+    private void visit( final UUID value ) {
+        fields.add( EntityField.create( fieldStack.peek(), value ) );
+    }
+
+
     private void visit( final boolean value ) {
         fields.add( EntityField.create( fieldStack.peek(), value ) );
     }
@@ -155,6 +165,11 @@ public class EntityMappingParser implements FieldParser {
             return;
         }
 
+        if(object instanceof  UUID){
+            visit((UUID) object);
+            return;
+        }
+
         if ( object instanceof Boolean ) {
             visit( ( Boolean ) object );
             return;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0980493/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
index 316a297..74925fd 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
@@ -19,10 +19,8 @@
 package org.apache.usergrid.persistence.index.impl;
 
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
 import java.util.Stack;
+import java.util.UUID;
 
 import org.elasticsearch.common.geo.GeoDistance;
 import org.elasticsearch.common.unit.DistanceUnit;
@@ -82,7 +80,6 @@ public class EsQueryVistor implements QueryVisitor {
     private final GeoSortFields geoSortFields = new GeoSortFields();
 
 
-
     @Override
     public void visit( AndOperand op ) throws IndexException {
 
@@ -122,7 +119,7 @@ public class EsQueryVistor implements QueryVisitor {
             queryBuilders.push( rightQuery );
         }
         //put in an empty in case we're not the root.  I.E X and Y and Z
-        else{
+        else {
             queryBuilders.push( NoOpQueryBuilder.INSTANCE );
         }
 
@@ -147,7 +144,7 @@ public class EsQueryVistor implements QueryVisitor {
             filterBuilders.push( rightFilter );
         }
         //push in a no-op in case we're not the root   I.E X and Y and Z
-        else{
+        else {
             filterBuilders.push( NoOpFilterBuilder.INSTANCE );
         }
     }
@@ -183,8 +180,8 @@ public class EsQueryVistor implements QueryVisitor {
             queryBuilders.push( rightQuery );
         }
 
-         //put in an empty in case we're not the root.  I.E X or Y or Z
-        else{
+        //put in an empty in case we're not the root.  I.E X or Y or Z
+        else {
             queryBuilders.push( NoOpQueryBuilder.INSTANCE );
         }
 
@@ -206,11 +203,10 @@ public class EsQueryVistor implements QueryVisitor {
         else if ( useRightFilter ) {
             filterBuilders.push( rightFilter );
         }
-         //put in an empty in case we're not the root.  I.E X or Y or Z
-        else{
+        //put in an empty in case we're not the root.  I.E X or Y or Z
+        else {
             queryBuilders.push( NoOpQueryBuilder.INSTANCE );
         }
-
     }
 
 
@@ -225,7 +221,7 @@ public class EsQueryVistor implements QueryVisitor {
         if ( use( notQueryBuilder ) ) {
             queryBuilders.push( QueryBuilders.boolQuery().mustNot( notQueryBuilder ) );
         }
-        else{
+        else {
             queryBuilders.push( NoOpQueryBuilder.INSTANCE );
         }
 
@@ -235,7 +231,7 @@ public class EsQueryVistor implements QueryVisitor {
         if ( use( notFilterBuilder ) ) {
             filterBuilders.push( FilterBuilders.boolFilter().mustNot( notFilterBuilder )
);
         }
-        else{
+        else {
             filterBuilders.push( NoOpFilterBuilder.INSTANCE );
         }
     }
@@ -278,8 +274,9 @@ public class EsQueryVistor implements QueryVisitor {
         float distance = op.getDistance().getFloatValue();
 
 
-        final FilterBuilder fb = FilterBuilders.geoDistanceFilter( IndexingUtils.FIELD_LOCATION_NESTED
).lat( lat ).lon( lon )
-                                               .distance( distance, DistanceUnit.METERS );
+        final FilterBuilder fb =
+                FilterBuilders.geoDistanceFilter( IndexingUtils.FIELD_LOCATION_NESTED ).lat(
lat ).lon( lon )
+                              .distance( distance, DistanceUnit.METERS );
 
 
         filterBuilders.push( fieldNameTerm( name, fb ) );
@@ -290,8 +287,8 @@ public class EsQueryVistor implements QueryVisitor {
         //this geoSort won't has a sort on it
 
         final GeoDistanceSortBuilder geoSort =
-                      SortBuilders.geoDistanceSort( IndexingUtils.FIELD_LOCATION_NESTED )
-                                  .unit( DistanceUnit.METERS ).geoDistance( GeoDistance.SLOPPY_ARC
).point( lat, lon );
+                SortBuilders.geoDistanceSort( IndexingUtils.FIELD_LOCATION_NESTED ).unit(
DistanceUnit.METERS )
+                            .geoDistance( GeoDistance.SLOPPY_ARC ).point( lat, lon );
 
         final TermFilterBuilder sortPropertyName = sortPropertyTermFilter( name );
 
@@ -505,6 +502,11 @@ public class EsQueryVistor implements QueryVisitor {
         }
 
 
+        if ( object instanceof UUID ) {
+            return IndexingUtils.FIELD_UUID_NESTED;
+        }
+
+
         throw new UnsupportedOperationException(
                 "Unkown search type of " + object.getClass().getName() + " encountered" );
     }
@@ -518,6 +520,10 @@ public class EsQueryVistor implements QueryVisitor {
             return ( ( String ) input ).toLowerCase();
         }
 
+        if ( input instanceof UUID ) {
+            return input.toString();
+        }
+
         return input;
     }
 
@@ -536,5 +542,4 @@ public class EsQueryVistor implements QueryVisitor {
     private boolean use( final FilterBuilder filterBuilder ) {
         return filterBuilder != NoOpFilterBuilder.INSTANCE;
     }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0980493/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
index 7a70e15..3ccac44 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
@@ -66,7 +66,6 @@ public class IndexingUtils {
 
     public static final String ENTITY_FIELDS = "fields";
 
-
     /**
      * Reserved field types in our document
      *
@@ -78,9 +77,7 @@ public class IndexingUtils {
     public static final String FIELD_DOUBLE = "double";
     public static final String FIELD_LOCATION = "location";
     public static final String FIELD_STRING = "string";
-
-
-
+    public static final String FIELD_UUID = "uuid";
 
 
     /**
@@ -92,6 +89,7 @@ public class IndexingUtils {
     public static final String FIELD_DOUBLE_NESTED = ENTITY_FIELDS + "." + FIELD_DOUBLE;
     public static final String FIELD_LOCATION_NESTED = ENTITY_FIELDS + "." + FIELD_LOCATION;
     public static final String FIELD_STRING_NESTED = ENTITY_FIELDS + "." + FIELD_STRING;
+    public static final String FIELD_UUID_NESTED = ENTITY_FIELDS + "." + FIELD_UUID;
     public static final String FIELD_STRING_EQUALS_NESTED = FIELD_STRING_NESTED + ".exact";
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0980493/stack/corepersistence/queryindex/src/main/resources/org/apache/usergrid/persistence/index/usergrid-mappings.json
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/resources/org/apache/usergrid/persistence/index/usergrid-mappings.json
b/stack/corepersistence/queryindex/src/main/resources/org/apache/usergrid/persistence/index/usergrid-mappings.json
index e90f5a7..4da1902 100644
--- a/stack/corepersistence/queryindex/src/main/resources/org/apache/usergrid/persistence/index/usergrid-mappings.json
+++ b/stack/corepersistence/queryindex/src/main/resources/org/apache/usergrid/persistence/index/usergrid-mappings.json
@@ -79,8 +79,12 @@
                 "index": "not_analyzed",
                 "doc_values": true
               }
-
             }
+          },
+          "uuid": {
+            "type": "string",
+            "index": "not_analyzed",
+            "doc_values": true
           }
         }
       }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0980493/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 082b72d..c9feadb 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
@@ -729,6 +729,51 @@ public class EntityIndexTest extends BaseIT {
     }
 
 
+
+    @Test
+    public void queryByUUID() throws Throwable {
+
+        Id appId = new SimpleId( "application" );
+        Id ownerId = new SimpleId( "owner" );
+
+        ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
+
+        IndexEdge indexSCope = new IndexEdgeImpl( ownerId, "user", SearchEdge.NodeType.SOURCE,
10 );
+
+        ApplicationEntityIndex entityIndex = eif.createApplicationEntityIndex( applicationScope
);
+
+
+        final UUID searchUUID = UUIDGenerator.newTimeUUID();
+
+        Map entityMap = new HashMap() {{
+            put( "searchUUID", searchUUID );
+        }};
+
+        Entity user = EntityIndexMapUtils.fromMap( entityMap );
+
+        final Id entityId = new SimpleId( "entitytype" );
+
+        EntityUtils.setId( user, entityId );
+        EntityUtils.setVersion( user, UUIDGenerator.newTimeUUID() );
+
+
+        EntityIndexBatch batch = entityIndex.createBatch();
+
+        batch.index( indexSCope, user );
+        batch.execute().get();
+        ei.refresh();
+
+        final String query = "where searchUUID = " + searchUUID;
+
+        final CandidateResults r = entityIndex.search( indexSCope, SearchTypes.fromTypes(
entityId.getType() ), query, 10 );
+        assertEquals( user.getId(), r.get( 0 ).getId() );
+
+        batch.deindex( indexSCope, user.getId(), user.getVersion() );
+        batch.execute().get();
+        ei.refresh();
+    }
+
+
 }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0980493/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverterTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverterTest.java
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverterTest.java
index 002e9b2..7fed42c 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverterTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverterTest.java
@@ -45,6 +45,7 @@ import org.apache.usergrid.persistence.model.field.IntegerField;
 import org.apache.usergrid.persistence.model.field.LocationField;
 import org.apache.usergrid.persistence.model.field.LongField;
 import org.apache.usergrid.persistence.model.field.StringField;
+import org.apache.usergrid.persistence.model.field.UUIDField;
 import org.apache.usergrid.persistence.model.field.value.EntityObject;
 import org.apache.usergrid.persistence.model.field.value.Location;
 import org.apache.usergrid.persistence.model.util.EntityUtils;
@@ -74,7 +75,7 @@ public class EntityToMapConverterTest {
         final ApplicationScope scope = new ApplicationScopeImpl( createId( "application"
) );
 
         final IndexEdge indexEdge =
-                new IndexEdgeImpl( createId( "source" ), "testEdgeType", SearchEdge.NodeType.SOURCE,
1000 );
+            new IndexEdgeImpl( createId( "source" ), "testEdgeType", SearchEdge.NodeType.SOURCE,
1000 );
 
 
         final Map<String, Object> entityMap = EntityToMapConverter.convert( scope,
indexEdge, entity );
@@ -130,66 +131,73 @@ public class EntityToMapConverterTest {
 
     @Test
     public void testStringField() {
-        testSingleField( new StringField( "name", "value" ), ( field, entityField ) ->
assertEquals( field.getValue(),
-                        entityField.get( IndexingUtils.FIELD_STRING ) ) );
+        testSingleField( new StringField( "Name", "value" ),
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_STRING ) ) );
     }
 
 
     @Test
     public void testBooleanField() {
-        testSingleField( new BooleanField( "name", true ), ( field, entityField ) -> assertEquals(
field.getValue(),
-                        entityField.get( IndexingUtils.FIELD_BOOLEAN ) ) );
+        testSingleField( new BooleanField( "Name", true ), ( field, entityField ) -> assertEquals(
field.getValue(),
+            entityField.get( IndexingUtils.FIELD_BOOLEAN ) ) );
     }
 
 
     @Test
     public void testIntegerField() {
-        testSingleField( new IntegerField( "name", 100 ),
-                ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_LONG )
-                                                      ) );
+        testSingleField( new IntegerField( "Name", 100 ),
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_LONG ) ) );
     }
 
 
     @Test
     public void testLongField() {
-        testSingleField( new LongField( "name", 100l ), ( field, entityField ) -> assertEquals(
field.getValue(),
-                        entityField.get( IndexingUtils.FIELD_LONG ) ) );
+        testSingleField( new LongField( "Name", 100l ),
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_LONG ) ) );
     }
 
 
     @Test
     public void testFloadField() {
-        testSingleField( new FloatField( "name", 1.10f ), ( field, entityField ) -> assertEquals(
field.getValue(),
-                        entityField.get( IndexingUtils.FIELD_DOUBLE ) ) );
+        testSingleField( new FloatField( "Name", 1.10f ),
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_DOUBLE ) ) );
+    }
+
+
+    /**
+     * Test converting a UUID to a string
+     */
+    @Test
+    public void testUUIDField() {
+        testSingleField( new UUIDField( "Name", UUIDGenerator.newTimeUUID() ),
+            ( field, entityField ) -> assertEquals( field.getValue().toString(), entityField.get(
IndexingUtils.FIELD_UUID ) ) );
     }
 
 
     @Test
     public void testDoubleField() {
-        testSingleField( new DoubleField( "name", 2.20d ), ( field, entityField ) -> assertEquals(
field.getValue(),
-                        entityField.get( IndexingUtils.FIELD_DOUBLE ) ) );
+        testSingleField( new DoubleField( "Name", 2.20d ),
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_DOUBLE ) ) );
     }
 
 
     @Test
     public void testLocationField() {
-        testSingleField( new LocationField( "name", new Location( 10, 20 ) ), ( field, entityField
) -> {
+        testSingleField( new LocationField( "Name", new Location( 10, 20 ) ), ( field, entityField
) -> {
             final Map<String, Double> latLong = ( Map<String, Double> ) entityField.get(
IndexingUtils.FIELD_LOCATION );
 
             assertEquals( Double.valueOf( 10 ),
-                    latLong.get( org.apache.usergrid.persistence.model.entity.EntityToMapConverter.LAT
) );
+                latLong.get( org.apache.usergrid.persistence.model.entity.EntityToMapConverter.LAT
) );
             assertEquals( Double.valueOf( 20 ),
-                    latLong.get( org.apache.usergrid.persistence.model.entity.EntityToMapConverter.LON
) );
+                latLong.get( org.apache.usergrid.persistence.model.entity.EntityToMapConverter.LON
) );
         } );
     }
 
 
-
     /**
      * Test the single field in our root level
      */
-    public <T> void testSingleField( final Field<T> field,
-                                     Action2<Field, EntityField> assertFunction ) {
+    public <T> void testSingleField( final Field<T> field, Action2<Field,
EntityField> assertFunction ) {
         Entity entity = new Entity( "test" );
         entity.setField( field );
 
@@ -201,7 +209,7 @@ public class EntityToMapConverterTest {
         final ApplicationScope scope = new ApplicationScopeImpl( createId( "application"
) );
 
         final IndexEdge indexEdge =
-                new IndexEdgeImpl( createId( "source" ), "testEdgeType", SearchEdge.NodeType.SOURCE,
1000 );
+            new IndexEdgeImpl( createId( "source" ), "testEdgeType", SearchEdge.NodeType.SOURCE,
1000 );
 
 
         final Map<String, Object> entityMap = EntityToMapConverter.convert( scope,
indexEdge, entity );
@@ -213,7 +221,10 @@ public class EntityToMapConverterTest {
 
         final EntityField esField = fields.get( 0 );
 
-        assertEquals( field.getName(), esField.get( IndexingUtils.FIELD_NAME ) );
+        //always test the lower case arrays
+        final String fieldName = field.getName().toLowerCase();
+
+        assertEquals( fieldName, esField.get( IndexingUtils.FIELD_NAME ) );
 
         assertFunction.call( field, esField );
     }
@@ -324,7 +335,7 @@ public class EntityToMapConverterTest {
         final ApplicationScope scope = new ApplicationScopeImpl( createId( "application"
) );
 
         final IndexEdge indexEdge =
-                new IndexEdgeImpl( createId( "source" ), "testEdgeType", SearchEdge.NodeType.SOURCE,
1000 );
+            new IndexEdgeImpl( createId( "source" ), "testEdgeType", SearchEdge.NodeType.SOURCE,
1000 );
 
 
         final Map<String, Object> entityMap = EntityToMapConverter.convert( scope,
indexEdge, entity );
@@ -345,47 +356,45 @@ public class EntityToMapConverterTest {
     }
 
 
-
     @Test
     public void testStringFieldSubObject() {
-        testNestedField( new StringField( "name", "value" ), ( field, entityField ) ->
assertEquals( field.getValue(),
-                entityField.get( IndexingUtils.FIELD_STRING ) ) );
+        testNestedField( new StringField( "name", "value" ),
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_STRING ) ) );
     }
 
 
     @Test
     public void testBooleanFieldSubObject() {
         testNestedField( new BooleanField( "name", true ), ( field, entityField ) -> assertEquals(
field.getValue(),
-                entityField.get( IndexingUtils.FIELD_BOOLEAN ) ) );
+            entityField.get( IndexingUtils.FIELD_BOOLEAN ) ) );
     }
 
 
     @Test
     public void testIntegerFieldSubObject() {
         testNestedField( new IntegerField( "name", 100 ),
-                ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_LONG )
-                                                      ) );
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_LONG ) ) );
     }
 
 
     @Test
     public void testLongFieldSubObject() {
-        testNestedField( new LongField( "name", 100l ), ( field, entityField ) -> assertEquals(
field.getValue(),
-                entityField.get( IndexingUtils.FIELD_LONG ) ) );
+        testNestedField( new LongField( "name", 100l ),
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_LONG ) ) );
     }
 
 
     @Test
     public void testFloadFieldSubObject() {
-        testNestedField( new FloatField( "name", 1.10f ), ( field, entityField ) -> assertEquals(
field.getValue(),
-                entityField.get( IndexingUtils.FIELD_DOUBLE ) ) );
+        testNestedField( new FloatField( "name", 1.10f ),
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_DOUBLE ) ) );
     }
 
 
     @Test
     public void testDoubleFieldSubObject() {
-        testNestedField( new DoubleField( "name", 2.20d ), ( field, entityField ) -> assertEquals(
field.getValue(),
-                entityField.get( IndexingUtils.FIELD_DOUBLE ) ) );
+        testNestedField( new DoubleField( "name", 2.20d ),
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_DOUBLE ) ) );
     }
 
 
@@ -395,117 +404,111 @@ public class EntityToMapConverterTest {
             final Map<String, Double> latLong = ( Map<String, Double> ) entityField.get(
IndexingUtils.FIELD_LOCATION );
 
             assertEquals( Double.valueOf( 10 ),
-                    latLong.get( org.apache.usergrid.persistence.model.entity.EntityToMapConverter.LAT
) );
+                latLong.get( org.apache.usergrid.persistence.model.entity.EntityToMapConverter.LAT
) );
             assertEquals( Double.valueOf( 20 ),
-                    latLong.get( org.apache.usergrid.persistence.model.entity.EntityToMapConverter.LON
) );
+                latLong.get( org.apache.usergrid.persistence.model.entity.EntityToMapConverter.LON
) );
         } );
     }
 
 
-     /**
-      * Test primitive arrays in the root of an object
-      *
-      * @param storedField The field stored on the nested object
-      * @param assertFunction The function
-      */
-     private <T> void testNestedField( final Field<T> storedField,   Action2<Field,
EntityField> assertFunction ) {
-
-         EntityObject leafEntity = new EntityObject( );
+    /**
+     * Test primitive arrays in the root of an object
+     *
+     * @param storedField The field stored on the nested object
+     * @param assertFunction The function
+     */
+    private <T> void testNestedField( final Field<T> storedField, Action2<Field,
EntityField> assertFunction ) {
 
-         leafEntity.setField( storedField );
+        EntityObject leafEntity = new EntityObject();
 
+        leafEntity.setField( storedField );
 
 
-         final EntityObjectField nested2Field = new EntityObjectField( "nested2", leafEntity
);
+        final EntityObjectField nested2Field = new EntityObjectField( "nested2", leafEntity
);
 
-         final EntityObject nested2 = new EntityObject();
-         nested2.setField( nested2Field );
+        final EntityObject nested2 = new EntityObject();
+        nested2.setField( nested2Field );
 
-         final EntityObjectField nested1Field = new EntityObjectField( "nested1", nested2
);
+        final EntityObjectField nested1Field = new EntityObjectField( "nested1", nested2
);
 
 
-         Entity rootEntity = new Entity( "test" );
+        Entity rootEntity = new Entity( "test" );
 
 
-         rootEntity.setField( nested1Field );
+        rootEntity.setField( nested1Field );
 
 
-         final UUID version = UUIDGenerator.newTimeUUID();
+        final UUID version = UUIDGenerator.newTimeUUID();
 
-         EntityUtils.setVersion( rootEntity, version );
+        EntityUtils.setVersion( rootEntity, version );
 
-         final ApplicationScope scope = new ApplicationScopeImpl( createId( "application"
) );
+        final ApplicationScope scope = new ApplicationScopeImpl( createId( "application"
) );
 
-         final IndexEdge indexEdge =
-                 new IndexEdgeImpl( createId( "source" ), "testEdgeType", SearchEdge.NodeType.SOURCE,
1000 );
+        final IndexEdge indexEdge =
+            new IndexEdgeImpl( createId( "source" ), "testEdgeType", SearchEdge.NodeType.SOURCE,
1000 );
 
 
-         final Map<String, Object> entityMap = EntityToMapConverter.convert( scope,
indexEdge, rootEntity );
+        final Map<String, Object> entityMap = EntityToMapConverter.convert( scope,
indexEdge, rootEntity );
 
 
-         final List<EntityField> fields = ( List<EntityField> ) entityMap.get(
IndexingUtils.ENTITY_FIELDS );
+        final List<EntityField> fields = ( List<EntityField> ) entityMap.get(
IndexingUtils.ENTITY_FIELDS );
 
-         assertEquals( 1, fields.size() );
+        assertEquals( 1, fields.size() );
 
 
-         for ( int i = 0; i < fields.size(); i++ ) {
-             final EntityField field = fields.get( i );
+        for ( int i = 0; i < fields.size(); i++ ) {
+            final EntityField field = fields.get( i );
 
-             final String path = "nested1.nested2." + storedField.getName();
+            final String path = "nested1.nested2." + storedField.getName();
 
-             assertEquals( path, field.get( IndexingUtils.FIELD_NAME ) );
+            assertEquals( path, field.get( IndexingUtils.FIELD_NAME ) );
 
 
-             assertFunction.call( storedField, field );
-         }
-     }
+            assertFunction.call( storedField, field );
+        }
+    }
 
 
     @Test
     public void testStringFieldSubObjectArray() {
         testNestedFieldArraySubObject( new StringField( "name", "value" ),
-                ( field, entityField ) -> assertEquals( field.getValue(),
-                        entityField.get( IndexingUtils.FIELD_STRING ) ) );
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_STRING ) ) );
     }
 
 
     @Test
     public void testBooleanFieldSubObjectArray() {
         testNestedFieldArraySubObject( new BooleanField( "name", true ),
-                ( field, entityField ) -> assertEquals( field.getValue(),
-                        entityField.get( IndexingUtils.FIELD_BOOLEAN ) ) );
+            ( field, entityField ) -> assertEquals( field.getValue(),
+                entityField.get( IndexingUtils.FIELD_BOOLEAN ) ) );
     }
 
 
     @Test
     public void testIntegerFieldSubObjectArray() {
         testNestedFieldArraySubObject( new IntegerField( "name", 100 ),
-                ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_LONG )
-                                                      ) );
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_LONG ) ) );
     }
 
 
     @Test
     public void testLongFieldSubObjectArray() {
         testNestedFieldArraySubObject( new LongField( "name", 100l ),
-                ( field, entityField ) -> assertEquals( field.getValue(),
-                        entityField.get( IndexingUtils.FIELD_LONG ) ) );
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_LONG ) ) );
     }
 
 
     @Test
     public void testFloadFieldSubObjectArray() {
         testNestedFieldArraySubObject( new FloatField( "name", 1.10f ),
-                ( field, entityField ) -> assertEquals( field.getValue(),
-                        entityField.get( IndexingUtils.FIELD_DOUBLE ) ) );
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_DOUBLE ) ) );
     }
 
 
     @Test
     public void testDoubleFieldSubObjectArray() {
         testNestedFieldArraySubObject( new DoubleField( "name", 2.20d ),
-                ( field, entityField ) -> assertEquals( field.getValue(),
-                        entityField.get( IndexingUtils.FIELD_DOUBLE ) ) );
+            ( field, entityField ) -> assertEquals( field.getValue(), entityField.get(
IndexingUtils.FIELD_DOUBLE ) ) );
     }
 
 
@@ -515,89 +518,85 @@ public class EntityToMapConverterTest {
             final Map<String, Double> latLong = ( Map<String, Double> ) entityField.get(
IndexingUtils.FIELD_LOCATION );
 
             assertEquals( Double.valueOf( 10 ),
-                    latLong.get( org.apache.usergrid.persistence.model.entity.EntityToMapConverter.LAT
) );
+                latLong.get( org.apache.usergrid.persistence.model.entity.EntityToMapConverter.LAT
) );
             assertEquals( Double.valueOf( 20 ),
-                    latLong.get( org.apache.usergrid.persistence.model.entity.EntityToMapConverter.LON
) );
+                latLong.get( org.apache.usergrid.persistence.model.entity.EntityToMapConverter.LON
) );
         } );
     }
 
 
-     /**
-      * Test primitive arrays in the root of an object
-      *
-      * @param storedField The field stored on the nested object
-      * @param assertFunction The function
-      */
-     private <T> void testNestedFieldArraySubObject( final Field<T> storedField,
-                                                     Action2<Field, EntityField> assertFunction
) {
-
-         EntityObject leafEntity = new EntityObject( );
-
-         leafEntity.setField( storedField );
+    /**
+     * Test primitive arrays in the root of an object
+     *
+     * @param storedField The field stored on the nested object
+     * @param assertFunction The function
+     */
+    private <T> void testNestedFieldArraySubObject( final Field<T> storedField,
+                                                    Action2<Field, EntityField> assertFunction
) {
 
+        EntityObject leafEntity = new EntityObject();
 
+        leafEntity.setField( storedField );
 
-         final EntityObjectField nested2Field = new EntityObjectField( "nested2", leafEntity
);
 
-         final EntityObject nested2 = new EntityObject();
-         nested2.setField( nested2Field );
+        final EntityObjectField nested2Field = new EntityObjectField( "nested2", leafEntity
);
 
-         final EntityObjectField nested1Field = new EntityObjectField( "nested1", nested2
);
+        final EntityObject nested2 = new EntityObject();
+        nested2.setField( nested2Field );
 
-         final EntityObject nested1 = new EntityObject();
-         nested1.setField( nested1Field );
+        final EntityObjectField nested1Field = new EntityObjectField( "nested1", nested2
);
 
+        final EntityObject nested1 = new EntityObject();
+        nested1.setField( nested1Field );
 
 
-         final ArrayField<EntityObject> array = new ArrayField<>( "array" );
+        final ArrayField<EntityObject> array = new ArrayField<>( "array" );
 
-         array.add( nested1 );
+        array.add( nested1 );
 
-         Entity rootEntity = new Entity( "test" );
+        Entity rootEntity = new Entity( "test" );
 
-         rootEntity.setField( array );
+        rootEntity.setField( array );
 
 
-         final UUID version = UUIDGenerator.newTimeUUID();
+        final UUID version = UUIDGenerator.newTimeUUID();
 
-         EntityUtils.setVersion( rootEntity, version );
+        EntityUtils.setVersion( rootEntity, version );
 
-         final ApplicationScope scope = new ApplicationScopeImpl( createId( "application"
) );
+        final ApplicationScope scope = new ApplicationScopeImpl( createId( "application"
) );
 
-         final IndexEdge indexEdge =
-                 new IndexEdgeImpl( createId( "source" ), "testEdgeType", SearchEdge.NodeType.SOURCE,
1000 );
+        final IndexEdge indexEdge =
+            new IndexEdgeImpl( createId( "source" ), "testEdgeType", SearchEdge.NodeType.SOURCE,
1000 );
 
 
-         final Map<String, Object> entityMap = EntityToMapConverter.convert( scope,
indexEdge, rootEntity );
+        final Map<String, Object> entityMap = EntityToMapConverter.convert( scope,
indexEdge, rootEntity );
 
 
-         final List<EntityField> fields = ( List<EntityField> ) entityMap.get(
IndexingUtils.ENTITY_FIELDS );
+        final List<EntityField> fields = ( List<EntityField> ) entityMap.get(
IndexingUtils.ENTITY_FIELDS );
 
-         assertEquals( 1, fields.size() );
+        assertEquals( 1, fields.size() );
 
 
-         for ( int i = 0; i < fields.size(); i++ ) {
-             final EntityField field = fields.get( i );
+        for ( int i = 0; i < fields.size(); i++ ) {
+            final EntityField field = fields.get( i );
 
-             final String path = "array.nested1.nested2." + storedField.getName();
+            final String path = "array.nested1.nested2." + storedField.getName();
 
-             assertEquals( path, field.get( IndexingUtils.FIELD_NAME ) );
+            assertEquals( path, field.get( IndexingUtils.FIELD_NAME ) );
 
 
-             assertFunction.call( storedField, field );
-         }
-     }
+            assertFunction.call( storedField, field );
+        }
+    }
 
 
     /**
      * 2d + arrays aren't supported, ensure we drop elements with a depth > 1
-     *
      */
     @Test
     public void testNDimensionalArray() {
 
 
-
         //create an object with a string value in it, this should be indexed
         final StringField string = new StringField( "string", "value" );
 
@@ -613,13 +612,12 @@ public class EntityToMapConverterTest {
         final ArrayField<Object> array = new ArrayField<>( "array" );
 
         //not indexed
-        array.add( subArray);
+        array.add( subArray );
 
         //indexed
         array.add( nested1 );
 
 
-
         Entity rootEntity = new Entity( "test" );
 
         rootEntity.setField( array );
@@ -632,7 +630,7 @@ public class EntityToMapConverterTest {
         final ApplicationScope scope = new ApplicationScopeImpl( createId( "application"
) );
 
         final IndexEdge indexEdge =
-                new IndexEdgeImpl( createId( "source" ), "testEdgeType", SearchEdge.NodeType.SOURCE,
1000 );
+            new IndexEdgeImpl( createId( "source" ), "testEdgeType", SearchEdge.NodeType.SOURCE,
1000 );
 
 
         final Map<String, Object> entityMap = EntityToMapConverter.convert( scope,
indexEdge, rootEntity );
@@ -650,7 +648,6 @@ public class EntityToMapConverterTest {
         assertEquals( path, field.get( IndexingUtils.FIELD_NAME ) );
 
 
-       assertEquals("value", field.get( IndexingUtils.FIELD_STRING ));
-
+        assertEquals( "value", field.get( IndexingUtils.FIELD_STRING ) );
     }
 }


Mime
View raw message