dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #28433
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14196: support dates in web-api filtering
------------------------------------------------------------
revno: 14196
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-03-12 09:32:41 +0100
message:
support dates in web-api filtering
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/EqOp.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/GtOp.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/GteOp.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/LtOp.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/LteOp.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/EqOp.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/EqOp.java 2014-03-12 08:16:09 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/EqOp.java 2014-03-12 08:32:41 +0000
@@ -29,10 +29,11 @@
*/
import java.util.Collection;
+import java.util.Date;
/**
-* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
-*/
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
public class EqOp extends Op
{
@Override
@@ -85,6 +86,13 @@
return OpStatus.EXCLUDE;
}
}
+ else if ( Date.class.isInstance( object ) )
+ {
+ Date s1 = getValue( Date.class );
+ Date s2 = (Date) object;
+
+ return (s1 != null && s2.equals( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE;
+ }
return OpStatus.IGNORE;
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/GtOp.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/GtOp.java 2014-03-12 08:16:09 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/GtOp.java 2014-03-12 08:32:41 +0000
@@ -29,10 +29,11 @@
*/
import java.util.Collection;
+import java.util.Date;
/**
-* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
-*/
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
public class GtOp extends Op
{
@Override
@@ -71,6 +72,13 @@
return OpStatus.EXCLUDE;
}
}
+ else if ( Date.class.isInstance( object ) )
+ {
+ Date s1 = getValue( Date.class );
+ Date s2 = (Date) object;
+
+ return (s1 != null && s2.after( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE;
+ }
return OpStatus.IGNORE;
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/GteOp.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/GteOp.java 2014-03-12 08:16:09 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/GteOp.java 2014-03-12 08:32:41 +0000
@@ -29,10 +29,11 @@
*/
import java.util.Collection;
+import java.util.Date;
/**
-* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
-*/
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
public class GteOp extends Op
{
@Override
@@ -71,6 +72,13 @@
return OpStatus.EXCLUDE;
}
}
+ else if ( Date.class.isInstance( object ) )
+ {
+ Date s1 = getValue( Date.class );
+ Date s2 = (Date) object;
+
+ return (s1 != null && (s2.after( s1 ) || s2.equals( s1 ))) ? OpStatus.INCLUDE : OpStatus.EXCLUDE;
+ }
return OpStatus.IGNORE;
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/LtOp.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/LtOp.java 2014-03-12 08:16:09 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/LtOp.java 2014-03-12 08:32:41 +0000
@@ -29,10 +29,11 @@
*/
import java.util.Collection;
+import java.util.Date;
/**
-* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
-*/
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
public class LtOp extends Op
{
@Override
@@ -71,6 +72,13 @@
return OpStatus.EXCLUDE;
}
}
+ else if ( Date.class.isInstance( object ) )
+ {
+ Date s1 = getValue( Date.class );
+ Date s2 = (Date) object;
+
+ return (s1 != null && (s2.before( s1 ))) ? OpStatus.INCLUDE : OpStatus.EXCLUDE;
+ }
return OpStatus.IGNORE;
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/LteOp.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/LteOp.java 2014-03-12 08:16:09 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/LteOp.java 2014-03-12 08:32:41 +0000
@@ -29,10 +29,11 @@
*/
import java.util.Collection;
+import java.util.Date;
/**
-* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
-*/
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
public class LteOp extends Op
{
@Override
@@ -71,6 +72,13 @@
return OpStatus.EXCLUDE;
}
}
+ else if ( Date.class.isInstance( object ) )
+ {
+ Date s1 = getValue( Date.class );
+ Date s2 = (Date) object;
+
+ return (s1 != null && (s2.before( s1 ) || s2.equals( s1 ))) ? OpStatus.INCLUDE : OpStatus.EXCLUDE;
+ }
return OpStatus.IGNORE;
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/Op.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/Op.java 2014-03-12 08:16:09 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ops/Op.java 2014-03-12 08:32:41 +0000
@@ -28,6 +28,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.Date;
/**
@@ -37,6 +39,16 @@
{
private String value;
+ private static SimpleDateFormat[] simpleDateFormats = new SimpleDateFormat[]{
+ new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" ),
+ new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" ),
+ new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm" ),
+ new SimpleDateFormat( "yyyy-MM-dd'T'HH" ),
+ new SimpleDateFormat( "yyyyMMdd" ),
+ new SimpleDateFormat( "yyyyMM" ),
+ new SimpleDateFormat( "yyyy" )
+ };
+
public boolean wantValue()
{
return true;
@@ -92,6 +104,16 @@
}
else if ( Date.class.isAssignableFrom( klass ) )
{
+ for ( SimpleDateFormat simpleDateFormat : simpleDateFormats )
+ {
+ try
+ {
+ return (T) simpleDateFormat.parse( value );
+ }
+ catch ( ParseException ignored )
+ {
+ }
+ }
}
return null;