dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37767
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19289: bugfixes to in-memory IN filter
------------------------------------------------------------
revno: 19289
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-06-05 10:07:51 +0700
message:
bugfixes to in-memory IN filter
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/InOp.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/Op.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/objectfilter/ops/InOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/InOp.java 2015-05-29 18:36:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/InOp.java 2015-06-05 03:07:51 +0000
@@ -29,6 +29,7 @@
*/
import java.util.Collection;
+import java.util.Date;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -36,24 +37,71 @@
public class InOp extends Op
{
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public OpStatus evaluate( Object object )
{
Collection<String> items = getValue( Collection.class );
- if ( items == null )
+ if ( items == null || object == null )
{
- return OpStatus.INCLUDE;
+ return OpStatus.IGNORE;
}
for ( String item : items )
{
- if ( item.equals( object ) )
+ if ( compare( item, object ) )
{
return OpStatus.INCLUDE;
}
}
- return OpStatus.IGNORE;
+ return OpStatus.EXCLUDE;
+ }
+
+ private boolean compare( String item, Object object )
+ {
+ if ( String.class.isInstance( object ) )
+ {
+ String s1 = getValue( String.class, item );
+ String s2 = (String) object;
+
+ return (s1 != null && s2.equals( s1 ));
+ }
+ else if ( Boolean.class.isInstance( object ) )
+ {
+ Boolean s1 = getValue( Boolean.class, item );
+ Boolean s2 = (Boolean) object;
+
+ return (s1 != null && s2.equals( s1 ));
+ }
+ else if ( Integer.class.isInstance( object ) )
+ {
+ Integer s1 = getValue( Integer.class, item );
+ Integer s2 = (Integer) object;
+
+ return (s1 != null && s2.equals( s1 ));
+ }
+ else if ( Float.class.isInstance( object ) )
+ {
+ Float s1 = getValue( Float.class, item );
+ Float s2 = (Float) object;
+
+ return (s1 != null && s2.equals( s1 ));
+ }
+ else if ( Date.class.isInstance( object ) )
+ {
+ Date s1 = getValue( Date.class, item );
+ Date s2 = (Date) object;
+
+ return (s1 != null && s2.equals( s1 ));
+ }
+ else if ( Enum.class.isInstance( object ) )
+ {
+ String s2 = String.valueOf( object );
+
+ return (item != null && s2.equals( item ));
+ }
+
+ return false;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/Op.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/Op.java 2015-04-09 08:59:36 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/Op.java 2015-06-05 03:07:51 +0000
@@ -57,5 +57,10 @@
return QueryUtils.getValue( klass, value );
}
+ public <T> T getValue( Class<T> klass, Object value )
+ {
+ return QueryUtils.getValue( klass, value );
+ }
+
public abstract OpStatus evaluate( Object object );
}