← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15523: use SchemaService instead of PropertyIntrospectorService in DefaultFilterService

 

------------------------------------------------------------
revno: 15523
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-06-02 23:07:50 +0200
message:
  use SchemaService instead of PropertyIntrospectorService in DefaultFilterService
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.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/DefaultFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java	2014-05-13 09:15:36 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java	2014-06-02 21:07:50 +0000
@@ -33,7 +33,8 @@
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.dxf2.filter.ops.Op;
 import org.hisp.dhis.schema.Property;
-import org.hisp.dhis.schema.PropertyIntrospectorService;
+import org.hisp.dhis.schema.Schema;
+import org.hisp.dhis.schema.SchemaService;
 import org.hisp.dhis.system.util.ReflectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -50,7 +51,7 @@
     private ParserService parserService;
 
     @Autowired
-    private PropertyIntrospectorService propertyIntrospectorService;
+    private SchemaService schemaService;
 
     @Override
     public <T extends IdentifiableObject> List<T> filterObjects( List<T> objects, List<String> filters )
@@ -86,12 +87,11 @@
         }
 
         Map<String, Map> fieldMap = Maps.newHashMap();
+        Schema schema = schemaService.getDynamicSchema( objects.get( 0 ).getClass() );
 
         if ( include == null && exclude == null )
         {
-            List<Property> properties = propertyIntrospectorService.getProperties( objects.get( 0 ).getClass() );
-
-            for ( Property property : properties )
+            for ( Property property : schema.getProperties() )
             {
                 fieldMap.put( property.getName(), Maps.newHashMap() );
             }
@@ -102,10 +102,9 @@
         }
         else
         {
-            List<Property> properties = propertyIntrospectorService.getProperties( objects.get( 0 ).getClass() );
             Map<String, Map> excludeMap = parserService.parsePropertyFilter( exclude );
 
-            for ( Property property : properties )
+            for ( Property property : schema.getProperties() )
             {
                 if ( !excludeMap.containsKey( property.getName() ) )
                 {
@@ -131,17 +130,17 @@
         }
 
         Map<String, Object> output = Maps.newHashMap();
-        Map<String, Property> propertiesMap = propertyIntrospectorService.getPropertiesMap( object.getClass() );
+        Schema schema = schemaService.getDynamicSchema( object.getClass() );
 
         for ( String key : fieldMap.keySet() )
         {
-            if ( !propertiesMap.containsKey( key ) )
+            if ( !schema.getPropertyMap().containsKey( key ) )
             {
                 continue;
             }
 
             Map value = fieldMap.get( key );
-            Property descriptor = propertiesMap.get( key );
+            Property descriptor = schema.getPropertyMap().get( key );
 
             Object returned = ReflectionUtils.invokeMethod( object, descriptor.getGetterMethod() );
 
@@ -240,11 +239,11 @@
     private Map<String, Object> getIdentifiableObjectProperties( Object object, List<String> fields )
     {
         Map<String, Object> idProps = Maps.newLinkedHashMap();
-        Map<String, Property> propertiesMap = propertyIntrospectorService.getPropertiesMap( object.getClass() );
+        Schema schema = schemaService.getDynamicSchema( object.getClass() );
 
         for ( String field : fields )
         {
-            Property descriptor = propertiesMap.get( field );
+            Property descriptor = schema.getPropertyMap().get( field );
 
             if ( descriptor == null )
             {
@@ -265,17 +264,17 @@
     @SuppressWarnings( "unchecked" )
     private <T> boolean evaluateWithFilters( T object, Filters filters )
     {
-        Map<String, Property> propertiesMap = propertyIntrospectorService.getPropertiesMap( object.getClass() );
+        Schema schema = schemaService.getDynamicSchema( object.getClass() );
 
         for ( String field : filters.getFilters().keySet() )
         {
-            if ( !propertiesMap.containsKey( field ) )
+            if ( !schema.getPropertyMap().containsKey( field ) )
             {
                 System.err.println( "Skipping non-existent field: " + field );
                 continue;
             }
 
-            Property descriptor = propertiesMap.get( field );
+            Property descriptor = schema.getPropertyMap().get( field );
 
             if ( descriptor == null )
             {