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/03/31 21:14:49 UTC

incubator-usergrid git commit: add list conversion method

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-526 04058383e -> b07d2a07b


add list conversion method


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

Branch: refs/heads/USERGRID-526
Commit: b07d2a07b733bab1c7ed8cb72a1e0bcad9b1dfb9
Parents: 0405838
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Mar 31 13:11:08 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Mar 31 13:11:08 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/util/CpEntityMapUtils.java  |  8 +-
 .../model/entity/EntityToMapConverter.java      |  5 --
 .../persistence/model/field/SetField.java       | 56 --------------
 .../index/impl/EntityToMapConverter.java        | 77 +++++++++++++-------
 .../index/impl/EntityIndexMapUtils.java         |  8 +-
 5 files changed, 54 insertions(+), 100 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b07d2a07/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java
index 6eb1b0c..0a49043 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java
@@ -44,7 +44,6 @@ import org.apache.usergrid.persistence.model.field.IntegerField;
 import org.apache.usergrid.persistence.model.field.ListField;
 import org.apache.usergrid.persistence.model.field.LocationField;
 import org.apache.usergrid.persistence.model.field.LongField;
-import org.apache.usergrid.persistence.model.field.SetField;
 import org.apache.usergrid.persistence.model.field.StringField;
 import org.apache.usergrid.persistence.model.field.UUIDField;
 import org.apache.usergrid.persistence.model.field.value.EntityObject;
@@ -289,12 +288,7 @@ public class CpEntityMapUtils {
                 entityMap.put(field.getName(),
                         new ArrayList( processCollectionForMap(list)));
 
-            } else if (f instanceof SetField) {
-                Set set = (Set) field.getValue();
-                entityMap.put(field.getName(),
-                        new ArrayList( processCollectionForMap(set)));
-
-            } else if (f instanceof EntityObjectField) {
+            }else if (f instanceof EntityObjectField) {
                 EntityObject eo = (EntityObject) field.getValue();
                 entityMap.put( field.getName(), toMap(eo)); // recursion
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b07d2a07/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java
index 6b36af7..8617c82 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java
@@ -57,11 +57,6 @@ public class EntityToMapConverter{
                 entityMap.put(field.getName(),
                         new ArrayList( processCollectionForMap(list)));
 
-            } else if (f instanceof SetField) {
-                Set set = (Set) field.getValue();
-                entityMap.put(field.getName(),
-                        new ArrayList( processCollectionForMap(set)));
-
             } else if (f instanceof EntityObjectField) {
                 EntityObject eo = (EntityObject) field.getValue();
                 entityMap.put( field.getName(), toMap(eo)); // recursion

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b07d2a07/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SetField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SetField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SetField.java
deleted file mode 100644
index 47a9c7c..0000000
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SetField.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.persistence.model.field;
-
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-/**
- * An object field that represents a set of objects
- */
-public class SetField<T> extends AbstractField<Set<T>> {
-
-    /**
-     * Constructor that initializes with an empty set for adding to later
-     */
-    public SetField( String name ) {
-        super( name, new LinkedHashSet<T>() );
-    }
-
-    public SetField( String name, Set<T> set ) {
-        super( name, set );
-    }
-
-    public SetField() {
-        super();
-    }
-
-    /**
-     * Add an entry to the set
-     */
-    public void addEntry( T setItem ) {
-        value.add( setItem );
-    }
-
-
-    @Override
-    public FieldTypeName getTypeName() {
-                return FieldTypeName.SET;
-            }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b07d2a07/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
index fdd9b92..64a0ab6 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
@@ -37,7 +37,7 @@ public class EntityToMapConverter {
      * @param context The context this entity appears in
      */
     public static Map convert(ApplicationScope applicationScope, final Entity entity, final String context ) {
-        final Map entityMap = entityToMap( entity );
+        final Map entityMap = entityToMap( entity, true );
 
         //add the context for filtering later
         entityMap.put( ENTITY_CONTEXT_FIELDNAME, context );
@@ -62,7 +62,7 @@ public class EntityToMapConverter {
      * bu_ - Boolean field
      * </pre>
      */
-    private static Map entityToMap( EntityObject entity ) {
+    private static Map entityToMap( EntityObject entity, boolean rootLevel ) {
 
         Map<String, Object> entityMap = new HashMap<String, Object>();
 
@@ -71,31 +71,12 @@ public class EntityToMapConverter {
             Field field = ( Field ) f;
 
 
-            if ( f instanceof ArrayField) {
-                List list = ( List ) field.getValue();
-                entityMap.put(  field.getName().toLowerCase(),
-                        new ArrayList( processCollectionForMap( list ) ) );
-            }
-            else if ( f instanceof ListField) {
-                List list = ( List ) field.getValue();
-                entityMap.put(field.getName().toLowerCase(),
-                        new ArrayList( processCollectionForMap( list ) ) );
-
-                if ( !list.isEmpty() ) {
-                    if ( list.get( 0 ) instanceof String ) {
-                        entityMap.put( ANALYZED_STRING_PREFIX + 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 ) ) );
+            if ( f instanceof ListField) {
+                putList(entityMap, field, ( List ) field.getValue(),rootLevel);
             }
             else if ( f instanceof EntityObjectField) {
                 EntityObject eo = ( EntityObject ) field.getValue();
-                entityMap.put(EO_PREFIX + field.getName().toLowerCase(), entityToMap(eo) ); // recursion
+                entityMap.put(EO_PREFIX + field.getName().toLowerCase(), entityToMap(eo,false) ); // recursion
             }
             else if ( f instanceof StringField ) {
 
@@ -137,6 +118,52 @@ public class EntityToMapConverter {
         return entityMap;
     }
 
+    private static void putList(Map<String, Object> entityMap, Field field, List list, boolean isRootLevel) {
+        if ( !list.isEmpty() ) {
+            if(isRootLevel) {
+                Object o = list.get(0);
+
+                if (o instanceof String) {
+                    entityMap.put(ANALYZED_STRING_PREFIX + field.getName().toLowerCase(),
+                        new ArrayList(processCollectionForMap(list)));
+                    return;
+                }
+                if (o instanceof Boolean) {
+                    entityMap.put(BOOLEAN_PREFIX + field.getName().toLowerCase(),
+                        new ArrayList(processCollectionForMap(list)));
+                    return;
+                }
+                if (o instanceof Long || o instanceof Integer) {
+                    entityMap.put(LONG_PREFIX + field.getName().toLowerCase(),
+                        new ArrayList(processCollectionForMap(list)));
+                    return;
+                }
+
+                if (o instanceof Double || o instanceof Float) {
+                    entityMap.put(DOUBLE_PREFIX + field.getName().toLowerCase(),
+                        new ArrayList(processCollectionForMap(list)));
+                    return;
+                }
+
+                if (o instanceof String) {
+                    entityMap.put(ANALYZED_STRING_PREFIX + field.getName().toLowerCase(),
+                        new ArrayList(processCollectionForMap(list)));
+                    return;
+                }
+
+                if (o instanceof Entity) {
+                    entityMap.put(field.getName().toLowerCase(),
+                        new ArrayList(processCollectionForMap(list)));
+                    return;
+                }
+            }
+            //else
+            entityMap.put(field.getName().toLowerCase(), new ArrayList(processCollectionForMap(list)));
+
+        }
+
+    }
+
 
     private static Collection processCollectionForMap( final Collection c ) {
         if ( c.isEmpty() ) {
@@ -148,7 +175,7 @@ public class EntityToMapConverter {
         if ( sample instanceof Entity ) {
             for ( Object o : c.toArray() ) {
                 Entity e = ( Entity ) o;
-                processed.add( entityToMap( e ) );
+                processed.add( entityToMap( e,false ) );
             }
         }
         else if ( sample instanceof List ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b07d2a07/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexMapUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexMapUtils.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexMapUtils.java
index 869aeac..34a8cd4 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexMapUtils.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexMapUtils.java
@@ -42,7 +42,6 @@ import org.apache.usergrid.persistence.model.field.IntegerField;
 import org.apache.usergrid.persistence.model.field.ListField;
 import org.apache.usergrid.persistence.model.field.LocationField;
 import org.apache.usergrid.persistence.model.field.LongField;
-import org.apache.usergrid.persistence.model.field.SetField;
 import org.apache.usergrid.persistence.model.field.StringField;
 import org.apache.usergrid.persistence.model.field.UUIDField;
 import org.apache.usergrid.persistence.model.field.value.EntityObject;
@@ -232,12 +231,7 @@ class EntityIndexMapUtils {
                 entityMap.put(field.getName(),
                         new ArrayList(processCollectionForMap(list)));
 
-            } else if (f instanceof SetField) {
-                Set set = (Set) field.getValue();
-                entityMap.put(field.getName(),
-                        new ArrayList(processCollectionForMap(set)));
-
-            } else if (f instanceof EntityObjectField) {
+            }  else if (f instanceof EntityObjectField) {
                 EntityObject eo = (EntityObject) field.getValue();
                 entityMap.put(field.getName(), toMap(eo)); // recursion