dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41223
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20990: support Conjunction/Disjunction in in-memory query engine
------------------------------------------------------------
revno: 20990
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-11-09 15:22:59 +0700
message:
support Conjunction/Disjunction in in-memory query engine
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 07:41:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/InMemoryQueryEngine.java 2015-11-09 08:22:59 +0000
@@ -104,16 +104,76 @@
{
for ( Criterion criterion : query.getCriterions() )
{
- Restriction restriction = (Restriction) criterion;
- Object value = getValue( query, object, restriction.getPath() );
-
- if ( !restriction.getOperator().test( value ) )
- {
- return false;
- }
- }
-
- return true;
+ // normal Restriction, just assume Conjunction
+ if ( Restriction.class.isInstance( criterion ) )
+ {
+ Restriction restriction = (Restriction) criterion;
+ Object value = getValue( query, object, restriction.getPath() );
+
+ if ( !restriction.getOperator().test( value ) )
+ {
+ return false;
+ }
+ }
+ else if ( Conjunction.class.isInstance( criterion ) )
+ {
+ Conjunction conjunction = (Conjunction) criterion;
+
+ if ( !testAnd( query, object, conjunction.getCriterions() ) )
+ {
+ return false;
+ }
+ }
+ else if ( Disjunction.class.isInstance( criterion ) )
+ {
+ Disjunction disjunction = (Disjunction) criterion;
+
+ if ( !testOr( query, object, disjunction.getCriterions() ) )
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ private boolean testAnd( Query query, T object, List<Criterion> criterions )
+ {
+ for ( Criterion criterion : criterions )
+ {
+ if ( Restriction.class.isInstance( criterion ) )
+ {
+ Restriction restriction = (Restriction) criterion;
+ Object value = getValue( query, object, restriction.getPath() );
+
+ if ( !restriction.getOperator().test( value ) )
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ private boolean testOr( Query query, T object, List<Criterion> criterions )
+ {
+ for ( Criterion criterion : criterions )
+ {
+ if ( Restriction.class.isInstance( criterion ) )
+ {
+ Restriction restriction = (Restriction) criterion;
+ Object value = getValue( query, object, restriction.getPath() );
+
+ if ( restriction.getOperator().test( value ) )
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
}
private Object getValue( Query query, Object object, String path )
=== 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 07:41:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java 2015-11-09 08:22:59 +0000
@@ -38,7 +38,6 @@
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;
@@ -348,7 +347,6 @@
}
@Test
- @Ignore
public void testDateRangeWithConjunction()
{
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
@@ -369,7 +367,6 @@
}
@Test
- @Ignore
public void testDoubleEqConjunction()
{
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
@@ -386,7 +383,6 @@
}
@Test
- @Ignore
public void testDoubleEqDisjunction()
{
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );