You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/11/24 15:40:46 UTC

[1/9] incubator-usergrid git commit: Additional geo query tests

Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o-events 43105f126 -> 32276938d


Additional geo query tests


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

Branch: refs/heads/two-dot-o-events
Commit: 7d5697b761c0a9744d9733e15355dbef3c117a5d
Parents: 00eb339
Author: ryan bridges <rb...@apigee.com>
Authored: Wed Nov 19 18:22:14 2014 -0500
Committer: grey <gr...@apigee.com>
Committed: Thu Nov 20 10:52:47 2014 -0800

----------------------------------------------------------------------
 .../org/apache/usergrid/persistence/GeoIT.java  | 404 +++++++++++++------
 1 file changed, 287 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7d5697b7/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
index 39e39b2..9556852 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
@@ -17,12 +17,7 @@
 package org.apache.usergrid.persistence;
 
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
 
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -36,6 +31,7 @@ import org.apache.usergrid.utils.MapUtils;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 
 @Concurrent()
@@ -48,168 +44,342 @@ public class GeoIT extends AbstractCoreIT {
     }
 
 
-    @Test
-    public void testGeo() throws Exception {
-        LOG.info( "GeoIT.testGeo" );
+  @Test
+  public void testGeo() throws Exception {
+    LOG.info( "GeoIT.testGeo" );
 
 
 
 
-        EntityManager em =  app.getEntityManager();
-        assertNotNull( em );
+    EntityManager em =  app.getEntityManager();
+    assertNotNull( em );
 
-        // create user at a location  
-        Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
-            put( "username", "edanuff" );
-            put( "email", "ed@anuff.com" );
-            put( "location", new LinkedHashMap<String, Object>() {{
-                put("latitude", 37.776753 );
-                put("longitude", -122.407846 );
-            }} ); 
-        }};
+    // create user at a location
+    Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+      put( "username", "edanuff" );
+      put( "email", "ed@anuff.com" );
+      put( "location", new LinkedHashMap<String, Object>() {{
+        put("latitude", 37.776753 );
+        put("longitude", -122.407846 );
+      }} );
+    }};
 
-        Entity user = em.create( "user", properties );
-        assertNotNull( user );
+    Entity user = em.create( "user", properties );
+    assertNotNull( user );
 
-        em.refreshIndex();
+    em.refreshIndex();
 
-        // define center point about 300m from that location
-        Point center = new Point( 37.774277, -122.404744 );
+    // define center point about 300m from that location
+    Point center = new Point( 37.774277, -122.404744 );
 
-        Query query = Query.fromQL( "select * where location within 200 of " 
-                                    + center.getLat() + "," + center.getLon());
-        Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+    Query query = Query.fromQL( "select * where location within 200 of "
+        + center.getLat() + "," + center.getLon());
+    Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
 
-        assertEquals("No results less than 200m away from center", 0, listResults.size() );
+    assertEquals("No results less than 200m away from center", 0, listResults.size() );
 
-        query = Query.fromQL( "select * where location within 400 of " 
-                              + center.getLat() + "," + center.getLon());
-        listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+    query = Query.fromQL( "select * where location within 400 of "
+        + center.getLat() + "," + center.getLon());
+    listResults = em.searchCollection( em.getApplicationRef(), "users", query );
 
-        this.dump( listResults );
+    this.dump( listResults );
 
-        assertEquals("1 result less than 400m away from center", 1, listResults.size() );
+    assertEquals("1 result less than 400m away from center", 1, listResults.size() );
 
-        // remove location from user
-        properties.remove("location");
-        em.updateProperties(user, properties);
-        em.refreshIndex();
+    // remove location from user
+    properties.remove("location");
+    em.updateProperties(user, properties);
+    em.refreshIndex();
 
-        query = Query.fromQL( "select * where location within 400 of " 
-                              + center.getLat() + "," + center.getLon());
-        listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+    query = Query.fromQL( "select * where location within 400 of "
+        + center.getLat() + "," + center.getLon());
+    listResults = em.searchCollection( em.getApplicationRef(), "users", query );
 
-        this.dump( listResults );
-        
-        // user no longer found with 400m search
-        assertEquals( 0, listResults.size() );
+    this.dump( listResults );
 
-        // move user and center to new locations
-        updatePos( em, user, 37.426373, -122.14108 );
+    // user no longer found with 400m search
+    assertEquals( 0, listResults.size() );
 
-        center = new Point( 37.774277, -122.404744 );
+    // move user and center to new locations
+    updatePos( em, user, 37.426373, -122.14108 );
 
-        query = Query.fromQL( "select * where location within 200 of " 
-                                    + center.getLat() + "," + center.getLon());
-        listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+    center = new Point( 37.774277, -122.404744 );
 
-        assertEquals( 0, listResults.size() );
+    query = Query.fromQL( "select * where location within 200 of "
+        + center.getLat() + "," + center.getLon());
+    listResults = em.searchCollection( em.getApplicationRef(), "users", query );
 
-        updatePos( em, user, 37.774277, -122.404744 );
+    assertEquals( 0, listResults.size() );
 
-        center = new Point( 37.776753, -122.407846 );
+    updatePos( em, user, 37.774277, -122.404744 );
 
-        query = Query.fromQL( "select * where location within 1000 of " 
-                                    + center.getLat() + "," + center.getLon());
-        listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+    center = new Point( 37.776753, -122.407846 );
 
-        assertEquals( 1, listResults.size() );
+    query = Query.fromQL( "select * where location within 1000 of "
+        + center.getLat() + "," + center.getLon());
+    listResults = em.searchCollection( em.getApplicationRef(), "users", query );
 
-        // check at globally large distance
+    assertEquals( 1, listResults.size() );
 
-        query = Query.fromQL( "select * where location within " + Integer.MAX_VALUE + " of " 
-                              + center.getLat() + "," + center.getLon());
-        listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+    // check at globally large distance
 
-        assertEquals( 1, listResults.size() );
+    query = Query.fromQL( "select * where location within " + Integer.MAX_VALUE + " of "
+        + center.getLat() + "," + center.getLon());
+    listResults = em.searchCollection( em.getApplicationRef(), "users", query );
 
-        // create a new entity so we have 2
-        LinkedHashMap<String, Object> properties2 = new LinkedHashMap<String, Object>() {{
-            put( "username", "sganyo" );
-            put( "email", "sganyo@anuff.com" );
-            put( "location", new LinkedHashMap<String, Object>() {{
-                put("latitude", 31.1 );
-                put("longitude", 121.2 );
-            }} ); 
-        }};
-        Entity user2 = em.create( "user", properties2 );
-        em.refreshIndex();
-        assertNotNull( user2 );
+    assertEquals( 1, listResults.size() );
 
-        query = Query.fromQL( "select * where location within 10000 of " 
-                                    + center.getLat() + "," + center.getLon());
-        listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+    // create a new entity so we have 2
+    LinkedHashMap<String, Object> properties2 = new LinkedHashMap<String, Object>() {{
+      put( "username", "sganyo" );
+      put( "email", "sganyo@anuff.com" );
+      put( "location", new LinkedHashMap<String, Object>() {{
+        put("latitude", 31.1 );
+        put("longitude", 121.2 );
+      }} );
+    }};
+    Entity user2 = em.create( "user", properties2 );
+    em.refreshIndex();
+    assertNotNull( user2 );
 
-        assertEquals( 1, listResults.size() );
+    query = Query.fromQL( "select * where location within 10000 of "
+        + center.getLat() + "," + center.getLon());
+    listResults = em.searchCollection( em.getApplicationRef(), "users", query );
 
-        // check at globally large distance
-        query = Query.fromQL( "select * where location within " + Integer.MAX_VALUE + " of " 
-                              + center.getLat() + "," + center.getLon());
-        listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+    assertEquals( 1, listResults.size() );
 
-        assertEquals( 2, listResults.size() );
+    // check at globally large distance
+    query = Query.fromQL( "select * where location within " + Integer.MAX_VALUE + " of "
+        + center.getLat() + "," + center.getLon());
+    listResults = em.searchCollection( em.getApplicationRef(), "users", query );
 
-        // check at globally large distance (center point close to other entity)
-        center = new Point( 31.14, 121.27 );
+    assertEquals( 2, listResults.size() );
 
-        query = Query.fromQL( "select * where location within " + Integer.MAX_VALUE + " of " 
-                              + center.getLat() + "," + center.getLon());
-        listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+    // check at globally large distance (center point close to other entity)
+    center = new Point( 31.14, 121.27 );
 
-        assertEquals( 2, listResults.size() );
+    query = Query.fromQL( "select * where location within " + Integer.MAX_VALUE + " of "
+        + center.getLat() + "," + center.getLon());
+    listResults = em.searchCollection( em.getApplicationRef(), "users", query );
 
-        Results emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
-                Query.fromQL( "location within 1000 of 37.776753, -122.407846" ) );
-        assertEquals( 1, emSearchResults.size() );
+    assertEquals( 2, listResults.size() );
 
-        updatePos( em, user, 37.776753, -122.407846 );
+    Results emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
+        Query.fromQL( "location within 1000 of 37.776753, -122.407846" ) );
+    assertEquals( 1, emSearchResults.size() );
 
-        center = new Point( 37.428526, -122.140916 );
+    updatePos( em, user, 37.776753, -122.407846 );
 
-        query = Query.fromQL( "select * where location within 1000 of " 
-                              + center.getLat() + "," + center.getLon());
-        listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+    center = new Point( 37.428526, -122.140916 );
 
+    query = Query.fromQL( "select * where location within 1000 of "
+        + center.getLat() + "," + center.getLon());
+    listResults = em.searchCollection( em.getApplicationRef(), "users", query );
 
-        assertEquals( 0, listResults.size() );
 
-        emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
-                Query.fromQL( "location within 1000 of 37.428526, -122.140916" ) );
-        assertEquals( 0, emSearchResults.size() );
+    assertEquals( 0, listResults.size() );
 
-        properties = new LinkedHashMap<String, Object>();
-        properties.put( "name", "Brickhouse" );
-        properties.put( "address", "426 Brannan Street" );
-        properties.put( "location", getLocation( 37.779632, -122.395131 ) );
+    emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
+        Query.fromQL( "location within 1000 of 37.428526, -122.140916" ) );
+    assertEquals( 0, emSearchResults.size() );
 
-        Entity restaurant = em.create( "restaurant", properties );
-        assertNotNull( restaurant );
+    properties = new LinkedHashMap<String, Object>();
+    properties.put( "name", "Brickhouse" );
+    properties.put( "address", "426 Brannan Street" );
+    properties.put( "location", getLocation( 37.779632, -122.395131 ) );
 
-        em.createConnection( user, "likes", restaurant );
+    Entity restaurant = em.create( "restaurant", properties );
+    assertNotNull( restaurant );
 
-        em.refreshIndex();
+    em.createConnection( user, "likes", restaurant );
+
+    em.refreshIndex();
 
-        emSearchResults = em.searchConnectedEntities( user, 
-                Query.fromQL( "location within 2000 of 37.776753, -122.407846" ).setConnectionType( "likes" ) );
-        assertEquals( 1, emSearchResults.size() );
+    emSearchResults = em.searchConnectedEntities( user,
+        Query.fromQL( "location within 2000 of 37.776753, -122.407846" ).setConnectionType( "likes" ) );
+    assertEquals( 1, emSearchResults.size() );
 
-        emSearchResults = em.searchConnectedEntities( user, 
-                Query.fromQL( "location within 1000 of 37.776753, -122.407846" ).setConnectionType( "likes" ) );
-        assertEquals( 0, emSearchResults.size() );
+    emSearchResults = em.searchConnectedEntities( user,
+        Query.fromQL( "location within 1000 of 37.776753, -122.407846" ).setConnectionType( "likes" ) );
+    assertEquals( 0, emSearchResults.size() );
+  }
+  @Test
+  public void testGeo2() throws Exception {
+    LOG.info( "GeoIT.testGeo2" );
+    EntityManager em =  app.getEntityManager();
+    assertNotNull( em );
+
+    // create user at a location
+    Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+      put( "type", "store" );
+      put( "name", "norwest" );
+      put( "location", new LinkedHashMap<String, Object>() {{
+        put("latitude", -33.746369 );
+        put("longitude", 150.952183 );
+      }} );
+    }};
+    Entity entity = em.create( "store", properties );
+    assertNotNull( entity );
+    properties = new LinkedHashMap<String, Object>() {{
+      put( "type", "store" );
+      put( "name", "ashfield" );
+      put( "location", new LinkedHashMap<String, Object>() {{
+        put("latitude", -33.889058 );
+        put("longitude", 151.124024 );
+      }} );
+    }};
+    entity = em.create( "store", properties );
+    assertNotNull( entity );
+
+    em.refreshIndex();
+
+    Point center = new Point( 37.776753, -122.407846 );
+
+    Query query = Query.fromQL( "select * where location within 10000 of "
+        + center.getLat() + "," + center.getLon());
+    Results listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
+
+    this.dump( listResults );
+
+    assertEquals("Results less than 10000m away from center", 0, listResults.size() );
+
+    Query query2 = Query.fromQL( "select * where location within 40000000 of "
+        + center.getLat() + "," + center.getLon());
+    listResults = em.searchCollection( em.getApplicationRef(), "stores", query2 );
+
+    assertEquals("Results from center point to ridiculously far", 2, listResults.size() );
+
+  }
+  @Test
+  public void testGeo3() throws Exception {
+    LOG.info( "GeoIT.testGeo3" );
+    EntityManager em =  app.getEntityManager();
+    assertNotNull( em );
+
+    // create user at a location
+    Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+      put( "name", "norwest" );
+      put( "location", new LinkedHashMap<String, Object>() {{
+        put("latitude", -33.746369 );
+        put("longitude", 150.952183 );
+      }} );
+    }};
+    Entity entity = em.create( "store", properties );
+    assertNotNull( entity );
+    properties = new LinkedHashMap<String, Object>() {{
+      put( "name", "ashfield" );
+      put( "location", new LinkedHashMap<String, Object>() {{
+        put("latitude", -33.889058 );
+        put("longitude", 151.124024 );
+      }} );
+    }};
+    entity = em.create( "store", properties );
+    assertNotNull( entity );
+
+    em.refreshIndex();
+
+    Point center = new Point( -33.746369, 150.952183 );
+
+    Query query = Query.fromQL( "select * where location within 10000 of "
+        + center.getLat() + "," + center.getLon());
+    Results listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
+
+    this.dump( listResults );
+
+    assertEquals("Results less than 10000m away from center", 1, listResults.size() );
+
+    Query query2 = Query.fromQL( "select * where location within 40000000 of "
+        + center.getLat() + "," + center.getLon());
+    listResults = em.searchCollection( em.getApplicationRef(), "stores", query2 );
+
+    assertEquals("Results from center point to ridiculously far", 2, listResults.size() );
+
+  }
+  @Test
+  public void testGeo4() throws Exception {
+    LOG.info( "GeoIT.testGeo4" );
+    EntityManager em =  app.getEntityManager();
+    assertNotNull( em );
+
+    // create user at a location
+    Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+      put( "name", "norwest" );
+      put( "location", new LinkedHashMap<String, Object>() {{
+        put("latitude", -33.746369 );
+        put("longitude", 150.952183 );
+      }} );
+    }};
+    Entity entity = em.create( "store", properties );
+    assertNotNull( entity );
+    properties = new LinkedHashMap<String, Object>() {{
+      put( "name", "ashfield" );
+      put( "location", new LinkedHashMap<String, Object>() {{
+        put("latitude", -33.889058 );
+        put("longitude", 151.124024 );
+      }} );
+    }};
+    entity = em.create( "store", properties );
+    assertNotNull( entity );
+
+    em.refreshIndex();
+
+    List<Point> points = new ArrayList<Point>();
+    points.add(new Point( 33.746369,-89 ));//Woodland, MS
+    points.add(new Point( 33.746369,-91 ));//Beulah, MS
+    points.add(new Point( -1.000000, 102.000000 ));//Somewhere in Indonesia
+    points.add(new Point( -90.000000, 90.000000 ));//Antarctica
+    points.add(new Point( 90, 90 ));//Santa's house
+    //and the cartesian product...
+    for(int i= -90;i<=90;i++){
+      for(int j= -180;j<=180;j++){
+        points.add(new Point( i, j ));
+      }
     }
+    Iterator<Point> pointIterator = points.iterator();
+    for(Point p=pointIterator.next();pointIterator.hasNext();p=pointIterator.next()){
+      Query query = Query.fromQL( "select * where location within 10000 of "
+          + p.getLat() + "," + p.getLon());
+      Results listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
 
+      this.dump( listResults );
+      assertEquals("Results less than 10000m away from center", 0, listResults.size() );
 
-    @Test
+      query = Query.fromQL( "select * where location within 40000000 of "
+          + p.getLat() + "," + p.getLon());
+      listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
+
+      assertEquals("Results from center point to ridiculously far", 2, listResults.size() );
+
+    }
+
+
+  }
+  @Test
+  public void testGeoBadPoints() throws Exception {
+    LOG.info( "GeoIT.testGeoBadPoints" );
+    double[][] vertices= {
+        {-91.000000, 90.000000},
+        {91.000000, 90.000000},
+        {90.000000, 400},
+        {90.000000, -270.000000},
+        {-91.000000, -91.000000}
+    };
+    for (int i=0;i<vertices.length;i++){
+      //bad coordinate. bad! you're supposed to have lat between -90 and 90
+      try {
+        Point p = new Point(vertices[i][0], vertices[i][1]);
+        assertTrue("Bad points should throw an exception ["+vertices[i][0]+","+vertices[i][1]+"]", false);
+      }catch(java.lang.IllegalArgumentException e){
+        assertTrue("Bad points should throw an exception ["+vertices[i][0]+","+vertices[i][1]+"]" , true);
+      }
+    }
+
+
+
+  }
+
+
+  @Test
     public void testPointPaging() throws Exception {
 
 


[7/9] incubator-usergrid git commit: Merge remote-tracking branch 'origin/two-dot-o' into two-dot-o-events

Posted by sn...@apache.org.
Merge remote-tracking branch 'origin/two-dot-o' into two-dot-o-events

Conflicts:
	stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
	stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java


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

Branch: refs/heads/two-dot-o-events
Commit: ee260cc158c0df12198a0671d96e07a0089f17ca
Parents: 43105f1 74866a5
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Nov 24 09:28:17 2014 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Nov 24 09:28:17 2014 -0500

----------------------------------------------------------------------
 .../org/apache/usergrid/persistence/GeoIT.java  | 404 +++++++++++++------
 .../index/impl/EsEntityIndexBatchImpl.java      |  69 ++--
 .../index/impl/EsEntityIndexImpl.java           | 105 +++--
 .../persistence/index/impl/EsProvider.java      |  55 +--
 .../persistence/index/impl/EsQueryVistor.java   |   3 +-
 .../index/impl/FailureMonitorImpl.java          |   4 +-
 .../persistence/index/impl/IndexingUtils.java   |  51 +--
 .../index/query/CandidateResults.java           |   3 -
 .../persistence/index/query/EntityResults.java  |   4 +-
 .../persistence/index/query/Identifier.java     |   3 +-
 .../usergrid/persistence/index/query/Query.java |  26 +-
 .../apache/usergrid/rest/AbstractRestIT.java    |   5 +-
 .../collection/BrowserCompatibilityTest.java    |   2 +-
 .../collection/DuplicateNameIT.java             |   2 +-
 .../collection/activities/PutTest.java          |   2 +-
 .../collection/groups/GroupResourceIT.java      | 240 +++++++++--
 .../collection/paging/PagingEntitiesTest.java   |   4 +-
 .../collection/paging/PagingResourceIT.java     |  14 +-
 .../users/ConnectionResourceTest.java           |  16 +-
 .../collection/users/OwnershipResourceIT.java   |  18 +-
 .../collection/users/RetrieveUsersTest.java     |   4 +-
 .../applications/queries/AndOrQueryTest.java    |  13 +-
 .../queries/BadGrammarQueryTest.java            |   2 +-
 .../applications/queries/GeoPagingTest.java     | 222 +++++++++-
 .../applications/queries/MatrixQueryTests.java  |   2 +-
 .../rest/applications/queries/OrderByTest.java  |   6 +-
 .../usergrid/rest/test/resource/Connection.java |   9 +
 .../rest/test/resource/TestContext.java         |  66 ++-
 .../rest/test/resource/ValueResource.java       |   2 +
 .../rest/test/resource/app/Application.java     |  16 +-
 .../rest/test/resource/app/Collection.java      |  81 ++++
 .../usergrid/rest/test/resource/app/Group.java  |  56 +++
 .../test/resource/app/GroupsCollection.java     |  66 +++
 .../usergrid/rest/test/resource/app/Role.java   |  56 +++
 .../rest/test/resource/app/RolesCollection.java |  64 +++
 .../rest/test/resource/app/UsersCollection.java |  26 +-
 36 files changed, 1336 insertions(+), 385 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ee260cc1/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index e0ec1ed,4ce4d12..6e68791
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@@ -173,9 -179,10 +185,10 @@@ public class EsEntityIndexBatchImpl imp
          }
  
  
 -        log.debug( "De-indexing type {} with documentId '{}'" , entityType, indexId);
 +        log.debug( "De-indexing type {} with documentId '{}'", entityType, indexId );
  
-         bulkRequest.add( client.prepareDelete( indexName, entityType, indexId ).setRefresh( refresh ) );
+         bulkRequest.add( client.prepareDelete( 
+                 indexName, entityType, indexId ).setRefresh( refresh ) );
  
          log.debug( "Deindexed Entity with index id " + indexId );
  

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ee260cc1/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 406c967,22aa05c..53aaf54
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@@ -221,16 -214,16 +222,16 @@@ public class EsEntityIndexImpl implemen
       */
      private void createMappings() throws IOException {
  
-         XContentBuilder xcb =
-                 IndexingUtils.createDoubleStringIndexMapping( XContentFactory.jsonBuilder(), "_default_" );
+         XContentBuilder xcb = IndexingUtils.createDoubleStringIndexMapping( 
+                 XContentFactory.jsonBuilder(), "_default_" );
  
-         PutIndexTemplateResponse pitr =
-                 esProvider.getClient().admin().indices().preparePutTemplate( "usergrid_template" )
-                           .setTemplate( config.getIndexPrefix() + "*" ).addMapping( "_default_",
-                         xcb ) // set mapping as the default for all types
-                         .execute().actionGet();
+         PutIndexTemplateResponse pitr = esProvider.getClient().admin().indices()
+                 .preparePutTemplate( "usergrid_template" )
+                 // set mapping as the default for all types
+                 .setTemplate( config.getIndexPrefix() + "*" ).addMapping( "_default_", xcb ) 
+                 .execute().actionGet();
  
 -        if(!pitr.isAcknowledged()){
 +        if ( !pitr.isAcknowledged() ) {
              throw new IndexException( "Unable to create default mappings" );
          }
      }
@@@ -306,10 -300,10 +308,9 @@@
              }
  
  
 -
              if ( logger.isDebugEnabled() ) {
-                 logger.debug( "Searching index {}\n  scope{} \n type {}\n   query {} ", new Object[] {
-                         this.indexName, context, entityTypes, srb
-                 } );
+                 logger.debug( "Searching index {}\n  scope{} \n type {}\n   query {} ", 
+                         new Object[] { this.indexName, context, entityTypes, srb } );
              }
  
  

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ee260cc1/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
index ee5557c,6d34b15..4319ce4
--- 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
@@@ -158,11 -153,11 +155,11 @@@ public class IndexingUtils 
  
                      .startArray( "dynamic_templates" )
  
-                            //we need most specific mappings first since it's a stop on match algorithm
+                         // we need most specific mappings first since it's a stop on match algorithm
  
                          .startObject()
 -                        .startObject( "context_template" )
 -                            .field( "match", IndexingUtils.ENTITYID_ID_FIELDNAME )
 +                        .startObject( "entity_id_template" )
 +                            .field( "match", IndexingUtils.ENTITY_ID_FIELDNAME )
                                   .field( "match_mapping_type", "string" )
                                          .startObject( "mapping" ).field( "type", "string" )
                                               .field( "index", "not_analyzed" )
@@@ -170,47 -165,44 +167,53 @@@
                                   .endObject()
                               .endObject()
  
- 
                          .startObject()
 -                        .startObject( "context_template" )
 +                        .startObject( "entity_context_template" )
                              .field( "match", IndexingUtils.ENTITY_CONTEXT_FIELDNAME )
                              .field( "match_mapping_type", "string" )
-                                 .startObject( "mapping" ).field( "type", "string" )
+                                 .startObject( "mapping" )
+                                     .field( "type", "string" )
                                      .field( "index", "not_analyzed" ).endObject()
                                  .endObject()
                           .endObject()
  
 +                         .startObject()
 +                           .startObject( "entity_version_template" )
 +                               .field( "match", IndexingUtils.ENTITY_VERSION_FIELDNAME )
 +                                    .field( "match_mapping_type", "string" )
 +                                           .startObject( "mapping" ).field( "type", "long" )
 +                                           .endObject()
 +                                    .endObject()
 +                                .endObject()
 +
                          // any string with field name that starts with sa_ gets analyzed
                          .startObject()
-                             .startObject( "template_1" ).field( "match", ANALYZED_STRING_PREFIX + "*" )
-                             .field( "match_mapping_type", "string" ).startObject( "mapping" ).field( "type", "string" )
-                             .field( "index", "analyzed" ).endObject().endObject()
+                             .startObject( "template_1" )
+                                 .field( "match", ANALYZED_STRING_PREFIX + "*" )
+                                 .field( "match_mapping_type", "string" ).startObject( "mapping" )
+                                 .field( "type", "string" )
+                                 .field( "index", "analyzed" )
+                             .endObject()
                          .endObject()
+                     .endObject()
  
-                                 // all other strings are not analyzed
-                         .startObject()
-                             .startObject( "template_2" )
-                                     //todo, should be string prefix, remove 2 field mapping
-                                 .field( "match", "*" ).field( "match_mapping_type", "string" ).startObject( "mapping" )
+                     // all other strings are not analyzed
+                     .startObject()
+                         .startObject( "template_2" )
+                             //todo, should be string prefix, remove 2 field mapping
+                             .field( "match", "*" )
+                             .field( "match_mapping_type", "string" )
+                             .startObject( "mapping" )
                                  .field( "type", "string" )
                                      .field( "index", "not_analyzed" )
-                                 .endObject()
                              .endObject()
                          .endObject()
+                     .endObject()
  
-                         // fields names starting with go_ get geo-indexed
-                         .startObject()
-                             .startObject( "template_3" )
-                                 .field( "match", GEO_PREFIX + "location" )
+                     // fields names starting with go_ get geo-indexed
+                     .startObject()
+                         .startObject( "template_3" )
+                             .field( "match", GEO_PREFIX + "location" )
                                  .startObject( "mapping" )
                                      .field( "type", "geo_point" )
                                  .endObject()


[6/9] incubator-usergrid git commit: Import cleanup and minor formatting changes only.

Posted by sn...@apache.org.
Import cleanup and minor formatting changes only.


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

Branch: refs/heads/two-dot-o-events
Commit: 74866a566f1ec5b00a9f05412840988f597eb57d
Parents: d5616f6
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Nov 21 11:13:24 2014 +0100
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Nov 21 11:13:24 2014 +0100

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexBatchImpl.java      |  66 +++++++-----
 .../index/impl/EsEntityIndexImpl.java           | 105 +++++++++----------
 .../persistence/index/impl/EsProvider.java      |  55 +---------
 .../persistence/index/impl/EsQueryVistor.java   |   3 +-
 .../index/impl/FailureMonitorImpl.java          |   4 +-
 .../persistence/index/impl/IndexingUtils.java   |  51 ++++-----
 .../index/query/CandidateResults.java           |   3 -
 .../persistence/index/query/EntityResults.java  |   4 +-
 .../persistence/index/query/Identifier.java     |   3 +-
 .../usergrid/persistence/index/query/Query.java |  26 ++---
 .../rest/test/resource/app/Collection.java      |  20 +++-
 11 files changed, 159 insertions(+), 181 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/74866a56/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index c4cdeeb..4ce4d12 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@ -1,4 +1,4 @@
-package org.apache.usergrid.persistence.index.impl;/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -16,7 +16,7 @@ package org.apache.usergrid.persistence.index.impl;/*
  * specific language governing permissions and limitations
  * under the License.
  */
-
+package org.apache.usergrid.persistence.index.impl;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -92,8 +92,8 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
     private final FailureMonitor failureMonitor;
 
 
-    public EsEntityIndexBatchImpl( final ApplicationScope applicationScope, final Client client, final IndexFig config,
-                                   final int autoFlushSize, final FailureMonitor failureMonitor ) {
+    public EsEntityIndexBatchImpl( final ApplicationScope applicationScope, final Client client, 
+            final IndexFig config, final int autoFlushSize, final FailureMonitor failureMonitor ) {
 
         this.applicationScope = applicationScope;
         this.client = client;
@@ -116,9 +116,14 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
 
         if ( log.isDebugEnabled() ) {
             log.debug( "Indexing entity {}:{} in scope\n   app {}\n   "
-                    + "owner {}\n   name {}\n   type {} \n scope type {}", new Object[] {
-                    entity.getId().getType(), entity.getId().getUuid(), applicationScope.getApplication(),
-                    indexScope.getOwner(), indexScope.getName(), entityType, context
+                + "owner {}\n   name {}\n   type {} \n scope type {}", new Object[] {
+                    entity.getId().getType(), 
+                    entity.getId().getUuid(), 
+                    applicationScope.getApplication(),
+                    indexScope.getOwner(), 
+                    indexScope.getName(), 
+                    entityType, 
+                    context
             } );
         }
 
@@ -137,7 +142,8 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
 
         log.debug( "Indexing entity documentId {} data {} ", indexId, entityAsMap );
 
-        bulkRequest.add( client.prepareIndex( indexName, entityType, indexId ).setSource( entityAsMap ) );
+        bulkRequest.add( client.prepareIndex( 
+                indexName, entityType, indexId ).setSource( entityAsMap ) );
 
         maybeFlush();
 
@@ -146,7 +152,7 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
 
 
     @Override
-    public EntityIndexBatch deindex( final IndexScope indexScope, final Id id, final UUID version ) {
+    public EntityIndexBatch deindex( final IndexScope indexScope, final Id id, final UUID version) {
 
         IndexValidationUtils.validateIndexScope( indexScope );
         ValidationUtils.verifyIdentity( id );
@@ -159,17 +165,24 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
 
 
         if ( log.isDebugEnabled() ) {
-            log.debug( "De-indexing entity {}:{} in scope\n   app {}\n   owner {}\n   " + "name {} context{}, type {},",
-                    new Object[] {
-                            id.getType(), id.getUuid(), applicationScope.getApplication(), indexScope.getOwner(),
-                            indexScope.getName(), context, entityType
-                    } );
+            log.debug( "De-indexing entity {}:{} in scope\n   app {}\n   owner {}\n   " 
+                + "name {} context{}, type {},",
+                new Object[] {
+                    id.getType(), 
+                    id.getUuid(), 
+                    applicationScope.getApplication(), 
+                    indexScope.getOwner(),
+                    indexScope.getName(), 
+                    context, 
+                    entityType
+                } );
         }
 
 
         log.debug( "De-indexing type {} with documentId '{}'" , entityType, indexId);
 
-        bulkRequest.add( client.prepareDelete( indexName, entityType, indexId ).setRefresh( refresh ) );
+        bulkRequest.add( client.prepareDelete( 
+                indexName, entityType, indexId ).setRefresh( refresh ) );
 
         log.debug( "Deindexed Entity with index id " + indexId );
 
@@ -225,8 +238,8 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
 
         for ( BulkItemResponse response : responses ) {
             if ( response.isFailed() ) {
-                throw new RuntimeException(
-                        "Unable to index documents.  Errors are :" + response.getFailure().getMessage() );
+                throw new RuntimeException( "Unable to index documents.  Errors are :" 
+                        + response.getFailure().getMessage() );
             }
         }
 
@@ -262,9 +275,9 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
         //add the context for filtering later
         entityMap.put( ENTITY_CONTEXT_FIELDNAME, context );
 
-        //but the fieldname
-        //we have to prefix because we use query equality to seek this later.  TODO see if we can make this more declarative
-        entityMap.put( ENTITYID_ID_FIELDNAME, IndexingUtils.idString(entity.getId()).toLowerCase() );
+        //but the fieldname we have to prefix because we use query equality to seek this later.  
+        // TODO see if we can make this more declarative
+        entityMap.put( ENTITYID_ID_FIELDNAME, IndexingUtils.idString(entity.getId()).toLowerCase());
 
         return entityMap;
     }
@@ -289,7 +302,8 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
 
             if ( f instanceof ListField ) {
                 List list = ( List ) field.getValue();
-                entityMap.put( field.getName().toLowerCase(), new ArrayList( processCollectionForMap( list ) ) );
+                entityMap.put( field.getName().toLowerCase(), 
+                        new ArrayList( processCollectionForMap( list ) ) );
 
                 if ( !list.isEmpty() ) {
                     if ( list.get( 0 ) instanceof String ) {
@@ -302,11 +316,13 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
             }
             else if ( f instanceof ArrayField ) {
                 List list = ( List ) field.getValue();
-                entityMap.put( field.getName().toLowerCase(), new ArrayList( processCollectionForMap( list ) ) );
+                entityMap.put( field.getName().toLowerCase(), 
+                        new ArrayList( processCollectionForMap( list ) ) );
             }
             else if ( f instanceof SetField ) {
                 Set set = ( Set ) field.getValue();
-                entityMap.put( field.getName().toLowerCase(), new ArrayList( processCollectionForMap( set ) ) );
+                entityMap.put( field.getName().toLowerCase(), 
+                        new ArrayList( processCollectionForMap( set ) ) );
             }
             else if ( f instanceof EntityObjectField ) {
                 EntityObject eo = ( EntityObject ) field.getValue();
@@ -329,7 +345,9 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
                 locMap.put( "lon", locField.getValue().getLongitude() );
                 entityMap.put( GEO_PREFIX + field.getName().toLowerCase(), locMap );
             }
-            else if ( f instanceof DoubleField || f instanceof FloatField || f instanceof IntegerField
+            else if (  f instanceof DoubleField 
+                    || f instanceof FloatField 
+                    || f instanceof IntegerField
                     || f instanceof LongField ) {
 
                 entityMap.put( NUMBER_PREFIX + field.getName().toLowerCase(), field.getValue() );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/74866a56/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index b1e5374..22aa05c 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -74,7 +74,6 @@ import com.google.inject.Inject;
 import com.google.inject.assistedinject.Assisted;
 
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.BOOLEAN_PREFIX;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITYID_ID_FIELDNAME;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.NUMBER_PREFIX;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.SPLITTER;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.STRING_PREFIX;
@@ -146,12 +145,13 @@ public class EsEntityIndexImpl implements EntityIndex {
             final int numberOfShards = config.getNumberOfShards();
             final int numberOfReplicas = config.getNumberOfReplicas();
 
-            Settings settings = ImmutableSettings.settingsBuilder().put( "index.number_of_shards", numberOfShards )
-                                                 .put( "index.number_of_replicas", numberOfReplicas ).build();
+            Settings settings = ImmutableSettings.settingsBuilder()
+                    .put( "index.number_of_shards", numberOfShards )
+                    .put( "index.number_of_replicas", numberOfReplicas ).build();
 
 
-            final CreateIndexResponse cir =
-                    admin.indices().prepareCreate( indexName ).setSettings( settings ).execute().actionGet();
+            final CreateIndexResponse cir = admin.indices().prepareCreate( indexName )
+                    .setSettings( settings ).execute().actionGet();
 
             logger.info( "Created new Index Name [{}] ACK=[{}]", indexName, cir.isAcknowledged() );
 
@@ -186,17 +186,19 @@ public class EsEntityIndexImpl implements EntityIndex {
             public boolean doOp() {
                 final String tempId = UUIDGenerator.newTimeUUID().toString();
 
-                esProvider.getClient().prepareIndex( indexName, VERIFY_TYPE, tempId ).setSource( DEFAULT_PAYLOAD )
-                          .get();
+                esProvider.getClient().prepareIndex( indexName, VERIFY_TYPE, tempId )
+                        .setSource( DEFAULT_PAYLOAD ).get();
 
-                logger.info( "Successfully created new document with docId {} in index {} and type {}", tempId,
-                        indexName, VERIFY_TYPE );
+                logger.info( "Successfully created new document with docId {} in index {} type {}", 
+                        tempId, indexName, VERIFY_TYPE );
 
                 // delete all types, this way if we miss one it will get cleaned up
-                esProvider.getClient().prepareDeleteByQuery( indexName ).setTypes( VERIFY_TYPE )
-                          .setQuery( MATCH_ALL_QUERY_BUILDER ).get();
+                esProvider.getClient().prepareDeleteByQuery( indexName )
+                        .setTypes( VERIFY_TYPE )
+                        .setQuery( MATCH_ALL_QUERY_BUILDER ).get();
 
-                logger.info( "Successfully deleted all documents in index {} and type {}", indexName, VERIFY_TYPE );
+                logger.info( "Successfully deleted all documents in index {} and type {}", 
+                        indexName, VERIFY_TYPE );
 
                 return true;
             }
@@ -207,36 +209,36 @@ public class EsEntityIndexImpl implements EntityIndex {
 
 
     /**
-     * Setup ElasticSearch type mappings as a template that applies to all new indexes. Applies to all indexes that
-     * start with our prefix.
+     * Setup ElasticSearch type mappings as a template that applies to all new indexes. 
+     * Applies to all indexes that* start with our prefix.
      */
     private void createMappings() throws IOException {
 
-        XContentBuilder xcb =
-                IndexingUtils.createDoubleStringIndexMapping( XContentFactory.jsonBuilder(), "_default_" );
+        XContentBuilder xcb = IndexingUtils.createDoubleStringIndexMapping( 
+                XContentFactory.jsonBuilder(), "_default_" );
 
-        PutIndexTemplateResponse pitr =
-                esProvider.getClient().admin().indices().preparePutTemplate( "usergrid_template" )
-                          .setTemplate( config.getIndexPrefix() + "*" ).addMapping( "_default_",
-                        xcb ) // set mapping as the default for all types
-                        .execute().actionGet();
+        PutIndexTemplateResponse pitr = esProvider.getClient().admin().indices()
+                .preparePutTemplate( "usergrid_template" )
+                // set mapping as the default for all types
+                .setTemplate( config.getIndexPrefix() + "*" ).addMapping( "_default_", xcb ) 
+                .execute().actionGet();
 
         if(!pitr.isAcknowledged()){
             throw new IndexException( "Unable to create default mappings" );
         }
-
-
     }
 
 
     @Override
     public EntityIndexBatch createBatch() {
-        return new EsEntityIndexBatchImpl( applicationScope, esProvider.getClient(), config, 1000, failureMonitor );
+        return new EsEntityIndexBatchImpl( 
+                applicationScope, esProvider.getClient(), config, 1000, failureMonitor );
     }
 
 
     @Override
-    public CandidateResults search( final IndexScope indexScope, final SearchTypes searchTypes, final Query query ) {
+    public CandidateResults search( final IndexScope indexScope, final SearchTypes searchTypes, 
+            final Query query ) {
 
         final String context = IndexingUtils.createContextName( indexScope );
         final String[] entityTypes = searchTypes.getTypeNames();
@@ -247,14 +249,12 @@ public class EsEntityIndexImpl implements EntityIndex {
         SearchResponse searchResponse;
 
         if ( query.getCursor() == null ) {
-            SearchRequestBuilder srb = esProvider.getClient().prepareSearch( indexName ).setTypes( entityTypes )
-                                                 .setScroll( cursorTimeout + "m" ).setQuery( qb );
-
-
+            SearchRequestBuilder srb = esProvider.getClient().prepareSearch( indexName )
+                    .setTypes( entityTypes )
+                    .setScroll( cursorTimeout + "m" ).setQuery( qb );
 
             final FilterBuilder fb = query.createFilterBuilder();
 
-
             //we have post filters, apply them
             if ( fb != null ) {
                 logger.debug( "   Filter: {} ", fb.toString() );
@@ -280,21 +280,21 @@ public class EsEntityIndexImpl implements EntityIndex {
                 // to ignore any fields that are not present.
 
                 final String stringFieldName = STRING_PREFIX + sp.getPropertyName();
-                final FieldSortBuilder stringSort =
-                        SortBuilders.fieldSort( stringFieldName ).order( order ).ignoreUnmapped( true );
+                final FieldSortBuilder stringSort = SortBuilders.fieldSort( stringFieldName )
+                        .order( order ).ignoreUnmapped( true );
                 srb.addSort( stringSort );
 
                 logger.debug( "   Sort: {} order by {}", stringFieldName, order.toString() );
 
                 final String numberFieldName = NUMBER_PREFIX + sp.getPropertyName();
-                final FieldSortBuilder numberSort =
-                        SortBuilders.fieldSort( numberFieldName ).order( order ).ignoreUnmapped( true );
+                final FieldSortBuilder numberSort = SortBuilders.fieldSort( numberFieldName )
+                        .order( order ).ignoreUnmapped( true );
                 srb.addSort( numberSort );
                 logger.debug( "   Sort: {} order by {}", numberFieldName, order.toString() );
 
                 final String booleanFieldName = BOOLEAN_PREFIX + sp.getPropertyName();
-                final FieldSortBuilder booleanSort =
-                        SortBuilders.fieldSort( booleanFieldName ).order( order ).ignoreUnmapped( true );
+                final FieldSortBuilder booleanSort = SortBuilders.fieldSort( booleanFieldName )
+                        .order( order ).ignoreUnmapped( true );
                 srb.addSort( booleanSort );
                 logger.debug( "   Sort: {} order by {}", booleanFieldName, order.toString() );
             }
@@ -302,9 +302,8 @@ public class EsEntityIndexImpl implements EntityIndex {
 
 
             if ( logger.isDebugEnabled() ) {
-                logger.debug( "Searching index {}\n  scope{} \n type {}\n   query {} ", new Object[] {
-                        this.indexName, context, entityTypes, srb
-                } );
+                logger.debug( "Searching index {}\n  scope{} \n type {}\n   query {} ", 
+                        new Object[] { this.indexName, context, entityTypes, srb } );
             }
 
 
@@ -330,8 +329,8 @@ public class EsEntityIndexImpl implements EntityIndex {
             }
             logger.debug( "Executing query with cursor: {} ", scrollId );
 
-            SearchScrollRequestBuilder ssrb =
-                    esProvider.getClient().prepareSearchScroll( scrollId ).setScroll( cursorTimeout + "m" );
+            SearchScrollRequestBuilder ssrb = esProvider.getClient()
+                    .prepareSearchScroll( scrollId ).setScroll( cursorTimeout + "m" );
 
             try {
                 searchResponse = ssrb.execute().actionGet();
@@ -392,7 +391,8 @@ public class EsEntityIndexImpl implements EntityIndex {
             @Override
             public boolean doOp() {
                 try {
-                    esProvider.getClient().admin().indices().prepareRefresh( indexName ).execute().actionGet();
+                    esProvider.getClient().admin().indices().prepareRefresh( indexName )
+                            .execute().actionGet();
                     logger.debug( "Refreshed index: " + indexName );
                     return true;
                 }
@@ -412,7 +412,8 @@ public class EsEntityIndexImpl implements EntityIndex {
     @Override
     public int getPendingTasks() {
 
-        final PendingClusterTasksResponse tasksResponse = esProvider.getClient().admin().cluster().pendingClusterTasks( new PendingClusterTasksRequest() ).actionGet();
+        final PendingClusterTasksResponse tasksResponse = esProvider.getClient().admin()
+                .cluster().pendingClusterTasks( new PendingClusterTasksRequest() ).actionGet();
 
         return tasksResponse.pendingTasks().size();
     }
@@ -426,13 +427,12 @@ public class EsEntityIndexImpl implements EntityIndex {
         final String context = IndexingUtils.createContextName( scope );
         final SearchTypes searchTypes = SearchTypes.fromTypes( id.getType() );
 
-        final QueryBuilder queryBuilder = QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context );
-
-
-        final SearchRequestBuilder srb =
-                esProvider.getClient().prepareSearch( indexName ).setTypes( searchTypes.getTypeNames() )
-                          .setScroll( cursorTimeout + "m" ).setQuery( queryBuilder );
+        final QueryBuilder queryBuilder = QueryBuilders.termQuery( 
+                IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context );
 
+        final SearchRequestBuilder srb = esProvider.getClient().prepareSearch( indexName )
+                .setTypes( searchTypes.getTypeNames() ).setScroll( cursorTimeout + "m" )
+                .setQuery( queryBuilder );
 
         final SearchResponse searchResponse;
         try {
@@ -499,8 +499,8 @@ public class EsEntityIndexImpl implements EntityIndex {
     public Health getClusterHealth() {
 
         try {
-            ClusterHealthResponse chr =
-                    esProvider.getClient().admin().cluster().health( new ClusterHealthRequest() ).get();
+            ClusterHealthResponse chr = esProvider.getClient().admin()
+                    .cluster().health( new ClusterHealthRequest() ).get();
             return Health.valueOf( chr.getStatus().name() );
         }
         catch ( Exception ex ) {
@@ -520,8 +520,7 @@ public class EsEntityIndexImpl implements EntityIndex {
 
         try {
             ClusterHealthResponse chr = esProvider.getClient().admin().cluster()
-                                                  .health( new ClusterHealthRequest( new String[] { indexName } ) )
-                                                  .get();
+                    .health( new ClusterHealthRequest( new String[] { indexName } ) ).get();
             return Health.valueOf( chr.getStatus().name() );
         }
         catch ( Exception ex ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/74866a56/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
index ea63ffc..2ea6774 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
@@ -25,10 +25,7 @@ import java.net.UnknownHostException;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.client.transport.TransportClient;
 import org.elasticsearch.common.settings.ImmutableSettings;
-import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.transport.InetSocketTransportAddress;
-import org.elasticsearch.node.Node;
-import org.elasticsearch.node.NodeBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,11 +47,9 @@ public class EsProvider {
 
     private final IndexFig indexFig;
     private static Client client;
-//    private static Node node;
 
     public static String LOCAL_ES_PORT_PROPNAME = "EMBEDDED_ES_PORT";
 
-
     @Inject
     public EsProvider( IndexFig fig ) {
         this.indexFig = fig;
@@ -86,28 +81,17 @@ public class EsProvider {
 
     private synchronized void createClient( IndexFig fig ) {
 
-
         if ( client != null) {
             return;
         }
 
-
-
         final String clusterName = fig.getClusterName();
         final int port = fig.getPort();
 
-
         ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder()
                  .put( "cluster.name", clusterName )
                  .put( "client.transport.sniff", true );
 
-
-
-//        String allHosts = "";
-
-
-
-
         String nodeName = fig.getNodeName();
 
         if ( "default".equals( nodeName ) ) {
@@ -123,49 +107,12 @@ public class EsProvider {
 
         settings.put( "node.name", nodeName);
 
-
-
         TransportClient transportClient = new TransportClient( settings.build() );
+
             // we will connect to ES on all configured hosts
-//            String SEP = "";
             for ( String host : fig.getHosts().split( "," ) ) {
-
                 transportClient.addTransportAddress( new InetSocketTransportAddress(host, port));
-
-//                allHosts = allHosts + SEP + host + ":" + fig.getPort();
-//                SEP = ",";
             }
-
-//        Settings settings = ImmutableSettings.settingsBuilder()
-//
-//                .put( "cluster.name", fig.getClusterName() )
-//
-//                        // this assumes that we're using zen for host discovery.  Putting an
-//                        // explicit set of bootstrap hosts ensures we connect to a valid cluster.
-//                .put( "discovery.zen.ping.unicast.hosts", allHosts )
-//                .put( "discovery.zen.ping.multicast.enabled", "false" ).put( "http.enabled", false )
-//                .put("transport.tcp.port", "9300-9400")
-//                .put( "client.transport.ping_timeout", 2000 ) // milliseconds
-//                .put( "client.transport.nodes_sampler_interval", 100 )
-////                .put( "network.tcp.blocking", true )
-//                .put( "node.client", true ).put( "node.name", nodeName+"Random test" )
-//
-//                .build();
-
-//        log.debug( "Creating ElasticSearch client with settings: " + settings.getAsMap() );
-//
-//        // use this client when connecting via socket only,
-//        // such as ssh tunnel or other firewall issues
-//        // newClient  = new TransportClient(settings).addTransportAddress(
-//        //                  new InetSocketTransportAddress("localhost", 9300) );
-//
-//        //use this client for quick connectivity
-//        node = NodeBuilder.nodeBuilder().settings( settings ).client( true ).node();
-//        client = node.client();
-
-
-
-//                .build();
        client =  transportClient;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/74866a56/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 0e4b0ad..f012bab 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
@@ -222,7 +222,8 @@ public class EsQueryVistor implements QueryVisitor {
             qb.minimumNumberShouldMatch(1);
 
             // field is an entity/array that does not need a prefix on its name
-            //TODO is this right now that we've updated our doc structure?  Should this be "must" instead of should?
+            // TODO is this right now that we've updated our doc structure?  
+            // Should this be "must" instead of should?
             qb = qb.should( QueryBuilders.wildcardQuery( name, svalue ) );
            
             // or field is just a string that does need a prefix

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/74866a56/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/FailureMonitorImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/FailureMonitorImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/FailureMonitorImpl.java
index eb17fac..fed9a50 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/FailureMonitorImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/FailureMonitorImpl.java
@@ -75,8 +75,8 @@ public class FailureMonitorImpl implements FailureMonitor {
 
         if ( fails > maxCount ) {
             LOG.error( "Unable to connect to elasticsearch.  Reason is {}", message, throwable );
-            LOG.warn( "We have failed to connect to Elastic Search {} times.  Max allowed is {}.  Resetting connection",
-                    fails, maxCount );
+            LOG.warn( "We have failed to connect to Elastic Search {} times.  "
+                    + "Max allowed is {}.  Resetting connection", fails, maxCount );
 
             esProvider.releaseClient();
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/74866a56/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 c7592bc..6d34b15 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
@@ -30,15 +30,12 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
 
 public class IndexingUtils {
 
-
     public static final String STRING_PREFIX = "su_";
     public static final String ANALYZED_STRING_PREFIX = "sa_";
     public static final String GEO_PREFIX = "go_";
     public static final String NUMBER_PREFIX = "nu_";
     public static final String BOOLEAN_PREFIX = "bu_";
 
-
-
     public static final String SPLITTER = "\\__";
 
     // These are not allowed in document type names: _ . , | #
@@ -156,7 +153,7 @@ public class IndexingUtils {
 
                     .startArray( "dynamic_templates" )
 
-                           //we need most specific mappings first since it's a stop on match algorithm
+                        // we need most specific mappings first since it's a stop on match algorithm
 
                         .startObject()
                         .startObject( "context_template" )
@@ -168,51 +165,55 @@ public class IndexingUtils {
                                  .endObject()
                              .endObject()
 
-
                         .startObject()
                         .startObject( "context_template" )
                             .field( "match", IndexingUtils.ENTITY_CONTEXT_FIELDNAME )
                             .field( "match_mapping_type", "string" )
-                                .startObject( "mapping" ).field( "type", "string" )
+                                .startObject( "mapping" )
+                                    .field( "type", "string" )
                                     .field( "index", "not_analyzed" ).endObject()
                                 .endObject()
                          .endObject()
 
                         // any string with field name that starts with sa_ gets analyzed
                         .startObject()
-                            .startObject( "template_1" ).field( "match", ANALYZED_STRING_PREFIX + "*" )
-                            .field( "match_mapping_type", "string" ).startObject( "mapping" ).field( "type", "string" )
-                            .field( "index", "analyzed" ).endObject().endObject()
+                            .startObject( "template_1" )
+                                .field( "match", ANALYZED_STRING_PREFIX + "*" )
+                                .field( "match_mapping_type", "string" ).startObject( "mapping" )
+                                .field( "type", "string" )
+                                .field( "index", "analyzed" )
+                            .endObject()
                         .endObject()
+                    .endObject()
 
-                                // all other strings are not analyzed
-                        .startObject()
-                            .startObject( "template_2" )
-                                    //todo, should be string prefix, remove 2 field mapping
-                                .field( "match", "*" ).field( "match_mapping_type", "string" ).startObject( "mapping" )
+                    // all other strings are not analyzed
+                    .startObject()
+                        .startObject( "template_2" )
+                            //todo, should be string prefix, remove 2 field mapping
+                            .field( "match", "*" )
+                            .field( "match_mapping_type", "string" )
+                            .startObject( "mapping" )
                                 .field( "type", "string" )
                                     .field( "index", "not_analyzed" )
-                                .endObject()
                             .endObject()
                         .endObject()
+                    .endObject()
 
-                        // fields names starting with go_ get geo-indexed
-                        .startObject()
-                            .startObject( "template_3" )
-                                .field( "match", GEO_PREFIX + "location" )
+                    // fields names starting with go_ get geo-indexed
+                    .startObject()
+                        .startObject( "template_3" )
+                            .field( "match", GEO_PREFIX + "location" )
                                 .startObject( "mapping" )
                                     .field( "type", "geo_point" )
                                 .endObject()
-                            .endObject()
                         .endObject()
+                    .endObject()
 
+                .endArray()
 
+            .endObject()
 
-                    .endArray()
-
-                .endObject()
-
-            .endObject();
+        .endObject();
 
         return builder;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/74866a56/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResults.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResults.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResults.java
index a71bcbe..be90446 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResults.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResults.java
@@ -19,9 +19,6 @@ package org.apache.usergrid.persistence.index.query;
 
 import java.util.Iterator;
 import java.util.List;
-
-
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/74866a56/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java
index b2aef93..59f20dd 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java
@@ -29,8 +29,8 @@ import org.apache.usergrid.persistence.model.entity.Entity;
 
 
 /**
- * Loads results from candidate results.  This needs to be refactored to the calling module, and should not exist in the
- * query index
+ * Loads results from candidate results.  This needs to be refactored to the calling module, 
+ * and should not exist in the query index
  */
 public class EntityResults implements Iterable<Entity>, Iterator<Entity> {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/74866a56/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Identifier.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Identifier.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Identifier.java
index 66dcd3b..9313c03 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Identifier.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Identifier.java
@@ -31,7 +31,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
 
 public class Identifier implements Serializable {
 
-    public static final String UUID_REX = "[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}";
+    public static final String UUID_REX = 
+            "[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}";
     public static final String EMAIL_REX =  "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}";
 
     public enum Type {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/74866a56/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
index a057b02..414061d 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
@@ -151,8 +151,9 @@ public class Query {
 
         //we have a root operand.  Translate our AST into an ES search
         if ( getRootOperand() != null ) {
-            //In the case of geo only queries, this will return null into the query builder.  Once we start
-            //using tiles, we won't need this check any longer, since a geo query will return a tile query + post filter
+            // In the case of geo only queries, this will return null into the query builder.  
+            // Once we start using tiles, we won't need this check any longer, since a geo query 
+            // will return a tile query + post filter
             QueryVisitor v = new EsQueryVistor();
 
             try {
@@ -167,14 +168,12 @@ public class Query {
         }
 
 
-        /**
-         * Add our filter for context to our query for fast execution.  Fast because it utilizes bitsets
-         * internally. See this post for more detail.
-         * http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/
-         */
+         // Add our filter for context to our query for fast execution.  
+         // Fast because it utilizes bitsets internally. See this post for more detail.
+         // http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/
 
-
-        // TODO evaluate performance when it's an all query.  Do we need to put the context term first for performance?
+        // TODO evaluate performance when it's an all query.  
+        // Do we need to put the context term first for performance?
         if ( queryBuilder != null ) {
             queryBuilder = QueryBuilders.boolQuery().must( queryBuilder ).must( QueryBuilders
                     .termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context ) );
@@ -906,11 +905,12 @@ public class Query {
 
     public void setLimit( int limit ) {
 
-        //      TODO tnine.  After users have had time to change their query limits,
+        // TODO tnine.  After users have had time to change their query limits,
         // this needs to be uncommented and enforced.
-        //        if(limit > MAX_LIMIT){
-        //          throw new IllegalArgumentException(String.format("Query limit must be <= to %d", MAX_LIMIT));
-        //        }
+        //    if(limit > MAX_LIMIT){
+        //        throw new IllegalArgumentException(
+        //            String.format("Query limit must be <= to %d", MAX_LIMIT));
+        //    }
 
         if ( limit > MAX_LIMIT ) {
             limit = MAX_LIMIT;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/74866a56/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
index ac65a01..9101464 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
@@ -1,10 +1,24 @@
-package org.apache.usergrid.rest.test.resource.app;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
+package org.apache.usergrid.rest.test.resource.app;
 
 import java.io.IOException;
 import java.util.Map;
-import java.util.UUID;
-
 import org.apache.usergrid.rest.test.resource.NamedResource;
 import org.apache.usergrid.rest.test.resource.SetResource;
 import org.apache.usergrid.utils.MapUtils;


[9/9] incubator-usergrid git commit: Fix merge issue.

Posted by sn...@apache.org.
Fix merge issue.


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

Branch: refs/heads/two-dot-o-events
Commit: 32276938d6a4ea986a15fa7bc7c2970a2a83ce41
Parents: c69f0ec
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Nov 24 09:40:22 2014 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Nov 24 09:40:22 2014 -0500

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexImpl.java           |  17 ++-
 .../persistence/index/impl/IndexingUtils.java   | 115 ++++++++++---------
 2 files changed, 67 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/32276938/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 53aaf54..aa797e2 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -51,7 +51,6 @@ import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.index.query.TermQueryBuilder;
 import org.elasticsearch.indices.IndexAlreadyExistsException;
 import org.elasticsearch.indices.IndexMissingException;
-import org.elasticsearch.rest.RestStatus;
 import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.SearchHits;
 import org.elasticsearch.search.sort.FieldSortBuilder;
@@ -72,7 +71,6 @@ import org.apache.usergrid.persistence.index.exceptions.IndexException;
 import org.apache.usergrid.persistence.index.query.CandidateResult;
 import org.apache.usergrid.persistence.index.query.CandidateResults;
 import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
@@ -82,6 +80,7 @@ import com.google.inject.Inject;
 import com.google.inject.assistedinject.Assisted;
 
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.BOOLEAN_PREFIX;
+import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITYID_ID_FIELDNAME;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.NUMBER_PREFIX;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.SPLITTER;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.STRING_PREFIX;
@@ -462,8 +461,7 @@ public class EsEntityIndexImpl implements EntityIndex {
     public void deleteAllVersionsOfEntity( Id entityId ) {
 
         final TermQueryBuilder tqb =
-                QueryBuilders.termQuery( ENTITY_ID_FIELDNAME, entityId.getUuid().toString().toLowerCase() );
-
+                QueryBuilders.termQuery( ENTITYID_ID_FIELDNAME, entityId.getUuid().toString().toLowerCase() );
 
         final DeleteByQueryResponse response =
                 esProvider.getClient().prepareDeleteByQuery( indexName ).setQuery( tqb ).execute().actionGet();
@@ -481,9 +479,8 @@ public class EsEntityIndexImpl implements EntityIndex {
     public void deletePreviousVersions( final Id id, final UUID version ) {
 
         final FilteredQueryBuilder fqb = QueryBuilders.filteredQuery(
-                QueryBuilders.termQuery( ENTITY_ID_FIELDNAME, id.getUuid().toString().toLowerCase() ),
-
-                FilterBuilders.rangeFilter( ENTITY_VERSION_FIELDNAME ).lt( version.timestamp() ) );
+            QueryBuilders.termQuery( IndexingUtils.ENTITYID_ID_FIELDNAME, id.getUuid().toString().toLowerCase() ),
+            FilterBuilders.rangeFilter( IndexingUtils.ENTITY_VERSION_FIELDNAME ).lt( version.timestamp() ) );
 
         final DeleteByQueryResponse response =
                 esProvider.getClient().prepareDeleteByQuery( indexName ).setQuery( fqb ).execute().actionGet();
@@ -507,9 +504,9 @@ public class EsEntityIndexImpl implements EntityIndex {
 
             for ( ShardOperationFailedException failedException : failures ) {
                 throw new IndexException( String.format(
-                        "Unable to delete by query %s.  Failed with code %d and reason %s on shard %s in index %s",
-                        query.toString(), failedException.status(), failedException.reason(), failedException.shardId(),
-                        failedException.index() ) );
+                    "Unable to delete by query %s.  Failed with code %d and reason %s on shard %s in index %s",
+                    query.toString(), failedException.status(), failedException.reason(), failedException.shardId(),
+                    failedException.index() ) );
             }
 
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/32276938/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 30b05e4..b26ca62 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
@@ -41,14 +41,17 @@ public class IndexingUtils {
     // These are not allowed in document type names: _ . , | #
     public static final String SEPARATOR = "__";
 
-    /**
-     * Reserved UG fields.
-     */
+    
+    //
+    // Reserved UG fields.
+    //
 
     public static final String ENTITY_CONTEXT_FIELDNAME = "ug_context";
 
     public static final String ENTITYID_ID_FIELDNAME = "ug_entityId";
 
+    public static final String ENTITY_VERSION_FIELDNAME = "ug_entityVersion";
+
 
     /**
       * Create our sub scope.  This is the ownerUUID + type
@@ -155,73 +158,75 @@ public class IndexingUtils {
                         // we need most specific mappings first since it's a stop on match algorithm
 
                         .startObject()
-                        .startObject( "entity_id_template" )
-                            .field( "match", IndexingUtils.ENTITY_ID_FIELDNAME )
-                                 .field( "match_mapping_type", "string" )
-                                        .startObject( "mapping" ).field( "type", "string" )
-                                             .field( "index", "not_analyzed" )
-                                        .endObject()
-                                 .endObject()
-                             .endObject()
-
-                        .startObject()
-                        .startObject( "entity_context_template" )
-                            .field( "match", IndexingUtils.ENTITY_CONTEXT_FIELDNAME )
-                            .field( "match_mapping_type", "string" )
-                                .startObject( "mapping" )
-                                    .field( "type", "string" )
-                                    .field( "index", "not_analyzed" ).endObject()
-                                .endObject()
-                         .endObject()
 
-                         .startObject()
-                           .startObject( "entity_version_template" )
-                               .field( "match", IndexingUtils.ENTITY_VERSION_FIELDNAME )
+                            .startObject( "entity_id_template" )
+                                .field( "match", IndexingUtils.ENTITYID_ID_FIELDNAME )
                                     .field( "match_mapping_type", "string" )
-                                           .startObject( "mapping" ).field( "type", "long" )
-                                           .endObject()
+                                            .startObject( "mapping" ).field( "type", "string" )
+                                                .field( "index", "not_analyzed" )
+                                            .endObject()
                                     .endObject()
                                 .endObject()
 
-                        // any string with field name that starts with sa_ gets analyzed
-                        .startObject()
-                            .startObject( "template_1" )
-                                .field( "match", ANALYZED_STRING_PREFIX + "*" )
-                                .field( "match_mapping_type", "string" ).startObject( "mapping" )
-                                .field( "type", "string" )
-                                .field( "index", "analyzed" )
+                            .startObject()
+                            .startObject( "entity_context_template" )
+                                .field( "match", IndexingUtils.ENTITY_CONTEXT_FIELDNAME )
+                                .field( "match_mapping_type", "string" )
+                                    .startObject( "mapping" )
+                                        .field( "type", "string" )
+                                        .field( "index", "not_analyzed" ).endObject()
+                                    .endObject()
                             .endObject()
-                        .endObject()
-                    .endObject()
-
-                    // all other strings are not analyzed
-                    .startObject()
-                        .startObject( "template_2" )
-                            //todo, should be string prefix, remove 2 field mapping
-                            .field( "match", "*" )
-                            .field( "match_mapping_type", "string" )
-                            .startObject( "mapping" )
-                                .field( "type", "string" )
-                                    .field( "index", "not_analyzed" )
+
+                            .startObject()
+                            .startObject( "entity_version_template" )
+                                .field( "match", IndexingUtils.ENTITY_VERSION_FIELDNAME )
+                                        .field( "match_mapping_type", "string" )
+                                            .startObject( "mapping" ).field( "type", "long" )
+                                            .endObject()
+                                        .endObject()
+                                    .endObject()
+
+                            // any string with field name that starts with sa_ gets analyzed
+                            .startObject()
+                                .startObject( "template_1" )
+                                    .field( "match", ANALYZED_STRING_PREFIX + "*" )
+                                    .field( "match_mapping_type", "string" ).startObject( "mapping" )
+                                    .field( "type", "string" )
+                                    .field( "index", "analyzed" )
+                                .endObject()
                             .endObject()
+
                         .endObject()
-                    .endObject()
 
-                    // fields names starting with go_ get geo-indexed
-                    .startObject()
-                        .startObject( "template_3" )
-                            .field( "match", GEO_PREFIX + "location" )
+                        // all other strings are not analyzed
+                        .startObject()
+                            .startObject( "template_2" )
+                                //todo, should be string prefix, remove 2 field mapping
+                                .field( "match", "*" )
+                                .field( "match_mapping_type", "string" )
                                 .startObject( "mapping" )
-                                    .field( "type", "geo_point" )
+                                    .field( "type", "string" )
+                                        .field( "index", "not_analyzed" )
                                 .endObject()
+                            .endObject()
+                        .endObject()
+
+                        // fields names starting with go_ get geo-indexed
+                        .startObject()
+                            .startObject( "template_3" )
+                                .field( "match", GEO_PREFIX + "location" )
+                                    .startObject( "mapping" )
+                                        .field( "type", "geo_point" )
+                                    .endObject()
+                            .endObject()
                         .endObject()
-                    .endObject()
 
-                .endArray()
+                    .endArray()
 
-            .endObject()
+                .endObject()
 
-        .endObject();
+            .endObject();
 
         return builder;
     }


[2/9] incubator-usergrid git commit: Added collection level entity creation. Added todos for places that need attention. Added distinction between CustomCollections and Collections ( created collections as a way to keep track of rest level calls ) Fixed

Posted by sn...@apache.org.
Added collection level entity creation.
Added todos for places that need attention.
Added distinction between CustomCollections and Collections ( created collections as a way to keep track of rest level calls )
Fixed tests that used CustomCollections so that they make the distinction.
Changed applications so that they also use Collections.
Changed UsersCollections so that it uses rest level calls and extends the base Collection class.


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

Branch: refs/heads/two-dot-o-events
Commit: 968352de5faaa027c1978a65b74526a94489ad2a
Parents: 7d5697b
Author: grey <gr...@apigee.com>
Authored: Thu Nov 20 14:01:29 2014 -0800
Committer: grey <gr...@apigee.com>
Committed: Thu Nov 20 14:01:29 2014 -0800

----------------------------------------------------------------------
 .../apache/usergrid/rest/AbstractRestIT.java    |  3 +-
 .../collection/BrowserCompatibilityTest.java    |  2 +-
 .../collection/DuplicateNameIT.java             |  2 +-
 .../collection/activities/PutTest.java          |  2 +-
 .../collection/paging/PagingEntitiesTest.java   |  4 +-
 .../collection/paging/PagingResourceIT.java     | 14 ++--
 .../users/ConnectionResourceTest.java           | 16 ++--
 .../collection/users/OwnershipResourceIT.java   | 18 ++---
 .../collection/users/RetrieveUsersTest.java     |  4 +-
 .../applications/queries/AndOrQueryTest.java    | 13 ++--
 .../queries/BadGrammarQueryTest.java            |  2 +-
 .../applications/queries/GeoPagingTest.java     | 81 ++++++++++++++++++--
 .../applications/queries/MatrixQueryTests.java  |  2 +-
 .../rest/applications/queries/OrderByTest.java  |  6 +-
 .../rest/test/resource/TestContext.java         | 15 +++-
 .../rest/test/resource/ValueResource.java       |  1 +
 .../rest/test/resource/app/Application.java     |  8 +-
 .../rest/test/resource/app/Collection.java      | 47 ++++++++++++
 .../rest/test/resource/app/UsersCollection.java | 14 +++-
 19 files changed, 199 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
index 60944af..4665bc6 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
@@ -430,7 +430,8 @@ public abstract class AbstractRestIT extends JerseyTest {
         LOG.debug("Refreshed index for appId {}", appId );
     }
 
-
+    //TODO: move refresh index into context so that we automatically refresh the indexs without needing to call
+    //different values of context.
     public void refreshIndex( String orgName, String appName ) {
 
         LOG.debug("Refreshing index for app {}/{}", orgName, appName );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BrowserCompatibilityTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BrowserCompatibilityTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BrowserCompatibilityTest.java
index fe12766..3bca666 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BrowserCompatibilityTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BrowserCompatibilityTest.java
@@ -66,7 +66,7 @@ public class BrowserCompatibilityTest extends AbstractRestIT {
     private void testBrowserAccept( String acceptHeader ) throws IOException {
 
 
-        CustomCollection things = context.application().collection( "things" );
+        CustomCollection things = context.application().customCollection( "things" );
 
         Map<String, String> entity = hashMap( "name", "thing1" );
         JsonNode response = things.create( entity );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/DuplicateNameIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/DuplicateNameIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/DuplicateNameIT.java
index 0273f04..39344d0 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/DuplicateNameIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/DuplicateNameIT.java
@@ -43,7 +43,7 @@ public class DuplicateNameIT extends AbstractRestIT {
     @Test
     public void duplicateNamePrevention() {
 
-        CustomCollection things = context.application().collection( "things" );
+        CustomCollection things = context.application().customCollection( "things" );
 
         Map<String, String> entity = MapUtils.hashMap( "name", "enzo" );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/PutTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/PutTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/PutTest.java
index 3d6dac9..850bd0e 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/PutTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/PutTest.java
@@ -44,7 +44,7 @@ public class PutTest extends AbstractRestIT {
     @Test //USERGRID-545
     public void putMassUpdateTest() throws IOException {
 
-        CustomCollection activities = context.collection( "activities" );
+        CustomCollection activities = context.customCollection( "activities" );
 
         Map actor = hashMap( "displayName", "Erin" );
         Map newActor = hashMap( "displayName", "Bob" );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingEntitiesTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingEntitiesTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingEntitiesTest.java
index 93a061d..dcd4188 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingEntitiesTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingEntitiesTest.java
@@ -49,7 +49,7 @@ public class PagingEntitiesTest extends AbstractRestIT {
     @Test //USERGRID-266
     public void pageThroughConnectedEntities() throws IOException {
 
-        CustomCollection activities = context.collection( "activities" );
+        CustomCollection activities = context.customCollection( "activities" );
 
         long created = 0;
         int maxSize = 100;
@@ -96,7 +96,7 @@ public class PagingEntitiesTest extends AbstractRestIT {
     @Test //USERGRID-1253
     public void pagingQueryReturnCorrectResults() throws Exception {
 
-        CustomCollection activities = context.collection( "activities" );
+        CustomCollection activities = context.customCollection( "activities" );
 
         long created = 0;
         int maxSize = 23;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingResourceIT.java
index e60a657..50f5f58 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/paging/PagingResourceIT.java
@@ -19,7 +19,7 @@ package org.apache.usergrid.rest.applications.collection.paging;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
+
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -66,7 +66,7 @@ public class PagingResourceIT extends AbstractRestIT {
     @Test
     public void collectionPaging() throws Exception {
 
-        CustomCollection things = context.application().collection( "test1things" );
+        CustomCollection things = context.application().customCollection( "test1things" );
 
         int size = 40;
 
@@ -111,7 +111,7 @@ public class PagingResourceIT extends AbstractRestIT {
             + "see also: https://issues.apache.org/jira/browse/USERGRID-211 ")
     public void startPaging() throws Exception {
 
-        CustomCollection things = context.application().collection( "test2things" );
+        CustomCollection things = context.application().customCollection( "test2things" );
 
         int size = 40;
 
@@ -159,7 +159,7 @@ public class PagingResourceIT extends AbstractRestIT {
     @Test
     public void collectionBatchDeleting() throws Exception {
 
-        CustomCollection things = context.application().collection( "test3things" );
+        CustomCollection things = context.application().customCollection( "test3things" );
 
         int size = 40;
 
@@ -202,7 +202,7 @@ public class PagingResourceIT extends AbstractRestIT {
     @Test
     public void emptyQlandLimitIgnored() throws Exception {
 
-        CustomCollection things = context.application().collection( "test4things" );
+        CustomCollection things = context.application().customCollection( "test4things" );
 
         Map<String, String> data = hashMap( "name", "thing1" );
         JsonNode response = things.create( data );
@@ -245,7 +245,7 @@ public class PagingResourceIT extends AbstractRestIT {
         // test that we do get cursor when we need one
         // create 50 widgets
         int widgetsSize = 50;
-        CustomCollection widgets = context.application().collection("widgets");
+        CustomCollection widgets = context.application().customCollection( "widgets" );
         for (int i = 0; i < widgetsSize; i++) {
             Map<String, String> entity = hashMap("name", String.valueOf(i));
             widgets.create(entity);
@@ -264,7 +264,7 @@ public class PagingResourceIT extends AbstractRestIT {
         // test that we DO NOT get cursor when we should not get cursor
         // create 5 trinkets
         int trinketsSize = 5;
-        CustomCollection trinkets = context.application().collection("trinkets");
+        CustomCollection trinkets = context.application().customCollection( "trinkets" );
         for (int i = 0; i < trinketsSize; i++) {
             Map<String, String> entity = hashMap("name", String.valueOf(i));
             trinkets.create(entity);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
index e034443..21b30d3 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
@@ -55,7 +55,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
     public void connectionsQueryTest() throws IOException {
 
 
-        CustomCollection activities = context.collection( "peeps" );
+        CustomCollection activities = context.customCollection( "peeps" );
 
         Map stuff = hashMap( "type", "chicken" );
 
@@ -113,7 +113,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
     @Test
     public void connectionsLoopbackTest() throws IOException {
 
-        CustomCollection things = context.collection( "things" );
+        CustomCollection things = context.customCollection( "things" );
 
         UUID thing1Id = getEntityId( things.create( hashMap( "name", "thing1" ) ), 0 );
 
@@ -143,7 +143,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
 
         //now that we know the URl is correct, follow it
 
-        response = context.collection( url ).get();
+        response = context.customCollection( url ).get();
 
         UUID returnedUUID = getEntityId( response, 0 );
 
@@ -161,7 +161,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
 
         //now we should get thing1 from the loopback url
 
-        response = context.collection( url ).get();
+        response = context.customCollection( url ).get();
 
         UUID returned = getEntityId( response, 0 );
 
@@ -172,7 +172,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
     @Test
     public void connectionsUUIDTest() throws IOException {
 
-        CustomCollection things = context.collection( "things" );
+        CustomCollection things = context.customCollection( "things" );
 
         UUID thing1Id = getEntityId( things.create( hashMap( "name", "thing1" ) ), 0 );
 
@@ -202,7 +202,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
 
         //now that we know the URl is correct, follow it
 
-        response = context.collection( url ).get();
+        response = context.customCollection( url ).get();
 
         UUID returnedUUID = getEntityId( response, 0 );
 
@@ -222,7 +222,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
     @Test //USERGRID-3011
     public void connectionsDeleteSecondEntityInConnectionTest() throws IOException {
 
-        CustomCollection things = context.collection( "things" );
+        CustomCollection things = context.customCollection( "things" );
 
         UUID thing1Id = getEntityId( things.create( hashMap( "name", "thing1" ) ), 0 );
 
@@ -246,7 +246,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
     @Test //USERGRID-3011
     public void connectionsDeleteFirstEntityInConnectionTest() throws IOException {
 
-        CustomCollection things = context.collection( "things" );
+        CustomCollection things = context.customCollection( "things" );
 
         UUID thing1Id = getEntityId( things.create( hashMap( "name", "thing1" ) ), 0 );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
index a514781..17d99ec 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
@@ -196,7 +196,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
 
         // create a 4peaks restaurant
         JsonNode data = context.application()
-                .collection( "restaurants" ).create( MapUtils.hashMap( "name", "4peaks" ) );
+                .customCollection( "restaurants" ).create( MapUtils.hashMap( "name", "4peaks" ) );
 
         refreshIndex(context.getOrgName(), context.getAppName());
 
@@ -219,7 +219,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
         user2.login( context ).makeActive( context );
         refreshIndex(context.getOrgName(), context.getAppName());
 
-        data = context.application().collection( "restaurants" )
+        data = context.application().customCollection( "restaurants" )
                       .create( MapUtils.hashMap( "name", "arrogantbutcher" ) );
         refreshIndex(context.getOrgName(), context.getAppName());
 
@@ -288,7 +288,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
 
         // test for user 1
 
-        CustomCollection restaurants = context.withUser( user1 ).application().collection( "restaurants" );
+        CustomCollection restaurants = context.withUser( user1 ).application().customCollection( "restaurants" );
         data = restaurants.entity( "4peaks" ).get();
 
         assertNotNull( data );
@@ -300,7 +300,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
         assertEquals( "arrogantbutcher", getEntity( data, 0 ).get( "name" ).asText() );
 
         // test for user 2
-        restaurants = context.withUser( user1 ).application().collection( "restaurants" );
+        restaurants = context.withUser( user1 ).application().customCollection( "restaurants" );
         data = restaurants.entity( "4peaks" ).get();
 
         assertNotNull( data );
@@ -317,7 +317,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
     public void contextualConnectionOwnershipGuestAccess() throws IOException {
 
         //set up full GET,PUT,POST,DELETE access for guests
-        context.application().collection( "roles" ).entity( "guest" ).collection( "permissions" )
+        context.application().customCollection( "roles" ).entity( "guest" ).collection( "permissions" )
                .create( MapUtils.hashMap( "permission", "get,put,post,delete:/**" ) );
 
 
@@ -325,19 +325,19 @@ public class OwnershipResourceIT extends AbstractRestIT {
         context.clearUser();
 
 
-        JsonNode city = context.application().collection( "cities" ).create( MapUtils.hashMap( "name", "tempe" ) );
+        JsonNode city = context.application().customCollection( "cities" ).create( MapUtils.hashMap( "name", "tempe" ) );
 
         refreshIndex(context.getOrgName(), context.getAppName());
 
         String cityId = getEntity( city, 0 ).get( "uuid" ).asText();
 
         // create a 4peaks restaurant
-        JsonNode data = context.application().collection( "cities" ).entity( "tempe" ).connection( "likes" )
+        JsonNode data = context.application().customCollection( "cities" ).entity( "tempe" ).connection( "likes" )
                                .collection( "restaurants" ).create( MapUtils.hashMap( "name", "4peaks" ) );
 
         String peaksId = getEntity( data, 0 ).get( "uuid" ).asText();
 
-        data = context.application().collection( "cities" ).entity( "tempe" ).connection( "likes" )
+        data = context.application().customCollection( "cities" ).entity( "tempe" ).connection( "likes" )
                       .collection( "restaurants" ).create( MapUtils.hashMap( "name", "arrogantbutcher" ) );
 
         String arrogantButcherId = getEntity( data, 0 ).get( "uuid" ).asText();
@@ -345,7 +345,7 @@ public class OwnershipResourceIT extends AbstractRestIT {
         // now query on user 1.
 
         Connection likeRestaurants =
-                context.application().collection( "cities" ).entity( "tempe" ).connection( "likes" );
+                context.application().customCollection( "cities" ).entity( "tempe" ).connection( "likes" );
 
         refreshIndex(context.getOrgName(), context.getAppName());
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/RetrieveUsersTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/RetrieveUsersTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/RetrieveUsersTest.java
index da7d59e..5a8d363 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/RetrieveUsersTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/RetrieveUsersTest.java
@@ -49,7 +49,7 @@ public class RetrieveUsersTest extends AbstractRestIT {
 
     @Test // USERGRID-1222
     public void queryForUsername() throws IOException {
-        CustomCollection users = context.collection( "users" );
+        CustomCollection users = context.customCollection( "users" );
 
         Map props = new HashMap();
 
@@ -70,7 +70,7 @@ public class RetrieveUsersTest extends AbstractRestIT {
 
     @Test // USERGRID-1727
     public void userEntityDictionaryHasRoles() throws IOException {
-        CustomCollection users = context.collection( "users" );
+        CustomCollection users = context.customCollection( "users" );
 
         Map props = new HashMap();
         props.put( "username", "Nina" );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/AndOrQueryTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/AndOrQueryTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/AndOrQueryTest.java
index 942044d..2003faf 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/AndOrQueryTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/AndOrQueryTest.java
@@ -49,7 +49,7 @@ public class AndOrQueryTest extends AbstractRestIT {
     @Test //USERGRID-900
     public void queriesWithAndPastLimit() throws IOException {
 
-        CustomCollection activities = context.collection( "activities" );
+        CustomCollection activities = context.customCollection( "activities" );
 
         long created = 0;
         Map actor = hashMap( "displayName", "Erin" );
@@ -87,7 +87,7 @@ public class AndOrQueryTest extends AbstractRestIT {
     @Test //USERGRID-1475
     public void displayFullQueriesInLimit() throws IOException {
 
-        CustomCollection activities = context.collection( "activities" );
+        CustomCollection activities = context.customCollection( "activities" );
 
         Map actor = hashMap( "displayName", "Erin" );
         Map props = new HashMap();
@@ -124,7 +124,7 @@ public class AndOrQueryTest extends AbstractRestIT {
     @Test //USERGRID-1615
     public void queryReturnCount() throws Exception {
 
-        CustomCollection activities = context.collection( "activities" );
+        CustomCollection activities = context.customCollection( "activities" );
 
         Map actor = hashMap( "displayName", "Erin" );
         Map props = new HashMap();
@@ -149,7 +149,8 @@ public class AndOrQueryTest extends AbstractRestIT {
     @Test //Check to make sure that asc works
     public void queryCheckAsc() throws Exception {
 
-        CustomCollection madeupStuff = context.collection( "imagination" + RandomStringUtils.randomAlphabetic(5));
+        CustomCollection madeupStuff = context.customCollection(
+                "imagination" + RandomStringUtils.randomAlphabetic( 5 ) );
         Map character = hashMap( "WhoHelpedYou", "Ruff" );
 
         JsonNode[] correctValues;
@@ -168,7 +169,7 @@ public class AndOrQueryTest extends AbstractRestIT {
 
     @Ignore("Test to make sure all 1000 exist with a regular query")
     public void queryReturnCheck() throws Exception {
-        CustomCollection madeupStuff = context.collection( "imagination" );
+        CustomCollection madeupStuff = context.customCollection( "imagination" );
         Map character = hashMap( "WhoHelpedYou", "Ruff" );
 
         int numOfEntities = 1000;
@@ -187,7 +188,7 @@ public class AndOrQueryTest extends AbstractRestIT {
 
     @Ignore
     public void queryReturnCheckWithShortHand() throws IOException {
-        CustomCollection madeupStuff = context.collection( "imagination" );
+        CustomCollection madeupStuff = context.customCollection( "imagination" );
         Map character = hashMap( "WhoHelpedYou", "Ruff" );
 
         madeupStuff.createEntitiesWithOrdinal( character, 1000 );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/BadGrammarQueryTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/BadGrammarQueryTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/BadGrammarQueryTest.java
index 0ac0558..a6eb831 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/BadGrammarQueryTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/BadGrammarQueryTest.java
@@ -48,7 +48,7 @@ public class BadGrammarQueryTest extends AbstractRestIT {
     @Test
     public void catchBadQueryGrammar() throws IOException {
 
-        CustomCollection things = context.collection( "things" );
+        CustomCollection things = context.customCollection( "things" );
 
         Map actor = hashMap( "displayName", "Erin" );
         Map props = new HashMap();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
index 9224029..fb9eb70 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
@@ -21,15 +21,22 @@ import java.util.HashMap;
 import java.util.Map;
 
 import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.UniformInterfaceException;
+
 import java.io.IOException;
 import org.junit.Rule;
 import org.junit.Test;
+
+import org.apache.usergrid.persistence.geo.model.Point;
+import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.rest.AbstractRestIT;
 import org.apache.usergrid.rest.TestContextSetup;
 import org.apache.usergrid.rest.test.resource.CustomCollection;
 
 import static org.junit.Assert.assertEquals;
 import static org.apache.usergrid.utils.MapUtils.hashMap;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 
 
 /**
@@ -47,7 +54,7 @@ public class GeoPagingTest extends AbstractRestIT {
     @Test //("Test uses up to many resources to run reliably") // USERGRID-1403
     public void groupQueriesWithGeoPaging() throws IOException {
 
-        CustomCollection groups = context.application().collection( "test1groups" );
+        CustomCollection groups = context.application().customCollection( "test1groups" );
 
         int maxRangeLimit = 2000;
         long[] index = new long[maxRangeLimit];
@@ -73,7 +80,7 @@ public class GeoPagingTest extends AbstractRestIT {
         refreshIndex(context.getOrgName(), context.getAppName());
 
         String query = "select * where location within 20000 of 37,-75 "
-                + " and created > " + index[2] 
+                + " and created > " + index[2]
                 + " and created < " + index[4] + "";
 
         JsonNode node = groups.withQuery( query ).get();
@@ -86,7 +93,7 @@ public class GeoPagingTest extends AbstractRestIT {
     @Test // USERGRID-1401
     public void groupQueriesWithConsistentResults() throws IOException {
 
-        CustomCollection groups = context.application().collection( "test2groups" );
+        CustomCollection groups = context.application().customCollection( "test2groups" );
 
         int maxRangeLimit = 20;
         JsonNode[] saved = new JsonNode[maxRangeLimit];
@@ -110,12 +117,11 @@ public class GeoPagingTest extends AbstractRestIT {
         }
 
         refreshIndex(context.getOrgName(), context.getAppName());
-
         JsonNode node = null;
         for ( int consistent = 0; consistent < 20; consistent++ ) {
 
-            String query = String.format( 
-                "select * where location within 100 of 37, -75 and ordinal >= %d and ordinal < %d", 
+            String query = String.format(
+                "select * where location within 100 of 37, -75 and ordinal >= %d and ordinal < %d",
                 saved[7].get( "ordinal" ).asLong(), saved[10].get( "ordinal" ).asLong() );
 
             node = groups.withQuery( query ).get(); //groups.query(query);
@@ -130,4 +136,67 @@ public class GeoPagingTest extends AbstractRestIT {
             }
         }
     }
+
+
+    /**
+     * Creates a store then queries to check ability to find different store from up to 40 mil meters away
+     * @throws IOException
+     */
+    @Test
+    public void testFarAwayLocationFromCenter() throws IOException {
+
+        JsonNode node = null;
+        String collectionName = "testFarAwayLocation";
+        Map store1 = entityMapLocationCreator( "usergrid",-33.746369 ,150.952183 );
+        Map store2 = entityMapLocationCreator( "usergrid2",-33.889058, 151.124024  );
+        Point center = new Point( 37.776753, -122.407846 );
+        //TODO: make query builder for this
+        Query queryClose = locationQuery( 10000 ,center );
+        Query queryFar = locationQuery( 40000000, center );
+
+        /*Create */
+        try {
+            node = context.collection( collectionName ).post( store1);
+        }
+        catch ( UniformInterfaceException e ) {
+            JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) );
+            fail( node.get( "error" ).textValue() );
+        }
+        assertNotNull( node );
+        assertEquals( "usergrid", node.get( "name" ).asText() );
+//TODO: check to see if context.application.collection is broken?
+        try {
+            node = context.collection( collectionName ).post( store2 );
+        }
+        catch ( UniformInterfaceException e ) {
+            JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) );
+            fail( node.get( "error" ).textValue() );
+        }
+
+        refreshIndex( context.getOrgName(),context.getAppName() );
+
+        /* run queries */
+        //context.collection( collectionName ).query(  )
+
+
+
+        // assertEquals(node.get(  ))
+    }
+
+    private Map entityMapLocationCreator(String name,Double lat, Double lon){
+        Map<String, Double> latLon = hashMap( "latitude", lat );
+        latLon.put( "longitude", lon );
+        Map<String, Object> entityData = new HashMap<String, Object>();
+        entityData.put( "name", name );
+        entityData.put( "location", latLon );
+
+        return entityData;
+    }
+
+    private Query locationQuery(int  metersAway, Point startingPoint){
+        return Query.fromQL( "select * where location within " + String.valueOf( metersAway ) + " of "
+                + startingPoint.getLat() + "," + startingPoint.getLon());
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/MatrixQueryTests.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/MatrixQueryTests.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/MatrixQueryTests.java
index 25bc33b..9531a14 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/MatrixQueryTests.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/MatrixQueryTests.java
@@ -61,7 +61,7 @@ public class MatrixQueryTests extends AbstractRestIT {
 
         //now create 4 restaurants
 
-        CustomCollection restaurants = context.collection( "restaurants" );
+        CustomCollection restaurants = context.customCollection( "restaurants" );
 
 
         Map restaurant1 = hashMap( "name", "Old Major" );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/OrderByTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/OrderByTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/OrderByTest.java
index 481f753..f00912c 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/OrderByTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/OrderByTest.java
@@ -50,7 +50,7 @@ public class OrderByTest extends AbstractRestIT {
     // USERGRID-1400
     public void orderByShouldNotAffectResults() throws IOException {
 
-        CustomCollection activities = context.collection( "activities" );
+        CustomCollection activities = context.customCollection( "activities" );
 
         long created = 0;
         Map actor = hashMap( "displayName", "Erin" );
@@ -82,7 +82,7 @@ public class OrderByTest extends AbstractRestIT {
     // USERGRID-1520
     public void orderByComesBeforeLimitResult() throws IOException {
 
-        CustomCollection activities = context.collection( "activities" );
+        CustomCollection activities = context.customCollection( "activities" );
 
         Map actor = hashMap( "displayName", "Erin" );
         Map props = new HashMap();
@@ -122,7 +122,7 @@ public class OrderByTest extends AbstractRestIT {
     // USERGRID-1521
     public void orderByReturnCorrectResults() throws IOException {
 
-        CustomCollection activities = context.collection( "activities" );
+        CustomCollection activities = context.customCollection( "activities" );
 
         int size = 200;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java
index c75945e..2c0531a 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.rest.test.resource;
 import java.util.UUID;
 
 import org.apache.usergrid.rest.test.resource.app.Application;
+import org.apache.usergrid.rest.test.resource.app.Collection;
 import org.apache.usergrid.rest.test.resource.app.User;
 import org.apache.usergrid.rest.test.resource.app.UsersCollection;
 import org.apache.usergrid.rest.test.resource.mgmt.Management;
@@ -72,12 +73,18 @@ public class TestContext {
         return withUser( null );
     }
 
+    public TestContext withOrg(){
+        return this;
+    }
 
     public TestContext withOrg( String orgName ) {
         testOrganization = new TestOrganization( orgName );
         return this;
     }
 
+    public TestContext withApp ( ) {
+        return this;
+    }
 
     public TestContext withApp( String appName ) {
         this.appName = appName;
@@ -156,9 +163,13 @@ public class TestContext {
         return new Application( getOrgName(), appName, root() );
     }
 
+//TODO: remove custom collections!
+    public CustomCollection customCollection( String str ) {
+        return application().customCollection( str );
+    }
 
-    public CustomCollection collection( String str ) {
-        return application().collection( str );
+    public Collection collection (String name) {
+        return application().collection( name );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java
index 4012cc4..3a9181a 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java
@@ -94,6 +94,7 @@ public abstract class ValueResource extends NamedResource {
 
 
     /** post to the entity set */
+    //TODO: fix error reporting 
     protected JsonNode postInternal( Map<String, ?> entity ) throws IOException {
 
         return mapper.readTree( jsonMedia( withParams( withToken( resource() ) ) ).post( String.class, entity ));

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Application.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Application.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Application.java
index dd393fc..9de259d 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Application.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Application.java
@@ -67,8 +67,12 @@ public class Application extends ValueResource {
         return new DevicesCollection( this );
     }
 
-
-    public CustomCollection collection( String name ) {
+//TODO: work out differences between CustomCollections and replace tests with a general collection method.
+    public CustomCollection customCollection( String name ) {
         return new CustomCollection( name, this );
     }
+
+    public Collection collection( String name ) {
+        return new Collection( name,this );
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
new file mode 100644
index 0000000..12592b5
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
@@ -0,0 +1,47 @@
+package org.apache.usergrid.rest.test.resource.app;
+
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.usergrid.rest.test.resource.NamedResource;
+import org.apache.usergrid.rest.test.resource.SetResource;
+import org.apache.usergrid.utils.MapUtils;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+
+//TODO: G make sure this no longer returns JsonNodes and instead returns EntityObjects.
+//TODO: Add in full rest suite of GET,PUT,DELETE methods. Delete will be mostly universal.
+public class Collection extends SetResource {
+
+    public Collection( String collectionName, NamedResource parent ) {
+        super( collectionName, parent );
+    }
+
+    /** Create the user in a collection using only the username */
+    public JsonNode post( String name ) throws IOException {
+        Map<String, String> data = MapUtils.hashMap( "name", name );
+
+        JsonNode response = this.postInternal( data );
+
+        return getEntity( response, 0 );
+    }
+
+
+    /**
+     * Create the user in a collection using username,email,password
+     * @param entityData
+     * @return
+     * @throws IOException
+     */
+    public JsonNode post(Map entityData) throws IOException{
+
+        JsonNode response = this.postInternal( entityData );
+
+        return getEntity( response, 0 );
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/968352de/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java
index 32b3ab8..da9cccc 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java
@@ -29,7 +29,7 @@ import org.apache.usergrid.utils.MapUtils;
 
 
 /** @author tnine */
-public class UsersCollection extends CollectionResource {
+public class UsersCollection extends Collection {
 
 
     public UsersCollection( NamedResource parent ) {
@@ -48,7 +48,7 @@ public class UsersCollection extends CollectionResource {
 
 
     /** Create the user */
-    public JsonNode create( String username, String email, String password ) throws IOException {
+    public JsonNode post( String username, String email, String password ) throws IOException {
         Map<String, String> data =
                 MapUtils.hashMap( "username", username ).map( "email", email ).map( "password", password );
 
@@ -57,6 +57,16 @@ public class UsersCollection extends CollectionResource {
         return getEntity( response, 0 );
     }
 
+    /** Create the user */
+    //TODO: delete create method once rest calls are implemented
+    public JsonNode create( String username, String email, String password ) throws IOException {
+        Map<String, String> data =
+                MapUtils.hashMap( "username", username ).map( "email", email ).map( "password", password );
+
+        JsonNode response = this.postInternal( data );
+
+        return getEntity( response, 0 );
+    }
 
     public Me me() {
         return new Me( this );


[3/9] incubator-usergrid git commit: added groups, roles collection, updates to groups tests

Posted by sn...@apache.org.
added groups, roles collection, updates to groups tests


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

Branch: refs/heads/two-dot-o-events
Commit: 884bd0141b72ac53eb2415429bea755cec0a85aa
Parents: 968352d
Author: Rod Simpson <ro...@apigee.com>
Authored: Thu Nov 20 15:51:25 2014 -0700
Committer: Rod Simpson <ro...@apigee.com>
Committed: Thu Nov 20 15:51:25 2014 -0700

----------------------------------------------------------------------
 .../collection/groups/GroupResourceIT.java      | 240 +++++++++++++++++--
 .../applications/queries/GeoPagingTest.java     | 100 +++++++-
 .../usergrid/rest/test/resource/Connection.java |   9 +
 .../rest/test/resource/TestContext.java         |  31 ++-
 .../rest/test/resource/app/Application.java     |   8 +
 .../rest/test/resource/app/Collection.java      |  24 +-
 .../usergrid/rest/test/resource/app/Group.java  |  56 +++++
 .../test/resource/app/GroupsCollection.java     |  66 +++++
 .../usergrid/rest/test/resource/app/Role.java   |  56 +++++
 .../rest/test/resource/app/RolesCollection.java |  64 +++++
 .../rest/test/resource/app/UsersCollection.java |  12 +
 11 files changed, 627 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/884bd014/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
index 0dd6dc8..5d21eb9 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
@@ -17,13 +17,21 @@
 package org.apache.usergrid.rest.applications.collection.groups;
 
 
+import java.util.Map;
 import java.util.UUID;
 
+import javax.rmi.CORBA.Util;
 import javax.ws.rs.core.MediaType;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import java.io.IOException;
+
+import com.google.gson.JsonObject;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+import org.apache.usergrid.utils.JsonUtils;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,54 +39,229 @@ import org.apache.usergrid.cassandra.Concurrent;
 import org.apache.usergrid.java.client.Client.Query;
 import org.apache.usergrid.java.client.response.ApiResponse;
 import org.apache.usergrid.rest.AbstractRestIT;
+import org.apache.usergrid.rest.TestContextSetup;
+import org.apache.usergrid.rest.test.resource.app.GroupsCollection;
 import org.apache.usergrid.utils.UUIDUtils;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
+import static org.junit.Assert.*;
 
-/** @author tnine */
+/** @author rockerston */
 @Concurrent()
 public class GroupResourceIT extends AbstractRestIT {
     private static Logger log = LoggerFactory.getLogger( GroupResourceIT.class );
 
-    private static final String GROUP = "testGroup";
+    /*
+    private static final String GROUP = "testGroup" + UUIDUtils.newTimeUUID();
+    private static final String USER = "edanuff" + UUIDUtils.newTimeUUID();
+*/
+
+    @Rule
+    public TestContextSetup context = new TestContextSetup( this );
 
-    private static final String USER = "edanuff";
+    public GroupResourceIT() throws Exception { }
 
-    private static boolean groupCreated = false;
+    /***
+     *
+     * Verify that we can create a group with a standard string in the name and path
+     */
+    @Test()
+    public void createGroupValidation() throws IOException {
 
+        GroupsCollection groups = context.groups();
 
-    public GroupResourceIT() throws Exception {
+        //create a group with a normal name
+        String groupName = "testgroup";
+        String groupPath = "testgroup";
+        JsonNode testGroup = groups.create(groupName, groupPath);
+        //verify the group was created
+        assertNull(testGroup.get("errors"));
+        assertEquals(testGroup.get("path").asText(), groupPath);
+    }
 
+    /***
+     *
+     * Verify that we can create a group with a slash in the name and path
+     */
+    @Test()
+    public void createGroupSlashInNameAndPathValidation() throws IOException {
+
+        GroupsCollection groups = context.groups();
+
+        //create a group with a slash in the name
+        String groupNameSlash = "test/group";
+        String groupPathSlash = "test/group";
+        JsonNode testGroup = groups.create( groupNameSlash, groupPathSlash );
+        //verify the group was created
+        assertNull( testGroup.get( "errors" ) );
+        assertEquals( testGroup.get("path").asText(),groupPathSlash );
     }
 
+    /***
+     *
+     * Verify that we can create a group with a space in the name
+     */
+    @Test()
+    public void createGroupSpaceInNameValidation() throws IOException {
 
-    @Before
-    public void setupGroup() {
-        if ( groupCreated ) {
-            return;
-        }
+        GroupsCollection groups = context.groups();
 
+        //create a group with a space in the name
+        String groupName = "test group";
+        String groupPath = "testgroup";
         try {
-            client.createGroup( GROUP );
-            groupCreated = true;
+            JsonNode testGroup = groups.create(groupName, groupPath);
+        } catch (UniformInterfaceException e) {
+            //verify the correct error was returned
+            JsonNode node = mapper.readTree( e.getResponse().getEntity( String.class ));
+            assertEquals( "illegal_argument", node.get( "error" ).textValue() );
         }
-        catch ( Exception e ) {
-            log.error( "Error creating group " + GROUP, e );
+    }
+
+    /***
+     *
+     * Verify that we cannot create a group with a space in the path
+     */
+    @Test()
+    public void createGroupSpaceInPathValidation() throws IOException {
+
+        GroupsCollection groups = context.groups();
+
+        //create a group with a space in the path
+        String groupName = "testgroup";
+        String groupPath = "test group";
+        try {
+            JsonNode testGroup = groups.create(groupName, groupPath);
+        } catch (UniformInterfaceException e) {
+            //verify the correct error was returned
+            JsonNode node = mapper.readTree( e.getResponse().getEntity( String.class ));
+            assertEquals( "illegal_argument", node.get( "error" ).textValue() );
         }
+    }
+
+    /***
+     *
+     * Verify that we cannot create a group with a space in the path
+     */
+    @Test
+    public void postGroupActivity() {
+
+/*
+        //1. create a group
+        GroupsCollection groups = context.groups();
+
+        //create a group with a normal name
+        String groupName = "groupTitle";
+        String groupPath = "groupPath";
+        JsonNode testGroup = groups.create(groupName, groupPath);
+        //verify the group was created
+        assertNull(testGroup.get("errors"));
+        assertEquals(testGroup.get("path").asText(), groupPath);
+
+        //2.
+   /*
+        UUID id = UUIDUtils.newTimeUUID();
+
+        String groupPath = "groupPath" + id;
+        String groupTitle = "groupTitle " + id;
+        String groupName = "groupName" + id;
+
+        ApiResponse response = client.createGroup( groupPath, groupTitle, groupName );
+
+        assertNull( "Error was: " + response.getErrorDescription(), response.getError() );
+
         refreshIndex("test-organization", "test-app");
 
+        UUID newId = response.getEntities().get( 0 ).getUuid();
+
+        Query results = client.queryGroups( String.format( "name='%s'", groupName ) );
+
+        response = results.getResponse();
+
+        UUID entityId = response.getEntities().get( 0 ).getUuid();
+
+        assertEquals( newId, entityId );
+
+        results = client.queryGroups( String.format( "title='%s'", groupTitle ) );
+
+        response = results.getResponse();
+
+        entityId = response.getEntities().get( 0 ).getUuid();
+
+        assertEquals( newId, entityId );
+
+        results = client.queryGroups( String.format( "title contains '%s'", id ) );
+
+        response = results.getResponse();
+
+        entityId = response.getEntities().get( 0 ).getUuid();
+
+        assertEquals( newId, entityId );
+
+        results = client.queryGroups( String.format( "path='%s'", groupPath ) );
+
+        response = results.getResponse();
+
+        entityId = response.getEntities().get( 0 ).getUuid();
+
+        assertEquals( newId, entityId );
+        */
     }
+}
 
+/*
+    @Test(expected = IllegalArgumentException.class)
+    public void failGroupNameValidation() throws IOException{
 
-    @Test
-    public void failGroupNameValidation() {
 
-        ApiResponse response = client.createGroup( "groupName/withslash" );
-        assertNull( response.getError() );
+
+        //context.application().groups().group("mygroup").connection("likes").collection("users").entity("bob").post();
+
+
+        /*
+        Map user1 =
+                hashMap( "username", "user1" ).map( "email", "testuser1@usergrid.com" ).map( "fullname", "Bob Smith" );
+
+        users.create( user1 );
+
+        GroupsCollection groups = context.groups();
+
+        /*
+        // set up context
+        String orgName = context.getOrgName();
+        String appName = context.getAppName();
+        String path = "/"+orgName+"/"+appName+"/groups/";
+
+        //-----------------------------------------------
+        // 1. test for group path with slash
+        //-----------------------------------------------
+        String groupPath = "grouppath/slash" + UUIDUtils.newTimeUUID();
+
+        String json = "{\"path\":\""+ groupPath +"\"}";
+        JsonNode node = mapper.readTree( resource().path( path )
+                .queryParam( "access_token", context.getActiveUser().getToken() ).accept( MediaType.APPLICATION_JSON )
+                .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, json ));
+
+        //verify
+        assertNull( node.get( "errors" ) );
+        assertEquals( node.get( "entities" ).get(0).get("path").asText(), groupPath);
+
+        //-----------------------------------------------
+        //2. test for group path with space
+        //-----------------------------------------------
+        groupPath = "grouppath space" + UUIDUtils.newTimeUUID();
+        try {
+            json = "{\"path\":\"" + groupPath + "\"}";
+            node = mapper.readTree(resource().path(path)
+                    .queryParam("access_token", context.getActiveUser().getToken()).accept(MediaType.APPLICATION_JSON)
+                    .type(MediaType.APPLICATION_JSON_TYPE).post(String.class, json));
+        } catch (Exception e) {
+
+            //verify
+            //assertNull( node.get( "errors" ) );
+            String doug = node.get("error").asText();
+            assertEquals( node.get("error").asText(), "illegal_argument");
+        }
+
 
         refreshIndex("test-organization", "test-app");
 
@@ -92,9 +275,10 @@ public class GroupResourceIT extends AbstractRestIT {
             }
             assertTrue( failed );
         }
-    }
 
+    }
 
+/*
     @Test
     public void postGroupActivity() {
 
@@ -164,9 +348,12 @@ public class GroupResourceIT extends AbstractRestIT {
         UUID createdId = response.getEntities().get( 0 ).getUuid();
 
         // add Permission
+        String orgName = context.getOrgName();
+        String appName = context.getAppName();
+        String path = "/"+orgName+"/"+appName+"/groups/";
 
         String json = "{\"permission\":\"delete:/test\"}";
-        JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/groups/" + createdId + "/permissions" )
+        JsonNode node = mapper.readTree( resource().path( path + createdId + "/permissions" )
                 .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
                 .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, json ));
 
@@ -292,4 +479,5 @@ public class GroupResourceIT extends AbstractRestIT {
         assertNull( node.get( "errors" ) );
         assertFalse( node.get( "entities" ).findValuesAsText( "name" ).contains( roleName ) );
     }
-}
+    */
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/884bd014/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
index fb9eb70..bb5b934 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
@@ -17,13 +17,16 @@
 package org.apache.usergrid.rest.applications.queries;
 
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.sun.jersey.api.client.UniformInterfaceException;
 
 import java.io.IOException;
+
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.Results;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -54,7 +57,7 @@ public class GeoPagingTest extends AbstractRestIT {
     @Test //("Test uses up to many resources to run reliably") // USERGRID-1403
     public void groupQueriesWithGeoPaging() throws IOException {
 
-        CustomCollection groups = context.application().customCollection( "test1groups" );
+        CustomCollection groups = context.application().customCollection("test1groups");
 
         int maxRangeLimit = 2000;
         long[] index = new long[maxRangeLimit];
@@ -93,7 +96,7 @@ public class GeoPagingTest extends AbstractRestIT {
     @Test // USERGRID-1401
     public void groupQueriesWithConsistentResults() throws IOException {
 
-        CustomCollection groups = context.application().customCollection( "test2groups" );
+        CustomCollection groups = context.application().customCollection("test2groups");
 
         int maxRangeLimit = 20;
         JsonNode[] saved = new JsonNode[maxRangeLimit];
@@ -147,8 +150,10 @@ public class GeoPagingTest extends AbstractRestIT {
 
         JsonNode node = null;
         String collectionName = "testFarAwayLocation";
-        Map store1 = entityMapLocationCreator( "usergrid",-33.746369 ,150.952183 );
-        Map store2 = entityMapLocationCreator( "usergrid2",-33.889058, 151.124024  );
+        Map store1 = entityMapLocationCreator( -33.746369 ,150.952183 );
+        store1.put( "name", "usergrid" );
+        Map store2 = entityMapLocationCreator( -33.889058, 151.124024 );
+        store2.put( "name", "usergrid" );
         Point center = new Point( 37.776753, -122.407846 );
         //TODO: make query builder for this
         Query queryClose = locationQuery( 10000 ,center );
@@ -183,11 +188,90 @@ public class GeoPagingTest extends AbstractRestIT {
         // assertEquals(node.get(  ))
     }
 
-    private Map entityMapLocationCreator(String name,Double lat, Double lon){
+
+    /**
+     * Creates two users, then a huge matrix of coordinates, then checks to see if any of the coordinates are near our users
+     * @throws IOException
+     */
+    @Test
+    public void createHugeMatrixOfCoordinates() throws IOException {
+
+
+        JsonNode node = null;
+
+        Map user1Coordinates = entityMapLocationCreator( -33.746369 ,150.952183 );
+        Map user2Coordinates = entityMapLocationCreator( -33.889058, 151.124024 );
+
+        /*Create */
+        try {
+            node = context.users().post("norwest", "norwest@usergrid.com", "norwest", user1Coordinates);
+        }
+        catch ( UniformInterfaceException e ) {
+            JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) );
+            fail( node.get( "error" ).textValue() );
+        }
+
+        /*Create */
+        try {
+            node = context.users().post("ashfield", "ashfield@usergrid.com", "ashfield", user2Coordinates);
+        }
+        catch ( UniformInterfaceException e ) {
+            JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) );
+            fail( node.get( "error" ).textValue() );
+        }
+
+        refreshIndex( context.getOrgName(),context.getAppName() );
+
+        List<Point> points = new ArrayList<Point>();
+        points.add(new Point( 33.746369,-89 ));//Woodland, MS
+        points.add(new Point( 33.746369,-91 ));//Beulah, MS
+        points.add(new Point( -1.000000, 102.000000 ));//Somewhere in Indonesia
+        points.add(new Point( -90.000000, 90.000000 ));//Antarctica
+        points.add(new Point( 90, 90 ));//Santa's house
+        //and the cartesian product...
+        for(int i= -90;i<=90;i++){
+            for(int j= -180;j<=180;j++){
+                points.add(new Point( i, j ));
+            }
+        }
+        Iterator<Point> pointIterator = points.iterator();
+        for(Point p=pointIterator.next();pointIterator.hasNext();p=pointIterator.next()){
+
+            Point center = new Point( p.getLat(),  p.getLon() );
+            Query query = locationQuery( 10000 ,center );
+
+            try {
+               // node = context.users( ).get(  ).withQuery( query );
+            }
+            catch ( UniformInterfaceException e ) {
+                JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) );
+                fail( node.get( "error" ).textValue() );
+            }
+
+/*
+            Query query = Query.fromQL( "select * where location within 10000 of "
+                    + p.getLat() + "," + p.getLon());
+            Results listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
+
+            this.dump( listResults );
+            assertEquals("Results less than 10000m away from center", 0, listResults.size() );
+
+            query = Query.fromQL( "select * where location within 40000000 of "
+                    + p.getLat() + "," + p.getLon());
+            listResults = em.searchCollection( em.getApplicationRef(), "stores", query );
+
+            assertEquals("Results from center point to ridiculously far", 2, listResults.size() );
+*/
+        }
+    }
+
+
+
+
+    private Map entityMapLocationCreator(Double lat, Double lon){
         Map<String, Double> latLon = hashMap( "latitude", lat );
         latLon.put( "longitude", lon );
         Map<String, Object> entityData = new HashMap<String, Object>();
-        entityData.put( "name", name );
         entityData.put( "location", latLon );
 
         return entityData;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/884bd014/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/Connection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/Connection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/Connection.java
index e491247..5a87472 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/Connection.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/Connection.java
@@ -19,6 +19,9 @@ package org.apache.usergrid.rest.test.resource;
 
 import java.util.UUID;
 
+import org.apache.usergrid.rest.test.resource.app.UsersCollection;
+import org.apache.usergrid.rest.test.resource.app.GroupsCollection;
+import org.apache.usergrid.rest.test.resource.app.RolesCollection;
 import org.apache.usergrid.rest.test.resource.app.queue.DevicesCollection;
 
 
@@ -45,6 +48,12 @@ public class Connection extends ValueResource {
         return new DevicesCollection( this );
     }
 
+    public UsersCollection users() { return new UsersCollection(this);}
+
+    public GroupsCollection groups() { return new GroupsCollection(this);}
+
+    public RolesCollection roles() { return new RolesCollection(this);}
+
 
     public CustomCollection collection( String name ) {
         return new CustomCollection( name, this );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/884bd014/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java
index 2c0531a..f1608b2 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java
@@ -23,6 +23,10 @@ import org.apache.usergrid.rest.test.resource.app.Application;
 import org.apache.usergrid.rest.test.resource.app.Collection;
 import org.apache.usergrid.rest.test.resource.app.User;
 import org.apache.usergrid.rest.test.resource.app.UsersCollection;
+import org.apache.usergrid.rest.test.resource.app.Group;
+import org.apache.usergrid.rest.test.resource.app.GroupsCollection;
+import org.apache.usergrid.rest.test.resource.app.Role;
+import org.apache.usergrid.rest.test.resource.app.RolesCollection;
 import org.apache.usergrid.rest.test.resource.mgmt.Management;
 import org.apache.usergrid.rest.test.security.TestUser;
 
@@ -107,7 +111,7 @@ public class TestContext {
         OrgUserUUIDWrapper ouuw = management().orgs().create( getOrgName(),activeUser );
         testOrganization.setUuid( ouuw.getOrgUUID() );
         activeUser.setUUID( ouuw.getUserUUID() );
-        refreshIndex( getOrgName(), appName );
+        refreshIndex(getOrgName(), appName);
         return this;
     }
 
@@ -139,10 +143,31 @@ public class TestContext {
         return application().users();
     }
 
-
     /** Get the app user resource */
     public User user( String username ) {
-        return application().users().user( username );
+        return application().users().user(username);
+    }
+
+
+    /** Get the users resource for the application */
+    public GroupsCollection groups() {
+        return application().groups();
+    }
+
+    /** Get the app group resource */
+    public Group group( String path ) {
+        return application().groups().group( path );
+    }
+
+
+    /** Get the groups resource for the application */
+    public RolesCollection roles() {
+        return application().roles();
+    }
+
+    /** Get the app role resource */
+    public Role role( String name ) {
+        return application().roles().role( name );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/884bd014/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Application.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Application.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Application.java
index 9de259d..79e24fd 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Application.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Application.java
@@ -57,6 +57,14 @@ public class Application extends ValueResource {
         return new UsersCollection( this );
     }
 
+    public GroupsCollection groups() {
+        return new GroupsCollection( this );
+    }
+
+    public RolesCollection roles() {
+        return new RolesCollection( this );
+    }
+
 
     public QueuesCollection queues() {
         return new QueuesCollection( this );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/884bd014/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
index 12592b5..ac65a01 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Collection.java
@@ -21,6 +21,12 @@ public class Collection extends SetResource {
     }
 
     /** Create the user in a collection using only the username */
+    /**
+     * POST an entity with only a name
+     * @param name
+     * @return JsonNode
+     * @throws IOException
+     */
     public JsonNode post( String name ) throws IOException {
         Map<String, String> data = MapUtils.hashMap( "name", name );
 
@@ -29,11 +35,25 @@ public class Collection extends SetResource {
         return getEntity( response, 0 );
     }
 
+    /**
+     * POST an entity with a name and a Map (e.g. if you want to add in a location sub-object
+     * @param name
+     * @param entityData
+     * @return JsonNode
+     * @throws IOException
+     */
+    public JsonNode post( String name, Map entityData ) throws IOException {
+        Map<String, String> data = MapUtils.hashMap( "name", name );
+        data.putAll(entityData);
+        JsonNode response = this.postInternal( data );
+
+        return getEntity( response, 0 );
+    }
 
     /**
-     * Create the user in a collection using username,email,password
+     * POST an entity with only a Map
      * @param entityData
-     * @return
+     * @return JsonNode
      * @throws IOException
      */
     public JsonNode post(Map entityData) throws IOException{

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/884bd014/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Group.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Group.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Group.java
new file mode 100644
index 0000000..4446bf6
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Group.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.rest.test.resource.app;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.rest.test.resource.EntityResource;
+import org.apache.usergrid.rest.test.resource.NamedResource;
+import org.apache.usergrid.rest.test.resource.app.queue.DevicesCollection;
+
+
+/**
+ * A resource for testing queues
+ *
+ * @author rockerston
+ */
+public class Group
+        extends EntityResource {
+
+    /**
+     * @param entityId
+     * @param parent
+     */
+    public Group( UUID entityId, NamedResource parent ) {
+        super( entityId, parent );
+    }
+
+
+    /**
+     * @param entityName
+     * @param parent
+     */
+    public Group( String entityName, NamedResource parent ) {
+        super( entityName, parent );
+    }
+
+
+    public DevicesCollection devices() {
+        return new DevicesCollection( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/884bd014/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java
new file mode 100644
index 0000000..0f49dcc
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.rest.test.resource.app;
+
+
+import java.util.Map;
+import java.util.UUID;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import org.apache.usergrid.rest.test.resource.CollectionResource;
+import org.apache.usergrid.rest.test.resource.Me;
+import org.apache.usergrid.rest.test.resource.NamedResource;
+import org.apache.usergrid.utils.MapUtils;
+
+
+/** @author rockerston */
+public class GroupsCollection extends CollectionResource {
+
+
+    public GroupsCollection( NamedResource parent ) {
+        super( "groups", parent );
+    }
+
+
+    public Group group( String username ) {
+        return new Group( username, this );
+    }
+
+
+    public Group group( UUID id ) {
+        return new Group( id, this );
+    }
+
+
+    /** Create the group */
+    public JsonNode create( String path, String title ) throws IOException {
+        Map<String, String> data =
+                MapUtils.hashMap( "path", path ).map( "title", title );
+
+        JsonNode response = this.postInternal( data );
+
+        return getEntity( response, 0 );
+    }
+
+
+
+
+    public Me me() {
+        return new Me( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/884bd014/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Role.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Role.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Role.java
new file mode 100644
index 0000000..b60ef56
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Role.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.rest.test.resource.app;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.rest.test.resource.EntityResource;
+import org.apache.usergrid.rest.test.resource.NamedResource;
+import org.apache.usergrid.rest.test.resource.app.queue.DevicesCollection;
+
+
+/**
+ * A resource for testing queues
+ *
+ * @author rockerston
+ */
+public class Role
+        extends EntityResource {
+
+    /**
+     * @param entityId
+     * @param parent
+     */
+    public Role( UUID entityId, NamedResource parent ) {
+        super( entityId, parent );
+    }
+
+
+    /**
+     * @param entityName
+     * @param parent
+     */
+    public Role( String entityName, NamedResource parent ) {
+        super( entityName, parent );
+    }
+
+
+    public DevicesCollection devices() {
+        return new DevicesCollection( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/884bd014/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/RolesCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/RolesCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/RolesCollection.java
new file mode 100644
index 0000000..dd3e737
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/RolesCollection.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.rest.test.resource.app;
+
+
+import java.util.Map;
+import java.util.UUID;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import org.apache.usergrid.rest.test.resource.CollectionResource;
+import org.apache.usergrid.rest.test.resource.Me;
+import org.apache.usergrid.rest.test.resource.NamedResource;
+import org.apache.usergrid.utils.MapUtils;
+
+
+/** @author rockerston */
+public class RolesCollection extends CollectionResource {
+
+
+    public RolesCollection( NamedResource parent ) {
+        super( "roles", parent );
+    }
+
+
+    public Role role( String name ) {
+        return new Role( name, this );
+    }
+
+
+    public Role role( UUID id ) {
+        return new Role( id, this );
+    }
+
+
+    /** Create the role */
+    public JsonNode create( String name, String title ) throws IOException {
+        Map<String, String> data =
+                MapUtils.hashMap( "name", name ).map( "title", title );
+
+        JsonNode response = this.postInternal( data );
+
+        return getEntity( response, 0 );
+    }
+
+
+    public Me me() {
+        return new Me( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/884bd014/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java
index da9cccc..d7b4293 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java
@@ -58,6 +58,18 @@ public class UsersCollection extends Collection {
     }
 
     /** Create the user */
+    public JsonNode post( String username, String email, String password, Map entityData ) throws IOException {
+        Map<String, String> data =
+                MapUtils.hashMap( "username", username ).map( "email", email ).map( "password", password );
+        data.putAll(entityData);
+
+        JsonNode response = this.postInternal( data );
+
+        return getEntity( response, 0 );
+    }
+
+
+    /** Create the user */
     //TODO: delete create method once rest calls are implemented
     public JsonNode create( String username, String email, String password ) throws IOException {
         Map<String, String> data =


[4/9] incubator-usergrid git commit: Added refreshIndex method to context so we no longer need to specify which org and apps we want for default context. Refactored test to make test intentions more clear and help with future tests. Added comment on quer

Posted by sn...@apache.org.
Added refreshIndex method to context so we no longer need to specify which org and apps we want for default context.
Refactored test to make test intentions more clear and help with future tests.
Added comment on query method in the ValueResource.


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

Branch: refs/heads/two-dot-o-events
Commit: 6e9db18d6be898891bbe20c556f17ff396405a40
Parents: 884bd01
Author: grey <gr...@apigee.com>
Authored: Thu Nov 20 16:33:43 2014 -0800
Committer: grey <gr...@apigee.com>
Committed: Thu Nov 20 16:33:43 2014 -0800

----------------------------------------------------------------------
 .../apache/usergrid/rest/AbstractRestIT.java    |  2 +-
 .../applications/queries/GeoPagingTest.java     | 85 ++++++++++++--------
 .../rest/test/resource/TestContext.java         | 20 +++++
 .../rest/test/resource/ValueResource.java       |  3 +-
 4 files changed, 75 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e9db18d/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
index 4665bc6..1a18568 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
@@ -411,7 +411,7 @@ public abstract class AbstractRestIT extends JerseyTest {
     }
 
 
-    public void refreshIndex( UUID appId ) {
+    protected void refreshIndex( UUID appId ) {
 
         LOG.debug("Refreshing index for appId {}", appId );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e9db18d/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
index bb5b934..e9229ec 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
@@ -27,6 +27,8 @@ import java.io.IOException;
 import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.Results;
+
+import org.jclouds.json.Json;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -150,42 +152,26 @@ public class GeoPagingTest extends AbstractRestIT {
 
         JsonNode node = null;
         String collectionName = "testFarAwayLocation";
-        Map store1 = entityMapLocationCreator( -33.746369 ,150.952183 );
-        store1.put( "name", "usergrid" );
-        Map store2 = entityMapLocationCreator( -33.889058, 151.124024 );
-        store2.put( "name", "usergrid" );
         Point center = new Point( 37.776753, -122.407846 );
-        //TODO: make query builder for this
-        Query queryClose = locationQuery( 10000 ,center );
-        Query queryFar = locationQuery( 40000000, center );
 
+        String queryClose = locationQuery( 10000 ,center );
+        String queryFar = locationQuery( 40000000, center );
+
+        //TODO: move test setup out of the test.
         /*Create */
-        try {
-            node = context.collection( collectionName ).post( store1);
-        }
-        catch ( UniformInterfaceException e ) {
-            JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) );
-            fail( node.get( "error" ).textValue() );
-        }
-        assertNotNull( node );
-        assertEquals( "usergrid", node.get( "name" ).asText() );
-//TODO: check to see if context.application.collection is broken?
-        try {
-            node = context.collection( collectionName ).post( store2 );
-        }
-        catch ( UniformInterfaceException e ) {
-            JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) );
-            fail( node.get( "error" ).textValue() );
-        }
+        createGeoUser( "usergrid", collectionName, -33.746369, 150.952183 );
 
-        refreshIndex( context.getOrgName(),context.getAppName() );
+        createGeoUser( "usergrid2", collectionName, -33.889058, 151.124024 );
 
         /* run queries */
-        //context.collection( collectionName ).query(  )
 
+        node = queryCollection( collectionName,queryClose );
 
+        assertEquals("Results from nearby, should return nothing" ,0, node.get( "entities" ).size() );
 
-        // assertEquals(node.get(  ))
+        node = queryCollection( collectionName,queryFar );
+
+        assertEquals("Results from center point to ridiculously far", 2, node.get( "entities" ).size() );
     }
 
 
@@ -238,10 +224,10 @@ public class GeoPagingTest extends AbstractRestIT {
         for(Point p=pointIterator.next();pointIterator.hasNext();p=pointIterator.next()){
 
             Point center = new Point( p.getLat(),  p.getLon() );
-            Query query = locationQuery( 10000 ,center );
+            String query = locationQuery( 10000 ,center );
 
             try {
-               // node = context.users( ).get(  ).withQuery( query );
+                //node = context.users( ).withQuery(query).get( );
             }
             catch ( UniformInterfaceException e ) {
                 JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) );
@@ -265,10 +251,43 @@ public class GeoPagingTest extends AbstractRestIT {
         }
     }
 
+    private JsonNode queryCollection(String collectionName,String query) throws IOException {
+        JsonNode node = null;
+        try {
+            node = context.collection( collectionName ).withQuery( query ).get();
+        }
+        catch ( UniformInterfaceException e ) {
+            JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) );
+            fail( node.get( "error" ).textValue() );
+        }
+
+        assertNotNull( node );
+        return node;
+    }
+
+    private void createGeoUser(String username,String collectionName,Double lat, Double lon ) throws IOException {
+
+        JsonNode node = null;
+
 
+        Map<String,Object> user = entityMapLocationCreator( lat, lon);
+        user.put( "name", username );
 
+        try {
+            node = context.collection( collectionName ).post( user );
+        }
+        catch ( UniformInterfaceException e ) {
+            JsonNode nodeError = mapper.readTree( e.getResponse().getEntity( String.class ) );
+            fail( node.get( "error" ).textValue() );
+        }
+
+        assertNotNull( node );
+        assertEquals( username, node.get( "name" ).asText() );
+
+        context.refreshIndex();
+    }
 
-    private Map entityMapLocationCreator(Double lat, Double lon){
+    private Map<String, Object> entityMapLocationCreator(Double lat, Double lon){
         Map<String, Double> latLon = hashMap( "latitude", lat );
         latLon.put( "longitude", lon );
         Map<String, Object> entityData = new HashMap<String, Object>();
@@ -277,9 +296,9 @@ public class GeoPagingTest extends AbstractRestIT {
         return entityData;
     }
 
-    private Query locationQuery(int  metersAway, Point startingPoint){
-        return Query.fromQL( "select * where location within " + String.valueOf( metersAway ) + " of "
-                + startingPoint.getLat() + "," + startingPoint.getLon());
+    private String locationQuery(int  metersAway, Point startingPoint){
+        return  "select * where location within " + String.valueOf( metersAway ) + " of "
+                + startingPoint.getLat() + "," + startingPoint.getLon();
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e9db18d/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java
index f1608b2..24a05e7 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/TestContext.java
@@ -213,6 +213,26 @@ public class TestContext {
         return createNewOrgAndUser().loginUser().createAppForOrg();
     }
 
+    public void refreshIndex() {
+
+        logger.debug("Refreshing index for app {}/{}", testOrganization.getOrgName(), appName );
+
+        try {
+
+            root().resource().path( "/refreshindex" )
+                  .queryParam( "org_name", testOrganization.getOrgName() )
+                  .queryParam( "app_name", appName )
+                  .accept( MediaType.APPLICATION_JSON )
+                  .post();
+
+        } catch ( Exception e) {
+            logger.debug("Error refreshing index", e);
+            return;
+        }
+
+        logger.debug("Refreshed index for app {}/{}", testOrganization.getOrgName(), appName );
+    }
+
     private void refreshIndex(String orgName, String appName) {
 
         logger.debug("Refreshing index for app {}/{}", orgName, appName );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e9db18d/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java
index 3a9181a..8649bed 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/ValueResource.java
@@ -94,7 +94,7 @@ public abstract class ValueResource extends NamedResource {
 
 
     /** post to the entity set */
-    //TODO: fix error reporting 
+    //TODO: fix error reporting
     protected JsonNode postInternal( Map<String, ?> entity ) throws IOException {
 
         return mapper.readTree( jsonMedia( withParams( withToken( resource() ) ) ).post( String.class, entity ));
@@ -219,6 +219,7 @@ public abstract class ValueResource extends NamedResource {
     }
 
 
+    //TODO: make query a chaining command, not just an immediate get.
     public JsonNode query( String query, String addition, String numAddition ) throws IOException {
         return getInternal( query, addition, numAddition );
     }


[5/9] incubator-usergrid git commit: Added additional GeoTest. Added uuid to collection names to prevent collisions ( however unlikely )

Posted by sn...@apache.org.
Added additional GeoTest. Added uuid to collection names to prevent collisions ( however unlikely )


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

Branch: refs/heads/two-dot-o-events
Commit: d5616f61c92eab3130e48b3546f00d1478591254
Parents: 6e9db18
Author: grey <gr...@apigee.com>
Authored: Thu Nov 20 16:49:33 2014 -0800
Committer: grey <gr...@apigee.com>
Committed: Thu Nov 20 16:49:33 2014 -0800

----------------------------------------------------------------------
 .../applications/queries/GeoPagingTest.java     | 62 +++++++++++++++-----
 1 file changed, 48 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d5616f61/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
index e9229ec..a3b4a93 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
@@ -34,6 +34,7 @@ import org.junit.Test;
 
 import org.apache.usergrid.persistence.geo.model.Point;
 import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.apache.usergrid.rest.AbstractRestIT;
 import org.apache.usergrid.rest.TestContextSetup;
 import org.apache.usergrid.rest.test.resource.CustomCollection;
@@ -145,16 +146,15 @@ public class GeoPagingTest extends AbstractRestIT {
 
     /**
      * Creates a store then queries to check ability to find different store from up to 40 mil meters away
-     * @throws IOException
      */
     @Test
     public void testFarAwayLocationFromCenter() throws IOException {
 
         JsonNode node = null;
-        String collectionName = "testFarAwayLocation";
+        String collectionName = "testFarAwayLocation" + UUIDUtils.newTimeUUID();
         Point center = new Point( 37.776753, -122.407846 );
 
-        String queryClose = locationQuery( 10000 ,center );
+        String queryClose = locationQuery( 10000, center );
         String queryFar = locationQuery( 40000000, center );
 
         //TODO: move test setup out of the test.
@@ -165,13 +165,43 @@ public class GeoPagingTest extends AbstractRestIT {
 
         /* run queries */
 
-        node = queryCollection( collectionName,queryClose );
+        node = queryCollection( collectionName, queryClose );
 
-        assertEquals("Results from nearby, should return nothing" ,0, node.get( "entities" ).size() );
+        assertEquals( "Results from nearby, should return nothing", 0, node.get( "entities" ).size() );
 
-        node = queryCollection( collectionName,queryFar );
+        node = queryCollection( collectionName, queryFar );
 
-        assertEquals("Results from center point to ridiculously far", 2, node.get( "entities" ).size() );
+        assertEquals( "Results from center point to ridiculously far", 2, node.get( "entities" ).size() );
+    }
+
+
+    /**
+     * Creates a store right on top of the center store and checks to see if we can find that store, then find both
+     * stores.
+     */
+    @Test
+    public void testFarAwayLocationWithOneResultCloser() throws IOException {
+        JsonNode node = null;
+        String collectionName = "testFarAwayLocation" + UUIDUtils.newTimeUUID();
+        Point center = new Point( -33.746369, 150.952183 );
+
+        String queryClose = locationQuery( 10000, center );
+        String queryFar = locationQuery( 40000000, center );
+
+        /*Create */
+        createGeoUser( "usergrid", collectionName, -33.746369, 150.952183 );
+
+        createGeoUser( "usergrid2", collectionName, -33.889058, 151.124024 );
+
+        /* run queries */
+
+        node = queryCollection( collectionName, queryClose );
+
+        assertEquals( "Results from nearby, should return 1 store", 1, node.get( "entities" ).size() );
+
+        node = queryCollection( collectionName, queryFar );
+
+        assertEquals( "Results from center point to ridiculously far", 2, node.get( "entities" ).size() );
     }
 
 
@@ -251,7 +281,8 @@ public class GeoPagingTest extends AbstractRestIT {
         }
     }
 
-    private JsonNode queryCollection(String collectionName,String query) throws IOException {
+
+    private JsonNode queryCollection( String collectionName, String query ) throws IOException {
         JsonNode node = null;
         try {
             node = context.collection( collectionName ).withQuery( query ).get();
@@ -265,12 +296,13 @@ public class GeoPagingTest extends AbstractRestIT {
         return node;
     }
 
-    private void createGeoUser(String username,String collectionName,Double lat, Double lon ) throws IOException {
+
+    private void createGeoUser( String username, String collectionName, Double lat, Double lon ) throws IOException {
 
         JsonNode node = null;
 
 
-        Map<String,Object> user = entityMapLocationCreator( lat, lon);
+        Map<String, Object> user = entityMapLocationCreator( lat, lon );
         user.put( "name", username );
 
         try {
@@ -287,7 +319,8 @@ public class GeoPagingTest extends AbstractRestIT {
         context.refreshIndex();
     }
 
-    private Map<String, Object> entityMapLocationCreator(Double lat, Double lon){
+
+    private Map<String, Object> entityMapLocationCreator( Double lat, Double lon ) {
         Map<String, Double> latLon = hashMap( "latitude", lat );
         latLon.put( "longitude", lon );
         Map<String, Object> entityData = new HashMap<String, Object>();
@@ -296,9 +329,10 @@ public class GeoPagingTest extends AbstractRestIT {
         return entityData;
     }
 
-    private String locationQuery(int  metersAway, Point startingPoint){
-        return  "select * where location within " + String.valueOf( metersAway ) + " of "
-                + startingPoint.getLat() + "," + startingPoint.getLon();
+
+    private String locationQuery( int metersAway, Point startingPoint ) {
+        return "select * where location within " + String.valueOf( metersAway ) + " of " + startingPoint.getLat() + ","
+                + startingPoint.getLon();
     }
 
 


[8/9] incubator-usergrid git commit: Fix merge issue.

Posted by sn...@apache.org.
Fix merge issue.


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

Branch: refs/heads/two-dot-o-events
Commit: c69f0ec33ab4683ded8738f95ff50ffd6c521451
Parents: ee260cc
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Nov 24 09:32:15 2014 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Nov 24 09:32:15 2014 -0500

----------------------------------------------------------------------
 .../persistence/index/impl/EsEntityIndexBatchImpl.java    | 10 +---------
 .../usergrid/persistence/index/impl/IndexingUtils.java    |  5 +----
 2 files changed, 2 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c69f0ec3/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index 6e68791..b099678 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@ -29,14 +29,7 @@ import java.util.UUID;
 import org.elasticsearch.action.bulk.BulkItemResponse;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
 import org.elasticsearch.action.bulk.BulkResponse;
-import org.elasticsearch.action.deletebyquery.DeleteByQueryRequest;
-import org.elasticsearch.action.deletebyquery.DeleteByQueryRequestBuilder;
-import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse;
 import org.elasticsearch.client.Client;
-import org.elasticsearch.index.query.FilterBuilders;
-import org.elasticsearch.index.query.FilteredQueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.index.query.TermQueryBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,9 +59,8 @@ import org.apache.usergrid.persistence.model.field.value.EntityObject;
 
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ANALYZED_STRING_PREFIX;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.BOOLEAN_PREFIX;
+import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITYID_ID_FIELDNAME;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITY_CONTEXT_FIELDNAME;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITY_ID_FIELDNAME;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITY_VERSION_FIELDNAME;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.GEO_PREFIX;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.NUMBER_PREFIX;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.STRING_PREFIX;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c69f0ec3/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 4319ce4..30b05e4 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
@@ -47,10 +47,7 @@ public class IndexingUtils {
 
     public static final String ENTITY_CONTEXT_FIELDNAME = "ug_context";
 
-    public static final String ENTITY_ID_FIELDNAME = "ug_entityId";
-
-    public static final String ENTITY_VERSION_FIELDNAME = "ug_entityVersion";
-
+    public static final String ENTITYID_ID_FIELDNAME = "ug_entityId";
 
 
     /**