You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/09/14 22:05:01 UTC
[2/2] usergrid git commit: change location to entity field
change location to entity field
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/6f0bf9ec
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/6f0bf9ec
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/6f0bf9ec
Branch: refs/heads/USERGRID-1015
Commit: 6f0bf9eccbeb2052e1bce4992edb182a97fd3c2a
Parents: 001a7e3
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Sep 14 14:04:18 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Sep 14 14:04:18 2015 -0600
----------------------------------------------------------------------
.../corepersistence/CpEntityMapUtilsTest.java | 4 +-
.../org/apache/usergrid/persistence/GeoIT.java | 52 +++++++++++++++++++-
.../model/entity/MapToEntityConverter.java | 4 --
3 files changed, 53 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f0bf9ec/stack/core/src/test/java/org/apache/usergrid/corepersistence/CpEntityMapUtilsTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/CpEntityMapUtilsTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/CpEntityMapUtilsTest.java
index 325e51f..b53f7ae 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/CpEntityMapUtilsTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/CpEntityMapUtilsTest.java
@@ -133,14 +133,14 @@ public class CpEntityMapUtilsTest {
cpEntity = CpEntityMapUtils.fromMap(properties, "loc", true);
- assertNull(cpEntity.getFieldMap().get("location"));
+ assertTrue(cpEntity.getFieldMap().get("location") instanceof EntityObjectField);
properties = new LinkedHashMap<String, Object>();
properties.put("location", "denver");
cpEntity = CpEntityMapUtils.fromMap(properties, "loc", true);
- assertNull(cpEntity.getFieldMap().get("location") );
+ assertTrue(cpEntity.getFieldMap().get("location") instanceof StringField);
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f0bf9ec/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 8d71826..230f9be 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
@@ -33,7 +33,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;
public class GeoIT extends AbstractCoreIT {
@@ -252,6 +252,56 @@ public class GeoIT extends AbstractCoreIT {
}
@Test
+ public void testNonGeolocationEntities() throws Exception {
+ //1. load test entities
+ EntityManager em = app.getEntityManager();
+ assertNotNull(em);
+
+ List<Map<String, Object>> locations =
+ new ArrayList<Map<String, Object>>();
+
+
+ locations.add(new LinkedHashMap<String, Object>() {{
+ put("name", "norwest");
+ put("location", "texas");
+ }});
+ locations.add(new LinkedHashMap<String, Object>() {{
+ put("type", "store");
+ put("name", "ashfield");
+ put("location", "new jersey");
+ }});
+
+ //2. load test entities
+ for (Map<String, Object> location : locations) {
+ Entity entity = em.create("store", location);
+ assertNotNull(entity);
+ LOG.debug("Entity {} created", entity.getProperty("name"));
+ }
+ app.refreshIndex();
+ //2. validate the size of the result
+ Query query = new Query();
+ Results listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
+ assertEquals("total number of 'stores'", locations.size(), listResults.size());
+ //3. verify each entity has geo data
+ for (Entity entity : listResults.entities) {
+ Object location = entity.getProperty("location");
+ assertNotNull(location);
+ assertTrue(location instanceof String);
+ }
+
+ query = Query.fromQL("select * where location='texas'");
+ listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
+ assertEquals("total number of 'stores'", 1, listResults.size());
+ //3. verify each entity has geo data
+ for (Entity entity : listResults.entities) {
+ Object location = entity.getProperty("location");
+ assertNotNull(location);
+ assertTrue(location instanceof String);
+ }
+
+ }
+
+ @Test
/**
* Load entities with location data and query them from a far away location
* 1. create entities with geo
http://git-wip-us.apache.org/repos/asf/usergrid/blob/6f0bf9ec/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverter.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverter.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverter.java
index c0db81b..2357a57 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverter.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverter.java
@@ -56,10 +56,6 @@ public class MapToEntityConverter{
Object value = map.get( fieldName );
boolean unique = schemaManager == null ? topLevel : topLevel && schemaManager.isPropertyUnique(entityType, fieldName);
//cannot store fields that aren't locations
- if(fieldName.toLowerCase().equals(locationKey) && !(value instanceof Map)) {
- logger.warn("can't map entity with location field");
- continue;
- }
if ( value instanceof String ) {
String stringValue =(String)value;