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 2015/08/25 23:41:22 UTC
[1/2] usergrid git commit: Ensure we persist entities with nested
arrays. The nested data will be serialized as binary and not specifically
typed.
Repository: usergrid
Updated Branches:
refs/heads/two-dot-o-dev 2303eeac8 -> ac9da14ba
Ensure we persist entities with nested arrays. The nested data will be serialized as binary and not specifically typed.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/2391bfd0
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/2391bfd0
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/2391bfd0
Branch: refs/heads/two-dot-o-dev
Commit: 2391bfd09d69c2797e440beb638d8bfa3532df4f
Parents: 7318607
Author: Michael Russo <mi...@gmail.com>
Authored: Tue Aug 25 13:36:24 2015 -0700
Committer: Michael Russo <mi...@gmail.com>
Committed: Tue Aug 25 13:36:24 2015 -0700
----------------------------------------------------------------------
.../corepersistence/CpEntityMapUtilsTest.java | 79 ++++++++++++++++++++
.../model/entity/MapToEntityConverter.java | 10 ++-
2 files changed, 88 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/2391bfd0/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 5d492a0..1656fa6 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
@@ -69,6 +69,37 @@ public class CpEntityMapUtilsTest {
assertUserWithBlocks( cpEntity );
}
+ @Test
+ public void testNestedArrayToMap() {
+
+ /*** This tests example property input of
+
+ {
+ "nestedarray" : [ [ "fred" ] ]
+ }
+
+ ****/
+
+ Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+ put( "nestedarray",
+ new ArrayList<ArrayList<String>>() {{
+ add(0, new ArrayList<String>() {{
+ add(0, "fred");
+ }});
+ }}
+ );
+ put( "block", new ArrayList<Object>() {{
+ add( new LinkedHashMap<String, Object>() {{ put("name", "fred"); }});
+ add( new LinkedHashMap<String, Object>() {{ put("name", "gertrude"); }});
+ add( new LinkedHashMap<String, Object>() {{ put("name", "mina"); }});
+ }});
+ }};
+
+ Entity cpEntity = CpEntityMapUtils.fromMap( properties, "user", true );
+ assertUserWithBlocks( cpEntity );
+ }
+
+
@Test
public void testSerialization() throws JsonProcessingException, IOException {
@@ -112,6 +143,54 @@ public class CpEntityMapUtilsTest {
}
+ @Test
+ public void testNestedArraySerialization() throws JsonProcessingException, IOException {
+
+ /*** This tests example property input of
+
+ {
+ "nestedarray" : [ [ "fred" ] ]
+ }
+
+ ****/
+
+ Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+ put( "nestedarray",
+ new ArrayList<ArrayList<String>>() {{
+ add(0, new ArrayList<String>() {{
+ add(0, "fred");
+ }});
+ }}
+ );
+ put( "block", new ArrayList<Object>() {{
+ add( new LinkedHashMap<String, Object>() {{ put("name", "fred"); }});
+ add( new LinkedHashMap<String, Object>() {{ put("name", "gertrude"); }});
+ add( new LinkedHashMap<String, Object>() {{ put("name", "mina"); }});
+ }});
+ }};
+
+ org.apache.usergrid.persistence.model.entity.Entity entity =
+ new org.apache.usergrid.persistence.model.entity.Entity(
+ new SimpleId( "user" ) );
+ entity = CpEntityMapUtils.fromMap( entity, properties, null, true );
+
+ assertUserWithBlocks( entity );
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationFeature.INDENT_OUTPUT);
+ mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT, "@class");
+
+ String entityString = mapper.writeValueAsString( entity );
+ //log.debug("Serialized to JSON: " + entityString );
+
+ TypeReference<Entity> tr = new TypeReference<Entity>() {};
+ entity = mapper.readValue( entityString, tr );
+ //log.debug("Round-tripped entity: " + CpEntityMapUtils.toMap(entity) );
+
+ assertUserWithBlocks( entity );
+ }
+
+
private void assertUserWithBlocks( org.apache.usergrid.persistence.model.entity.Entity e ) {
assertTrue( e.getField("block") instanceof ListField );
http://git-wip-us.apache.org/repos/asf/usergrid/blob/2391bfd0/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 79f8973..323d424 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
@@ -145,7 +145,15 @@ public class MapToEntityConverter{
return newList;
} else if ( sample instanceof List ) {
- return processListForField( list ); // recursion
+ List<Object> newList = new ArrayList<Object>();
+ for (Object o : list) {
+ if (o instanceof List) {
+ newList.add(processListForField((List) o));
+ } else {
+ newList.add(o);
+ }
+ }
+ return newList;
} else {
return list;
[2/2] usergrid git commit: Merge branch 'pr/354' into two-dot-o-dev.
This closes #354.
Posted by sn...@apache.org.
Merge branch 'pr/354' into two-dot-o-dev. This closes #354.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/ac9da14b
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/ac9da14b
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/ac9da14b
Branch: refs/heads/two-dot-o-dev
Commit: ac9da14ba21921e9727700bb122401c4562b98dc
Parents: 2303eea 2391bfd
Author: Dave Johnson <sn...@apache.org>
Authored: Tue Aug 25 17:40:48 2015 -0400
Committer: Dave Johnson <sn...@apache.org>
Committed: Tue Aug 25 17:40:48 2015 -0400
----------------------------------------------------------------------
.../corepersistence/CpEntityMapUtilsTest.java | 79 ++++++++++++++++++++
.../model/entity/MapToEntityConverter.java | 10 ++-
2 files changed, 88 insertions(+), 1 deletion(-)
----------------------------------------------------------------------