← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19405: bugfix for DefaultQueryService, properly parse dates with ::: in them

 

------------------------------------------------------------
revno: 19405
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-06-15 11:43:40 +0700
message:
  bugfix for DefaultQueryService, properly parse dates with ::: in them
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryService.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java
  dhis-2/pom.xml


--
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/DefaultQueryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryService.java	2015-06-04 09:25:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryService.java	2015-06-15 04:43:40 +0000
@@ -152,55 +152,57 @@
             return null;
         }
 
+        String value = filter.substring( split[0].length() + ":".length() + split[1].length() + ":".length() );
+
         switch ( split[1] )
         {
             case "eq":
             {
-                return Restrictions.eq( split[0], QueryUtils.getValue( property.getKlass(), split[2] ) );
+                return Restrictions.eq( split[0], QueryUtils.getValue( property.getKlass(), value ) );
             }
             case "ne":
             {
-                return Restrictions.ne( split[0], QueryUtils.getValue( property.getKlass(), split[2] ) );
+                return Restrictions.ne( split[0], QueryUtils.getValue( property.getKlass(), value ) );
             }
             case "neq":
             {
-                return Restrictions.ne( split[0], QueryUtils.getValue( property.getKlass(), split[2] ) );
+                return Restrictions.ne( split[0], QueryUtils.getValue( property.getKlass(), value ) );
             }
             case "gt":
             {
-                return Restrictions.gt( split[0], QueryUtils.getValue( property.getKlass(), split[2] ) );
+                return Restrictions.gt( split[0], QueryUtils.getValue( property.getKlass(), value ) );
             }
             case "lt":
             {
-                return Restrictions.lt( split[0], QueryUtils.getValue( property.getKlass(), split[2] ) );
+                return Restrictions.lt( split[0], QueryUtils.getValue( property.getKlass(), value ) );
             }
             case "gte":
             {
-                return Restrictions.ge( split[0], QueryUtils.getValue( property.getKlass(), split[2] ) );
+                return Restrictions.ge( split[0], QueryUtils.getValue( property.getKlass(), value ) );
             }
             case "ge":
             {
-                return Restrictions.ge( split[0], QueryUtils.getValue( property.getKlass(), split[2] ) );
+                return Restrictions.ge( split[0], QueryUtils.getValue( property.getKlass(), value ) );
             }
             case "lte":
             {
-                return Restrictions.le( split[0], QueryUtils.getValue( property.getKlass(), split[2] ) );
+                return Restrictions.le( split[0], QueryUtils.getValue( property.getKlass(), value ) );
             }
             case "le":
             {
-                return Restrictions.le( split[0], QueryUtils.getValue( property.getKlass(), split[2] ) );
+                return Restrictions.le( split[0], QueryUtils.getValue( property.getKlass(), value ) );
             }
             case "like":
             {
-                return Restrictions.like( split[0], "%" + split[2] + "%" );
+                return Restrictions.like( split[0], "%" + value + "%" );
             }
             case "ilike":
             {
-                return Restrictions.ilike( split[0], "%" + split[2] + "%" );
+                return Restrictions.ilike( split[0], "%" + value + "%" );
             }
             case "in":
             {
-                return Restrictions.in( split[0], parseInOperator( split[2] ) );
+                return Restrictions.in( split[0], parseInOperator( value ) );
             }
             case "null":
             {

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java	2015-06-15 04:15:16 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java	2015-06-15 04:43:40 +0000
@@ -28,15 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.period.Period.DEFAULT_DATE_FORMAT;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.TimeZone;
-
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.period.Period;
@@ -44,7 +35,21 @@
 import org.joda.time.DateTime;
 import org.joda.time.Days;
 import org.joda.time.Months;
-import org.joda.time.format.*;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.DateTimeFormatterBuilder;
+import org.joda.time.format.DateTimeParser;
+import org.joda.time.format.PeriodFormatter;
+import org.joda.time.format.PeriodFormatterBuilder;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
+import static org.hisp.dhis.period.Period.DEFAULT_DATE_FORMAT;
 
 /**
  * @author Lars Helge Overland
@@ -53,22 +58,22 @@
 public class DateUtils
 {
     private static final DateTimeParser[] SUPPORTED_DATE_FORMAT_PARSERS = {
-            DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").getParser(),
-            DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS").getParser(),
-            DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").getParser(),
-            DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").getParser(),
-            DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mmZ").getParser(),
-            DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm").getParser(),
-            DateTimeFormat.forPattern("yyyy-MM-dd'T'HHZ").getParser(),
-            DateTimeFormat.forPattern("yyyy-MM-dd'T'HH").getParser(),
-            DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ssZ").getParser(),
-            DateTimeFormat.forPattern("yyyy-MM-dd").getParser(),
-            DateTimeFormat.forPattern("yyyy-MM").getParser(),
-            DateTimeFormat.forPattern("yyyy").getParser()
+        DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" ).getParser(),
+        DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mm:ss.SSS" ).getParser(),
+        DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mm:ssZ" ).getParser(),
+        DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mm:ss" ).getParser(),
+        DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mmZ" ).getParser(),
+        DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mm" ).getParser(),
+        DateTimeFormat.forPattern( "yyyy-MM-dd'T'HHZ" ).getParser(),
+        DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH" ).getParser(),
+        DateTimeFormat.forPattern( "yyyy-MM-dd HH:mm:ssZ" ).getParser(),
+        DateTimeFormat.forPattern( "yyyy-MM-dd" ).getParser(),
+        DateTimeFormat.forPattern( "yyyy-MM" ).getParser(),
+        DateTimeFormat.forPattern( "yyyy" ).getParser()
     };
 
     private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder()
-            .append( null, SUPPORTED_DATE_FORMAT_PARSERS ).toFormatter();
+        .append( null, SUPPORTED_DATE_FORMAT_PARSERS ).toFormatter();
 
     private static final String SEP = ", ";
 
@@ -175,7 +180,7 @@
             return date2 != null ? date2 : null;
         }
 
-        return date2 != null ? ( date1.after( date2 ) ? date1 : date2 ) : date1;
+        return date2 != null ? (date1.after( date2 ) ? date1 : date2) : date1;
     }
 
     /**
@@ -593,7 +598,7 @@
      * start and end dates using a day, month, second format.
      *
      * @param start the start date.
-     * @param end the end date.
+     * @param end   the end date.
      * @return a string, or null if the given start or end date is null.
      */
     public static String getPrettyInterval( Date start, Date end )

=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml	2015-06-15 04:03:19 +0000
+++ dhis-2/pom.xml	2015-06-15 04:43:40 +0000
@@ -629,7 +629,7 @@
       <dependency>
         <groupId>joda-time</groupId>
         <artifactId>joda-time</artifactId>
-        <version>2.6</version>
+        <version>2.8</version>
       </dependency>
       <dependency>
         <groupId>javax.servlet</groupId>