← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21001: minor, validate to see if property path is valid or not

 

------------------------------------------------------------
revno: 21001
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-11-10 10:06:07 +0700
message:
  minor, validate to see if property path is valid or not
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/InMemoryQueryEngine.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.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-core/src/main/java/org/hisp/dhis/query/InMemoryQueryEngine.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/InMemoryQueryEngine.java	2015-11-09 08:22:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/InMemoryQueryEngine.java	2015-11-10 03:06:07 +0000
@@ -179,6 +179,12 @@
     private Object getValue( Query query, Object object, String path )
     {
         Property property = query.getSchema().getProperty( path );
+
+        if ( property == null )
+        {
+            throw new QueryException( "No property found for path " + path );
+        }
+
         return ReflectionUtils.invokeMethod( object, property.getGetterMethod() );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java	2015-11-09 08:59:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java	2015-11-10 03:06:07 +0000
@@ -33,11 +33,13 @@
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.ValueType;
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementGroup;
 import org.hisp.dhis.query.operators.MatchMode;
 import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaService;
 import org.jfree.data.time.Year;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -61,6 +63,8 @@
 
     private Collection<DataElement> dataElements = new ArrayList<>();
 
+    private Collection<DataElementGroup> dataElementGroups = new ArrayList<>();
+
     @Before
     public void createDataElements()
     {
@@ -96,6 +100,19 @@
         dataElements.add( dataElementD );
         dataElements.add( dataElementE );
         dataElements.add( dataElementF );
+
+        DataElementGroup dataElementGroupA = createDataElementGroup( 'A' );
+        dataElementGroupA.addDataElement( dataElementA );
+        dataElementGroupA.addDataElement( dataElementB );
+        dataElementGroupA.addDataElement( dataElementC );
+
+        DataElementGroup dataElementGroupB = createDataElementGroup( 'B' );
+        dataElementGroupB.addDataElement( dataElementD );
+        dataElementGroupB.addDataElement( dataElementE );
+        dataElementGroupB.addDataElement( dataElementF );
+
+        dataElementGroups.add( dataElementGroupA );
+        dataElementGroups.add( dataElementGroupB );
     }
 
     private boolean collectionContainsUid( Collection<? extends IdentifiableObject> collection, String uid )
@@ -493,4 +510,26 @@
         assertEquals( "deabcdefghE", objects.get( 4 ).getUid() );
         assertEquals( "deabcdefghF", objects.get( 5 ).getUid() );
     }
+
+    @Test( expected = QueryException.class )
+    public void testInvalidDeepPath()
+    {
+        Query query = Query.from( schemaService.getDynamicSchema( DataElementGroup.class ) );
+        query.setObjects( dataElementGroups );
+        query.add( Restrictions.eq( "dataElements.id", "deabcdefghA" ) );
+        queryEngine.query( query );
+    }
+
+    @Test
+    @Ignore
+    public void testEqDeepPath()
+    {
+        Query query = Query.from( schemaService.getDynamicSchema( DataElementGroup.class ) );
+        query.setObjects( dataElementGroups );
+        query.add( Restrictions.eq( "dataElements.id", "deabcdefghA" ) );
+        List<? extends IdentifiableObject> objects = queryEngine.query( query );
+
+        assertEquals( 1, objects.size() );
+        assertEquals( "abcdefghijA", objects.get( 0 ).getUid() );
+    }
 }