← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19873: Event analytics, added support for native date/timestamp column types

 

------------------------------------------------------------
revno: 19873
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-08-27 17:28:24 +0200
message:
  Event analytics, added support for native date/timestamp column types
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.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-api/src/main/java/org/hisp/dhis/common/ValueType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java	2015-07-15 13:33:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java	2015-08-27 15:28:24 +0000
@@ -32,7 +32,6 @@
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
-import org.joda.time.DateTime;
 
 /**
  * @author Lars Helge Overland
@@ -47,7 +46,7 @@
     BOOLEAN( Boolean.class ),
     TRUE_ONLY( Boolean.class ),
     DATE( Date.class ),
-    DATETIME( DateTime.class ),
+    DATETIME( Date.class ),
     NUMBER( Double.class ),
     UNIT_INTERVAL( Double.class ),
     PERCENTAGE( Double.class ),

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2015-08-02 14:59:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2015-08-27 15:28:24 +0000
@@ -268,6 +268,14 @@
     }
 
     /**
+     * Indicates whether the value type of this data element is date.
+     */
+    public boolean isDateType()
+    {
+        return VALUE_TYPE_DATE.equals( type ) || VALUE_TYPE_DATETIME.equals( type );
+    }
+    
+    /**
      * Returns the value type. If value type is int and the number type exists,
      * the number type is returned, otherwise the type is returned.
      */

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java	2015-08-02 14:59:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java	2015-08-27 15:28:24 +0000
@@ -138,6 +138,14 @@
     }
 
     /**
+     * Indicates whether the value type of this attribute is date.
+     */
+    public boolean isDateType()
+    {
+        return TYPE_DATE.equals( valueType );
+    }
+
+    /**
      * Indicates whether this attribute has an option set.
      */
     public boolean hasOptionSet()

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2015-08-19 08:08:11 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2015-08-27 15:28:24 +0000
@@ -69,6 +69,8 @@
     implements AnalyticsTableManager
 {
     protected static final Log log = LogFactory.getLog( JdbcAnalyticsTableManager.class );
+    
+    protected static final String DATE_REGEXP = "^\\d{4}-\\d{2}-\\d{2}(\\s|T)?(\\d{2}:\\d{2}:\\d{2})?$";
 
     public static final String PREFIX_ORGUNITGROUPSET = "ougs_";
     public static final String PREFIX_ORGUNITLEVEL = "uidlevel";

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java	2015-08-19 08:08:11 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java	2015-08-27 15:28:24 +0000
@@ -29,6 +29,7 @@
  */
 
 import static org.hisp.dhis.commons.util.TextUtils.removeLast;
+import static org.hisp.dhis.system.util.MathUtils.NUMERIC_LENIENT_REGEXP;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -49,7 +50,6 @@
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.system.util.DateUtils;
-import org.hisp.dhis.system.util.MathUtils;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.transaction.annotation.Transactional;
@@ -223,8 +223,10 @@
     public List<String[]> getDimensionColumns( AnalyticsTable table )
     {
         final String dbl = statementBuilder.getDoubleColumnType();
-        final String numericClause = " and value " + statementBuilder.getRegexpMatch() + " '"
-            + MathUtils.NUMERIC_LENIENT_REGEXP + "'";
+        final String numericClause = " and value " + statementBuilder.getRegexpMatch() + " '" + NUMERIC_LENIENT_REGEXP + "'";
+        final String dateClause = " and value " + statementBuilder.getRegexpMatch() + " '" + DATE_REGEXP + "'";
+        
+        //TODO dateClause regexp
 
         List<String[]> columns = new ArrayList<>();
 
@@ -260,7 +262,7 @@
         {
             ValueType valueType = ValueType.getFromDataElement( dataElement );
             String dataType = getColumnType( valueType );
-            String dataClause = dataElement.isNumericType() ? numericClause : "";
+            String dataClause = dataElement.isNumericType() ? numericClause : dataElement.isDateType() ? dateClause : "";
             String select = getSelectClause( valueType );
 
             String sql = "(select " + select + " from trackedentitydatavalue where programstageinstanceid=psi.programstageinstanceid " + 
@@ -288,7 +290,7 @@
         {
             ValueType valueType = ValueType.getFromAttribute( attribute );
             String dataType = getColumnType( valueType );
-            String dataClause = attribute.isNumericType() ? numericClause : "";
+            String dataClause = attribute.isNumericType() ? numericClause : attribute.isDateType() ? dateClause : "";
             String select = getSelectClause( valueType );
 
             String sql = "(select " + select + " from trackedentityattributevalue where trackedentityinstanceid=pi.trackedentityinstanceid " + 
@@ -399,6 +401,10 @@
         {
             return "integer";
         }
+        else if ( Date.class.equals( valueType.getJavaClass() ) )
+        {
+            return "timestamp";
+        }
         else
         {
             return "character varying(255)";
@@ -423,6 +429,10 @@
         {
             return "case when value = 'true' then 1 when value = 'false' then 0 else null end";
         }
+        else if ( Date.class.equals( valueType.getJavaClass() ) )
+        {
+            return "cast(value as timestamp)";
+        }
         else
         {
             return "value";