← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19575: applied patch from TW, adds datetime support (not exposed in D2 UI)

 

------------------------------------------------------------
revno: 19575
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-07-08 12:02:25 +0700
message:
  applied patch from TW, adds datetime support (not exposed in D2 UI)
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/util/ObjectUtils.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueDailyConverter.java
  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/PDFUtils.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html


--
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-06-03 13:37:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java	2015-07-08 05:02:25 +0000
@@ -30,8 +30,10 @@
 
 import java.util.Date;
 
+import org.hisp.dhis.calendar.DateTimeUnit;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+import org.joda.time.DateTime;
 
 /**
  * @author Lars Helge Overland
@@ -46,6 +48,7 @@
     BOOLEAN( Boolean.class ),
     TRUE_ONLY( Boolean.class ),
     DATE( Date.class ),
+    DATETIME(DateTime.class),
     NUMBER( Double.class ),
     UNIT_INTERVAL( Double.class ),
     PERCENTAGE( Double.class ),
@@ -132,6 +135,10 @@
         {
             return ValueType.DATE;
         }
+        else if ( DataElement.VALUE_TYPE_DATETIME.equals( dataElement.getType() ) )
+        {
+            return ValueType.DATETIME;
+        }
 
         return ValueType.TEXT; // Fall back
     }

=== 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-06-10 20:22:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2015-07-08 05:02:25 +0000
@@ -94,6 +94,7 @@
     public static final String VALUE_TYPE_BOOL = "bool";
     public static final String VALUE_TYPE_TRUE_ONLY = "trueOnly";
     public static final String VALUE_TYPE_DATE = "date";
+    public static final String VALUE_TYPE_DATETIME = "datetime";
     public static final String VALUE_TYPE_UNIT_INTERVAL = "unitInterval";
     public static final String VALUE_TYPE_PERCENTAGE = "percentage";
 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/util/ObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/util/ObjectUtils.java	2015-02-18 17:33:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/util/ObjectUtils.java	2015-07-08 05:02:25 +0000
@@ -34,6 +34,7 @@
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+import org.joda.time.DateTime;
 
 public class ObjectUtils
 {
@@ -43,6 +44,7 @@
         put( DataElement.VALUE_TYPE_BOOL, Boolean.class );
         put( DataElement.VALUE_TYPE_TRUE_ONLY, Boolean.class );
         put( DataElement.VALUE_TYPE_DATE, Date.class );
+        put( DataElement.VALUE_TYPE_DATETIME, DateTime.class );
         put( DataElement.VALUE_TYPE_UNIT_INTERVAL, Double.class );
         put( DataElement.VALUE_TYPE_PERCENTAGE, Double.class );
         put( TrackedEntityAttribute.TYPE_NUMBER, Double.class );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties	2015-07-07 12:22:03 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties	2015-07-08 05:02:25 +0000
@@ -551,6 +551,7 @@
 int=Number
 number=Number
 date=Date
+date_time=Date & Time
 yes_no=Yes/No
 bool=Yes/No
 none=None

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java	2015-07-04 16:43:29 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java	2015-07-08 05:02:25 +0000
@@ -352,7 +352,8 @@
                 out.write( SEPARATOR_B );
             }
 
-            else if ( dataElementType.equals( DataElement.VALUE_TYPE_DATE ) )
+            else if ( dataElementType.equals( DataElement.VALUE_TYPE_DATE )
+                || dataElementType.equals( DataElement.VALUE_TYPE_DATETIME ) )
             {
                 out.write( SEPARATOR_B );
                 out.write( SEPARATOR_B );

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueDailyConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueDailyConverter.java	2015-07-04 16:43:29 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueDailyConverter.java	2015-07-08 05:02:25 +0000
@@ -766,7 +766,8 @@
 
             }
 
-            else if ( dataElementType.equals( DataElement.VALUE_TYPE_DATE ) )
+            else if ( dataElementType.equals( DataElement.VALUE_TYPE_DATE )
+                || dataElementType.equals( DataElement.VALUE_TYPE_DATETIME ) )
             {
                 out.write( SEPARATOR_B );
                 out.write( SEPARATOR_B );

=== 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:43:40 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java	2015-07-08 05:02:25 +0000
@@ -72,9 +72,20 @@
         DateTimeFormat.forPattern( "yyyy" ).getParser()
     };
 
-    private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder()
+    private static final DateTimeFormatter DATE_FORMATTER = new DateTimeFormatterBuilder()
         .append( null, SUPPORTED_DATE_FORMAT_PARSERS ).toFormatter();
 
+    private static final DateTimeParser[] SUPPORTED_DATE_TIME_FORMAT_PARSERS = {
+            DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" ).getParser(),
+            DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mm:ssZ" ).getParser(),
+            DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mmZ" ).getParser(),
+            DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mm:ss" ).getParser(),
+            DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mm" ).getParser()
+    };
+
+    private static final DateTimeFormatter DATE_TIME_FORMATTER = ( new DateTimeFormatterBuilder() )
+            .append(null, SUPPORTED_DATE_TIME_FORMAT_PARSERS).toFormatter();
+
     private static final String SEP = ", ";
 
     public static final PeriodFormatter DAY_SECOND_FORMAT = new PeriodFormatterBuilder()
@@ -483,6 +494,26 @@
     }
 
     /**
+     * This method checks whether the String dateTimeString is a valid datetime following
+     * the format "yyyy-MM-dd".
+     *
+     * @param dateTimeString the string to be checked.
+     * @return true/false depending on whether the string is a valid datetime according to the format "yyyy-MM-dd".
+     */
+    public static boolean dateTimeIsValid(final String dateTimeString)
+    {
+        try
+        {
+            DATE_TIME_FORMATTER.parseDateTime(dateTimeString);
+            return true;
+        }
+        catch( IllegalArgumentException ex )
+        {
+            return false;
+        }
+    }
+
+    /**
      * Returns the number of seconds until the next day at the given hour.
      *
      * @param hour the hour.
@@ -627,6 +658,6 @@
             return null;
         }
 
-        return DATE_TIME_FORMATTER.parseDateTime( dateString ).toDate();
+        return DATE_FORMATTER.parseDateTime( dateString ).toDate();
     }
 }

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PDFUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PDFUtils.java	2015-06-16 18:30:37 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PDFUtils.java	2015-07-08 05:02:25 +0000
@@ -696,6 +696,7 @@
         map.put( DataElement.VALUE_TYPE_INT, "number" );
         map.put( DataElement.VALUE_TYPE_BOOL, "yes_no" );
         map.put( DataElement.VALUE_TYPE_DATE, "date" );
+        map.put( DataElement.VALUE_TYPE_DATETIME, "date_time" );
         return map;
     }
 

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java	2015-06-02 11:11:54 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java	2015-07-08 05:02:25 +0000
@@ -329,6 +329,11 @@
             return "value_not_valid_date";
         }
 
+        if ( VALUE_TYPE_DATETIME.equals( type ) && !DateUtils.dateTimeIsValid( value ) )
+        {
+            return "value_not_valid_datetime";
+        }
+
         return null;
     }
 

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java	2015-04-24 16:07:03 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java	2015-07-08 05:02:25 +0000
@@ -29,6 +29,7 @@
  */
 
 import static org.hisp.dhis.system.util.DateUtils.dateIsValid;
+import static org.hisp.dhis.system.util.DateUtils.dateTimeIsValid;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
@@ -62,6 +63,22 @@
         assertFalse( dateIsValid( "01-01-01" ) );
         assertFalse( dateIsValid( "abcd-01-01" ) );
     }
+
+    @Test
+    public void testDateTimeIsValid()
+    {
+        assertTrue( dateTimeIsValid( "2000-01-01T10:00:00.000Z" ) );
+        assertTrue( dateTimeIsValid( "2000-01-01T10:00:00.000+05:30" ) );
+        assertTrue( dateTimeIsValid( "2000-01-01T10:00:00Z" ) );
+        assertTrue( dateTimeIsValid( "2000-01-01T10:00:00+05:30" ) );
+        assertTrue( dateTimeIsValid( "2000-01-01T10:00:00" ) );
+        assertTrue( dateTimeIsValid( "2000-01-01T10:00Z" ) );
+        assertTrue( dateTimeIsValid( "2000-01-01T10:00+05:30" ) );
+        assertTrue( dateTimeIsValid( "2000-01-01T10:00" ) );
+        assertFalse( dateTimeIsValid( "2000-01-01" ) );
+        assertFalse( dateTimeIsValid( "01-01-2000" ) );
+        assertFalse( dateTimeIsValid( "abcd" ) );
+    }
     
     @Test
     public void testDaysBetween()

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java	2015-06-02 11:11:54 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java	2015-07-08 05:02:25 +0000
@@ -28,23 +28,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.system.util.ValidationUtils.coordinateIsValid;
-import static org.hisp.dhis.system.util.ValidationUtils.dataValueIsValid;
-import static org.hisp.dhis.system.util.ValidationUtils.emailIsValid;
-import static org.hisp.dhis.system.util.ValidationUtils.getLatitude;
-import static org.hisp.dhis.system.util.ValidationUtils.getLongitude;
-import static org.hisp.dhis.system.util.ValidationUtils.isValidHexColor;
-import static org.hisp.dhis.system.util.ValidationUtils.passwordIsValid;
-import static org.hisp.dhis.system.util.ValidationUtils.dataValueIsZeroAndInsignificant;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
 import org.hisp.dhis.dataelement.DataElement;
 import org.junit.Test;
 
+import static org.hisp.dhis.system.util.ValidationUtils.*;
+import static org.junit.Assert.*;
+
 /**
  * @author Lars Helge Overland
  */
@@ -59,7 +48,7 @@
         assertTrue( coordinateIsValid( "[170.99034,78.94221]" ) );
         assertTrue( coordinateIsValid( "[-167,-28.94221]" ) );
         assertTrue( coordinateIsValid( "[37.99034,28]" ) );
-        
+
         assertFalse( coordinateIsValid( "23.34343,56.3232" ) );
         assertFalse( coordinateIsValid( "23.34343 56.3232" ) );
         assertFalse( coordinateIsValid( "[23.34f43,56.3232]" ) );
@@ -68,7 +57,7 @@
         assertFalse( coordinateIsValid( "[++37,-28.94221]" ) );
         assertFalse( coordinateIsValid( "S-0.27726 E37.08472" ) );
         assertFalse( coordinateIsValid( null ) );
-                
+
         assertFalse( coordinateIsValid( "-185.12345,45.45423" ) );
         assertFalse( coordinateIsValid( "192.56789,-45.34332" ) );
         assertFalse( coordinateIsValid( "140.34,92.23323" ) );
@@ -85,7 +74,7 @@
         assertNull( getLongitude( "23.34343,56.3232" ) );
         assertNull( getLongitude( null ) );
     }
-    
+
     @Test
     public void testGetLatitude()
     {
@@ -94,7 +83,7 @@
         assertNull( getLatitude( "23.34343,56.3232" ) );
         assertNull( getLatitude( null ) );
     }
-    
+
     @Test
     public void testPasswordIsValid()
     {
@@ -103,28 +92,28 @@
         assertFalse( passwordIsValid( "Johndoedoe" ) );
         assertTrue( passwordIsValid( "Johndoe1" ) );
     }
-    
+
     @Test
     public void testEmailIsValid()
     {
         assertFalse( emailIsValid( "john@doe" ) );
         assertTrue( emailIsValid( "john@xxxxxxx" ) );
     }
-    
+
     @Test
     public void testDataValueIsZeroAndInsignificant()
     {
         DataElement de = new DataElement( "DEA" );
         de.setType( DataElement.VALUE_TYPE_INT );
         de.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM );
-      
+
         assertTrue( dataValueIsZeroAndInsignificant( "0", de ) );
-        
+
         de.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM );
 
         assertFalse( dataValueIsZeroAndInsignificant( "0", de ) );
     }
-    
+
     @Test
     public void testDataValueIsValid()
     {
@@ -133,61 +122,67 @@
 
         assertNull( dataValueIsValid( null, de ) );
         assertNull( dataValueIsValid( "", de ) );
-        
+
         assertNull( dataValueIsValid( "34", de ) );
         assertNotNull( dataValueIsValid( "Yes", de ) );
-        
+
         de.setNumberType( DataElement.VALUE_TYPE_NUMBER );
-        
+
         assertNull( dataValueIsValid( "3.7", de ) );
         assertNotNull( dataValueIsValid( "No", de ) );
 
         de.setNumberType( DataElement.VALUE_TYPE_POSITIVE_INT );
-        
+
         assertNull( dataValueIsValid( "3", de ) );
         assertNotNull( dataValueIsValid( "-4", de ) );
-        
+
         de.setNumberType( DataElement.VALUE_TYPE_ZERO_OR_POSITIVE_INT );
-        
+
         assertNull( dataValueIsValid( "3", de ) );
         assertNotNull( dataValueIsValid( "-4", de ) );
 
         de.setNumberType( DataElement.VALUE_TYPE_NEGATIVE_INT );
-        
+
         assertNull( dataValueIsValid( "-3", de ) );
         assertNotNull( dataValueIsValid( "4", de ) );
 
         de.setType( DataElement.VALUE_TYPE_TEXT );
 
         assertNull( dataValueIsValid( "0", de ) );
-        
+
         de.setType( DataElement.VALUE_TYPE_BOOL );
-        
+
         assertNull( dataValueIsValid( "true", de ) );
         assertNotNull( dataValueIsValid( "yes", de ) );
-        
+
         de.setType( DataElement.VALUE_TYPE_TRUE_ONLY );
 
         assertNull( dataValueIsValid( "true", de ) );
         assertNotNull( dataValueIsValid( "false", de ) );
-        
+
         de.setType( DataElement.VALUE_TYPE_DATE );
         assertNull( dataValueIsValid( "2013-04-01", de ) );
         assertNotNull( dataValueIsValid( "2012304-01", de ) );
-        assertNotNull( dataValueIsValid( "Date", de ) );        
+        assertNotNull( dataValueIsValid( "Date", de ) );
+
+        de.setType( DataElement.VALUE_TYPE_DATETIME );
+        assertNull( dataValueIsValid( "2013-04-01T11:00:00.000Z", de ) );
+        assertNotNull( dataValueIsValid( "2013-04-01", de ) );
+        assertNotNull( dataValueIsValid( "abcd", de ) );
     }
 
     @Test
-    public void testIsValidHexColor() {
+    public void testIsValidHexColor()
+    {
         assertFalse( isValidHexColor( "abcpqr" ) );
         assertFalse( isValidHexColor( "#qwerty" ) );
-        assertFalse( isValidHexColor( "FFAB#O") );
+        assertFalse( isValidHexColor( "FFAB#O" ) );
 
         assertTrue( isValidHexColor( "#FF0" ) );
         assertTrue( isValidHexColor( "#FF0000" ) );
         assertTrue( isValidHexColor( "FFFFFF" ) );
         assertTrue( isValidHexColor( "ffAAb4" ) );
         assertTrue( isValidHexColor( "#4a6" ) );
-        assertTrue( isValidHexColor ( "abc" ) );
+        assertTrue( isValidHexColor( "abc" ) );
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2015-07-02 07:19:49 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2015-07-08 05:02:25 +0000
@@ -170,6 +170,17 @@
                                        blur-or-change="saveDatavalue()" 
                                        class="form-control">
                             </div>
+                            <div ng-switch-when="datetime">
+                                <input type="text"
+                                       placeholder="{{dhis2CalendarFormat.keyDateFormat}}"
+                                       d2-date
+                                       max-date="prStDes[eventGridColumn.id].allowFutureDate ? '' : 0"
+                                       ng-model="currentEvent[eventGridColumn.id]"
+                                       ng-required={{eventGridColumn.compulsory}}
+                                       name="foo"
+                                       input-field-id={{eventGridColumn.id}}
+                                       style="width:99%;"/>
+                            </div>
                             <div ng-switch-when="trueOnly">
                                 <input type="checkbox"                                         
                                        ng-model="currentEvent[eventGridColumn.id]"                                                               
@@ -380,6 +391,19 @@
                                            blur-or-change="saveDatavalue()" 
                                            class="form-control"/>
                                 </div>
+                                <div ng-switch-when="datetime">
+                                    <input type="text"
+                                           placeholder="{{dhis2CalendarFormat.keyDateFormat}}"
+                                           d2-date
+                                           max-date="prStDes[de.dataElement.id].allowFutureDate ? '' : 0"
+                                           d2-date-validator
+                                           ng-model="currentEvent[de.dataElement.id]"
+                                           ng-required={{prStDes[de.dataElement.id].compulsory}}
+                                           name="foo"
+                                           input-field-id={{de.dataElement.id}}
+                                           blur-or-change="saveDatavalue()"
+                                           class="form-control"/>
+                                </div>
                                 <div ng-switch-when="trueOnly">
                                     <input type="checkbox"                                                  
                                            ng-model="currentEvent[de.dataElement.id]"