dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #28798
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14437: extend propertyIntrospectorService with getPropertiesMap, updating filter to use this
------------------------------------------------------------
revno: 14437
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-03-26 16:02:47 +0100
message:
extend propertyIntrospectorService with getPropertiesMap, updating filter to use this
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyIntrospectorService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java
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-api/src/main/java/org/hisp/dhis/schema/PropertyIntrospectorService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyIntrospectorService.java 2014-03-26 11:38:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyIntrospectorService.java 2014-03-26 15:02:47 +0000
@@ -29,6 +29,7 @@
*/
import java.util.List;
+import java.util.Map;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -36,4 +37,6 @@
public interface PropertyIntrospectorService
{
List<Property> getProperties( Class<?> klass );
+
+ Map<String, Property> getPropertiesMap( Class<?> klass );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java 2014-03-26 11:38:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java 2014-03-26 15:02:47 +0000
@@ -59,6 +59,21 @@
return scanClass( klass );
}
+ @Override
+ public Map<String, Property> getPropertiesMap( Class<?> klass )
+ {
+ Map<String, Property> propertyMap = Maps.newHashMap();
+
+ List<Property> properties = scanClass( klass );
+
+ for ( Property property : properties )
+ {
+ propertyMap.put( property.getName(), property );
+ }
+
+ return propertyMap;
+ }
+
// -------------------------------------------------------------------------
// Scanning Helpers
// -------------------------------------------------------------------------
=== 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-03-26 11:32:35 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java 2014-03-26 15:02:47 +0000
@@ -33,8 +33,7 @@
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.Schema;
-import org.hisp.dhis.schema.SchemaService;
+import org.hisp.dhis.schema.PropertyIntrospectorService;
import org.hisp.dhis.system.util.ReflectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -51,7 +50,7 @@
private ParserService parserService;
@Autowired
- private SchemaService schemaService;
+ private PropertyIntrospectorService propertyIntrospectorService;
@Override
public <T extends IdentifiableObject> List<T> filterObjects( List<T> objects, List<String> filters )
@@ -90,9 +89,9 @@
if ( include == null && exclude == null )
{
- Schema schema = schemaService.getSchema( objects.get( 0 ).getClass() );
+ List<Property> properties = propertyIntrospectorService.getProperties( objects.get( 0 ).getClass() );
- for ( Property property : schema.getProperties() )
+ for ( Property property : properties )
{
fieldMap.put( property.getName(), Maps.newHashMap() );
}
@@ -103,11 +102,10 @@
}
else
{
- Schema schema = schemaService.getSchema( objects.get( 0 ).getClass() );
-
+ List<Property> properties = propertyIntrospectorService.getProperties( objects.get( 0 ).getClass() );
Map<String, Map> excludeMap = parserService.parsePropertyFilter( exclude );
- for ( Property property : schema.getProperties() )
+ for ( Property property : properties )
{
if ( !excludeMap.containsKey( property.getName() ) )
{
@@ -133,17 +131,17 @@
}
Map<String, Object> output = Maps.newHashMap();
- Schema schema = schemaService.getSchema( object.getClass() );
+ Map<String, Property> propertiesMap = propertyIntrospectorService.getPropertiesMap( object.getClass() );
for ( String key : fieldMap.keySet() )
{
- if ( !schema.containsProperty( key ) )
+ if ( !propertiesMap.containsKey( key ) )
{
continue;
}
Map value = fieldMap.get( key );
- Property descriptor = schema.getPropertyByName( key );
+ Property descriptor = propertiesMap.get( key );
Object returned = ReflectionUtils.invokeMethod( object, descriptor.getMethod() );
@@ -234,11 +232,11 @@
private Map<String, Object> getIdentifiableObjectProperties( Object object, List<String> fields )
{
Map<String, Object> idProps = Maps.newLinkedHashMap();
- Schema schema = schemaService.getSchema( object.getClass() );
+ Map<String, Property> propertiesMap = propertyIntrospectorService.getPropertiesMap( object.getClass() );
for ( String field : fields )
{
- Property descriptor = schema.getPropertyByName( field );
+ Property descriptor = propertiesMap.get( field );
if ( descriptor == null )
{
@@ -259,17 +257,17 @@
@SuppressWarnings( "unchecked" )
private <T extends IdentifiableObject> boolean evaluateWithFilters( T object, Filters filters )
{
- Schema schema = schemaService.getSchema( object.getClass() );
+ Map<String, Property> propertiesMap = propertyIntrospectorService.getPropertiesMap( object.getClass() );
for ( String field : filters.getFilters().keySet() )
{
- if ( !schema.containsProperty( field ) )
+ if ( !propertiesMap.containsKey( field ) )
{
System.err.println( "Skipping non-existent field: " + field );
continue;
}
- Property descriptor = schema.getPropertyByName( field );
+ Property descriptor = propertiesMap.get( field );
if ( descriptor == null )
{