← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15762: use new class FieldMap (forwarding map) instead of Map<String, Map> in filterservice and parserse...

 

------------------------------------------------------------
revno: 15762
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-06-19 12:51:49 +0200
message:
  use new class FieldMap (forwarding map) instead of Map<String, Map> in filterservice and parserservice
added:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldMap.java
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFieldFilterService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultParserService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ParserService.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFieldFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFieldFilterService.java	2014-06-17 15:28:24 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFieldFilterService.java	2014-06-19 10:51:49 +0000
@@ -31,7 +31,6 @@
 import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.node.types.CollectionNode;
@@ -45,7 +44,6 @@
 
 import java.util.Collection;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -76,19 +74,19 @@
 
         Schema rootSchema = schemaService.getDynamicSchema( klass );
 
-        Map<String, Map> fieldMap = Maps.newHashMap();
+        FieldMap fieldMap = new FieldMap();
         Schema schema = schemaService.getDynamicSchema( objects.get( 0 ).getClass() );
 
         if ( fields == null )
         {
             for ( Property property : schema.getProperties() )
             {
-                fieldMap.put( property.getName(), Maps.newHashMap() );
+                fieldMap.put( property.getName(), new FieldMap() );
             }
         }
         else
         {
-            fieldMap = parserService.parsePropertyFilter( fields );
+            fieldMap = parserService.parseFieldFilter( fields );
         }
 
         CollectionNode collectionNode = new CollectionNode( rootSchema.getCollectionName() );
@@ -103,7 +101,7 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    private ComplexNode buildComplexNode( Map<String, Map> fieldMap, Class<?> klass, Object object )
+    private ComplexNode buildComplexNode( FieldMap fieldMap, Class<?> klass, Object object )
     {
         Schema schema = schemaService.getDynamicSchema( klass );
 
@@ -129,7 +127,7 @@
             Object returnValue = ReflectionUtils.invokeMethod( object, property.getGetterMethod() );
             Schema propertySchema = schemaService.getDynamicSchema( property.getKlass() );
 
-            Map fieldValue = fieldMap.get( fieldKey );
+            FieldMap fieldValue = fieldMap.get( fieldKey );
 
             if ( property.isCollection() )
             {
@@ -160,7 +158,7 @@
                     }
                     else if ( !property.isSimple() )
                     {
-                        Map<String, Map> map = getFullFieldMap( schemaService.getDynamicSchema( property.getItemKlass() ) );
+                        FieldMap map = getFullFieldMap( schemaService.getDynamicSchema( property.getItemKlass() ) );
 
                         for ( Object collectionObject : collection )
                         {
@@ -233,14 +231,14 @@
         return complexNode;
     }
 
-    private void updateFields( Map<String, Map> fieldMap, Class<?> klass )
+    private void updateFields( FieldMap fieldMap, Class<?> klass )
     {
         // we need two run this (at least) two times, since some of the presets might contain other presets
         _updateFields( fieldMap, klass, true );
         _updateFields( fieldMap, klass, false );
     }
 
-    private void _updateFields( Map<String, Map> fieldMap, Class<?> klass, boolean expandOnly )
+    private void _updateFields( FieldMap fieldMap, Class<?> klass, boolean expandOnly )
     {
         Schema schema = schemaService.getDynamicSchema( klass );
         List<String> cleanupFields = Lists.newArrayList();
@@ -253,7 +251,7 @@
                 {
                     if ( !fieldMap.containsKey( mapKey ) )
                     {
-                        fieldMap.put( mapKey, Maps.newHashMap() );
+                        fieldMap.put( mapKey, new FieldMap() );
                     }
                 }
 
@@ -272,7 +270,7 @@
                 {
                     if ( !fieldMap.containsKey( field ) )
                     {
-                        fieldMap.put( field, Maps.newHashMap() );
+                        fieldMap.put( field, new FieldMap() );
                     }
                 }
 
@@ -295,16 +293,16 @@
         }
     }
 
-    private Map<String, Map> getFullFieldMap( Schema schema )
+    private FieldMap getFullFieldMap( Schema schema )
     {
-        Map<String, Map> map = Maps.newHashMap();
+        FieldMap fieldMap = new FieldMap();
 
         for ( String mapKey : schema.getPropertyMap().keySet() )
         {
-            map.put( mapKey, Maps.newHashMap() );
+            fieldMap.put( mapKey, new FieldMap() );
         }
 
-        return map;
+        return fieldMap;
     }
 
     private ComplexNode getProperties( Property currentProperty, Object object, List<String> fields )

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultParserService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultParserService.java	2014-06-09 10:26:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultParserService.java	2014-06-19 10:51:49 +0000
@@ -29,11 +29,9 @@
  */
 
 import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import org.apache.commons.lang.StringUtils;
 
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -68,10 +66,10 @@
     }
 
     @Override
-    public Map<String, Map> parsePropertyFilter( String fields )
+    public FieldMap parseFieldFilter( String fields )
     {
         List<String> prefixList = Lists.newArrayList();
-        Map<String, Map> parsed = Maps.newHashMap();
+        FieldMap fieldMap = new FieldMap();
 
         StringBuilder builder = new StringBuilder();
 
@@ -79,7 +77,7 @@
         {
             if ( c.equals( "," ) )
             {
-                putInMap( parsed, joinedWithPrefix( builder, prefixList ) );
+                putInMap( fieldMap, joinedWithPrefix( builder, prefixList ) );
                 builder = new StringBuilder();
                 continue;
             }
@@ -95,7 +93,7 @@
             {
                 if ( !builder.toString().isEmpty() )
                 {
-                    putInMap( parsed, joinedWithPrefix( builder, prefixList ) );
+                    putInMap( fieldMap, joinedWithPrefix( builder, prefixList ) );
                 }
 
                 prefixList.remove( prefixList.size() - 1 );
@@ -111,10 +109,10 @@
 
         if ( !builder.toString().isEmpty() )
         {
-            putInMap( parsed, joinedWithPrefix( builder, prefixList ) );
+            putInMap( fieldMap, joinedWithPrefix( builder, prefixList ) );
         }
 
-        return parsed;
+        return fieldMap;
     }
 
     private String joinedWithPrefix( StringBuilder builder, List<String> prefixList )
@@ -125,7 +123,7 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    private void putInMap( Map<String, Map> map, String path )
+    private void putInMap( FieldMap fieldMap, String path )
     {
         if ( StringUtils.isEmpty( path ) )
         {
@@ -134,12 +132,12 @@
 
         for ( String p : path.split( "\\." ) )
         {
-            if ( map.get( p ) == null )
+            if ( fieldMap.get( p ) == null )
             {
-                map.put( p, Maps.newHashMap() );
+                fieldMap.put( p, new FieldMap() );
             }
 
-            map = map.get( p );
+            fieldMap = fieldMap.get( p );
         }
     }
 }

=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldMap.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldMap.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldMap.java	2014-06-19 10:51:49 +0000
@@ -0,0 +1,48 @@
+package org.hisp.dhis.dxf2.filter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+import com.google.common.collect.ForwardingMap;
+import com.google.common.collect.Maps;
+
+import java.util.Map;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class FieldMap extends ForwardingMap<String, FieldMap>
+{
+    private final Map<String, FieldMap> delegate = Maps.newHashMap();
+
+    @Override
+    protected Map<String, FieldMap> delegate()
+    {
+        return delegate;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ParserService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ParserService.java	2014-04-14 06:43:16 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ParserService.java	2014-06-19 10:51:49 +0000
@@ -29,7 +29,6 @@
  */
 
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -45,10 +44,11 @@
     Filters parseObjectFilter( List<String> filters );
 
     /**
-     * Parses and writes out map with included/excluded properties.
+     * Parses and writes out fieldMap with included/excluded properties.
      *
      * @param filter String to parse, can be used for both inclusion/exclusion
-     * @return Map with property name as key, and another map as value (recursive)
+     * @return FieldMap with property name as key, and another FieldMap as value (recursive)
+     * @see org.hisp.dhis.dxf2.filter.FieldMap
      */
-    Map<String, Map> parsePropertyFilter( String filter );
+    FieldMap parseFieldFilter( String filter );
 }