usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject [1/2] usergrid git commit: Fix issue with null values nested in an entity list field being represented as a top-level entity NullField instead of a null value.
Date Sun, 24 Jan 2016 02:02:24 GMT
Repository: usergrid
Updated Branches:
  refs/heads/master 78727e18c -> 40be90f5e


Fix issue with null values nested in an entity list field being represented as a top-level
entity NullField instead of a null value.


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

Branch: refs/heads/master
Commit: 595955dff9ee4a706de9d97b86c5f0636fe24b43
Parents: 2e37c21
Author: Michael Russo <michaelarusso@gmail.com>
Authored: Sat Jan 23 17:34:54 2016 -0800
Committer: Michael Russo <michaelarusso@gmail.com>
Committed: Sat Jan 23 17:34:54 2016 -0800

----------------------------------------------------------------------
 .../corepersistence/CpEntityMapUtilsTest.java   | 28 +++++++++++++-
 .../model/entity/MapToEntityConverter.java      | 39 +++++++++-----------
 .../model/entity/MapToEntityConverterTest.java  |  4 +-
 3 files changed, 44 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/595955df/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 b53f7ae..a636821 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
@@ -21,7 +21,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
-import junit.framework.Assert;
 import org.apache.usergrid.corepersistence.util.CpEntityMapUtils;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
@@ -38,7 +37,6 @@ import java.io.IOException;
 import java.util.*;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 
@@ -245,4 +243,30 @@ public class CpEntityMapUtilsTest {
         assertEquals("fred", entityObject.getField("name").getValue());
     }
 
+    @Test
+    public void testNullSerialization() throws IOException {
+
+        Map<String, Object> properties = new HashMap<>();
+
+        List<Object> array = new ArrayList<>();
+        array.add(null);
+        array.add("test");
+
+        properties.put("array", array);
+
+        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 );
+
+        assertTrue( entity.getField("array") instanceof ListField );
+        assertTrue( entity.getField("array").getValue() instanceof List );
+        List arrayReturned = (List) entity.getField("array").getValue();
+
+        assertEquals( null, arrayReturned.get(0) );
+        assertEquals( "test", arrayReturned.get(1) );
+
+
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/595955df/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 7610489..fb19963 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
@@ -32,6 +32,7 @@ import java.nio.ByteBuffer;
 import java.util.*;
 
 public class MapToEntityConverter{
+
     public static final Logger logger = LoggerFactory.getLogger(MapToEntityConverter.class);
 
     private final JsonFactory jsonFactory = new JsonFactory();
@@ -60,7 +61,6 @@ public class MapToEntityConverter{
 
         }
 
-
         return entity;
     }
 
@@ -84,17 +84,12 @@ public class MapToEntityConverter{
 
                 returnList.add( processListForListField( fieldName, (List) sample ) );
 
-            } else if ( sample != null ) {
-
-                returnList.add( sample );
-
             } else {
 
-                returnList.add( new NullField(fieldName) );
+                returnList.add( sample );
 
             }
 
-
         });
 
 
@@ -123,38 +118,32 @@ public class MapToEntityConverter{
 
                     newList.add(o);
 
-//                    if (o instanceof List) {
-//                        newList.add( processField( fieldName, (List) o, false));
-//                    } else {
-//                        newList.add(o);
-//                    }
-
                 }
 
             } else {
 
                 newList.add( sample );
-            }
 
+            }
 
         });
 
         return newList;
 
-
     }
 
 
     private Field processMapValue( Object value, String fieldName) {
 
         // check to see if the map is truly a location object
-        if ("location" .equals(fieldName.toString().toLowerCase()) ) {
+        if ( locationKey.equalsIgnoreCase(fieldName) ) {
+
             return processLocationField((Map<String, Object>) value, fieldName);
-        } else {
 
+        } else {
 
-            // not a location element, process it as map
-           return processMapField( value, fieldName);
+            // not a location element, process it as a normal map
+            return processMapField( value, fieldName);
         }
     }
 
@@ -164,6 +153,7 @@ public class MapToEntityConverter{
         return new EntityObjectField( fieldName, fromMap( (Map<String, Object>)value,
false));
     }
 
+
     /**
      * for location we need to parse two formats potentially and convert to a typed field
      */
@@ -269,22 +259,27 @@ public class MapToEntityConverter{
 
         } else if ( value == null ){
 
+            // not supported from outside API yet, but let's keep it in serialization it's
a handled in this logic
             processedField = new NullField( fieldName, unique );
 
         } else {
+
             byte[] valueSerialized;
             try {
+
                 valueSerialized = objectMapper.writeValueAsBytes( value );
+
             }
             catch ( JsonProcessingException e ) {
+
                 throw new RuntimeException( "Can't serialize object ",e );
+
             }
 
             ByteBuffer byteBuffer = ByteBuffer.wrap(valueSerialized);
-            ByteArrayField bf = new ByteArrayField( fieldName, byteBuffer.array(), value.getClass()
);
-            processedField = bf;
-        }
+            processedField = new ByteArrayField( fieldName, byteBuffer.array(), value.getClass()
);
 
+        }
 
         return processedField;
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/595955df/stack/corepersistence/model/src/test/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverterTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/test/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverterTest.java
b/stack/corepersistence/model/src/test/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverterTest.java
index acc8cfd..b06d8f6 100644
--- a/stack/corepersistence/model/src/test/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverterTest.java
+++ b/stack/corepersistence/model/src/test/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverterTest.java
@@ -139,9 +139,7 @@ public class MapToEntityConverterTest {
 
         List arrayReturned = (List) entity.getField("arrayNullValues").getValue();
 
-        Field convertedMapValue = (Field) arrayReturned.get(0);
-
-        assertTrue( convertedMapValue.getTypeName() == FieldTypeName.NULL);
+        assertTrue( arrayReturned.get(0) == null);
     }
 
     @Test


Mime
View raw message