← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13196: changed to using ISO 8601 in DataValueSets.dataValue, renamed timestamp => lastUpdated

 

------------------------------------------------------------
revno: 13196
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-12-10 19:10:47 +0100
message:
  changed to using ISO 8601 in DataValueSets.dataValue, renamed timestamp => lastUpdated
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValue.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingCsvDataValue.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingDataValue.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.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/datavalue/DataValue.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValue.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValue.java	2013-12-10 18:10:47 +0000
@@ -53,10 +53,10 @@
     protected String categoryOptionCombo;
 
     protected String value;
-    
+
     protected String storedBy;
 
-    protected String timestamp;
+    protected String lastUpdated;
 
     protected String comment;
 
@@ -70,7 +70,7 @@
     {
     }
 
-    
+
     //--------------------------------------------------------------------------
     // Getters and setters
     //--------------------------------------------------------------------------
@@ -156,14 +156,14 @@
     @JsonProperty
     @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
-    public String getTimestamp()
+    public String getLastUpdated()
     {
-        return timestamp;
+        return lastUpdated;
     }
 
-    public void setTimestamp( String timestamp )
+    public void setLastUpdated( String lastUpdated )
     {
-        this.timestamp = timestamp;
+        this.lastUpdated = lastUpdated;
     }
 
     @JsonProperty

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingCsvDataValue.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingCsvDataValue.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingCsvDataValue.java	2013-12-10 18:10:47 +0000
@@ -28,28 +28,28 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.system.util.TextUtils.valueOf;
+import com.csvreader.CsvWriter;
 
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import com.csvreader.CsvWriter;
+import static org.hisp.dhis.system.util.TextUtils.valueOf;
 
 public class StreamingCsvDataValue
     extends DataValue
 {
     private CsvWriter writer;
-    
+
     private List<String> values;
-    
+
     public StreamingCsvDataValue( CsvWriter writer )
     {
         this.writer = writer;
         this.values = new ArrayList<String>();
     }
-    
+
     public StreamingCsvDataValue( String[] row )
     {
         this.values = Arrays.asList( row );
@@ -63,7 +63,7 @@
     {
         return index >= 0 && index < values.size() ? values.get( index ) : null;
     }
-    
+
     //--------------------------------------------------------------------------
     // Getters
     //--------------------------------------------------------------------------
@@ -105,9 +105,9 @@
     }
 
     @Override
-    public String getTimestamp()
+    public String getLastUpdated()
     {
-        return timestamp = timestamp == null ? getValue( 6 ) : timestamp;
+        return lastUpdated = lastUpdated == null ? getValue( 6 ) : lastUpdated;
     }
 
     @Override
@@ -163,9 +163,9 @@
     }
 
     @Override
-    public void setTimestamp( String timestamp )
+    public void setLastUpdated( String lastUpdated )
     {
-        values.add( timestamp );
+        values.add( lastUpdated );
     }
 
     @Override
@@ -184,7 +184,7 @@
     public void close()
     {
         String[] row = new String[values.size()];
-        
+
         try
         {
             writer.writeRecord( values.toArray( row ) );
@@ -194,14 +194,14 @@
             throw new RuntimeException( "Failed to write CSV record", ex );
         }
     }
-    
+
     public static String[] getHeaders()
     {
-        String[] headers = { 
-            "dataelement", "period", "orgunit", 
-            "categoryoptioncombo", "value", "storedby", 
-            "timestamp", "comment", "followup" };
-        
+        String[] headers = {
+            "dataelement", "period", "orgunit",
+            "categoryoptioncombo", "value", "storedby",
+            "lastupdated", "comment", "followup" };
+
         return headers;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingDataValue.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingDataValue.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingDataValue.java	2013-12-10 18:10:47 +0000
@@ -28,11 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.system.util.TextUtils.valueOf;
-
 import org.amplecode.staxwax.reader.XMLReader;
 import org.amplecode.staxwax.writer.XMLWriter;
 
+import static org.hisp.dhis.system.util.TextUtils.valueOf;
+
 public class StreamingDataValue
     extends DataValue
 {
@@ -43,12 +43,12 @@
     private static final String FIELD_ORGUNIT = "orgUnit";
     private static final String FIELD_VALUE = "value";
     private static final String FIELD_STOREDBY = "storedBy";
-    private static final String FIELD_TIMESTAMP = "timestamp";
+    private static final String FIELD_LAST_UPDATED = "lastUpdated";
     private static final String FIELD_COMMENT = "comment";
     private static final String FIELD_FOLLOWUP = "followUp";
-    
+
     private XMLWriter writer;
-    
+
     private XMLReader reader;
 
     //--------------------------------------------------------------------------
@@ -58,10 +58,10 @@
     public StreamingDataValue( XMLWriter writer )
     {
         this.writer = writer;
-        
+
         this.writer.openElement( FIELD_DATAVALUE );
     }
-    
+
     public StreamingDataValue( XMLReader reader )
     {
         this.reader = reader;
@@ -108,9 +108,9 @@
     }
 
     @Override
-    public String getTimestamp()
+    public String getLastUpdated()
     {
-        return timestamp = timestamp == null ? reader.getAttributeValue( FIELD_TIMESTAMP ) : timestamp;
+        return lastUpdated = lastUpdated == null ? reader.getAttributeValue( FIELD_LAST_UPDATED ) : lastUpdated;
     }
 
     @Override
@@ -166,9 +166,9 @@
     }
 
     @Override
-    public void setTimestamp( String timestamp )
+    public void setLastUpdated( String lastUpdated )
     {
-        writer.writeAttribute( FIELD_TIMESTAMP, timestamp );
+        writer.writeAttribute( FIELD_LAST_UPDATED, lastUpdated );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2013-12-08 21:46:50 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2013-12-10 18:10:47 +0000
@@ -409,7 +409,7 @@
                 internalValue.setStoredBy( dataValue.getStoredBy() );
             }
 
-            internalValue.setTimestamp( getDefaultDate( dataValue.getTimestamp() ) );
+            internalValue.setTimestamp( getDefaultDate( dataValue.getLastUpdated() ) );
             internalValue.setComment( dataValue.getComment() );
             internalValue.setFollowup( dataValue.getFollowup() );
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java	2013-12-10 18:10:47 +0000
@@ -28,16 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
-import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
-import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
-
-import java.io.OutputStream;
-import java.io.Writer;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Set;
-
+import com.csvreader.CsvWriter;
 import org.amplecode.staxwax.factory.XMLFactory;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
@@ -46,17 +37,29 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.system.util.StreamUtils;
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.support.rowset.SqlRowSet;
 
-import com.csvreader.CsvWriter;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Set;
+
+import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
+import static org.hisp.dhis.system.util.DateUtils.getLongDateString;
+import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
+import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
 
 public class SpringDataValueSetStore
     implements DataValueSetStore
 {
     private static final char CSV_DELIM = ',';
-    
+
     @Autowired
     private JdbcTemplate jdbcTemplate;
 
@@ -64,68 +67,78 @@
     // DataValueSetStore implementation
     //--------------------------------------------------------------------------
 
-    public void writeDataValueSetXml( DataSet dataSet, Date completeDate, Period period, OrganisationUnit orgUnit, 
+    public void writeDataValueSetXml( DataSet dataSet, Date completeDate, Period period, OrganisationUnit orgUnit,
         Set<DataElement> dataElements, Set<Period> periods, Set<OrganisationUnit> orgUnits, OutputStream out )
     {
         DataValueSet dataValueSet = new StreamingDataValueSet( XMLFactory.getXMLWriter( out ) );
-        
+
         writeDataValueSet( dataSet, completeDate, period, orgUnit, dataElements, periods, orgUnits, dataValueSet );
-        
+
         StreamUtils.closeOutputStream( out );
     }
-    
+
     public void writeDataValueSetCsv( Set<DataElement> dataElements, Set<Period> periods, Set<OrganisationUnit> orgUnits, Writer writer )
     {
         DataValueSet dataValueSet = new StreamingCsvDataValueSet( new CsvWriter( writer, CSV_DELIM ) );
-        
+
         writeDataValueSet( null, null, null, null, dataElements, periods, orgUnits, dataValueSet );
     }
-    
-    private void writeDataValueSet( DataSet dataSet, Date completeDate, Period period, OrganisationUnit orgUnit, 
+
+    private void writeDataValueSet( DataSet dataSet, Date completeDate, Period period, OrganisationUnit orgUnit,
         Set<DataElement> dataElements, Set<Period> periods, Set<OrganisationUnit> orgUnits, DataValueSet dataValueSet )
-    {        
+    {
         SqlRowSet rowSet = jdbcTemplate.queryForRowSet( getDataValueSql( dataElements, periods, orgUnits ) );
+        DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
 
         dataValueSet.setDataSet( dataSet != null ? dataSet.getUid() : null );
         dataValueSet.setCompleteDate( getMediumDateString( completeDate ) );
         dataValueSet.setPeriod( period != null ? period.getIsoDate() : null );
         dataValueSet.setOrgUnit( orgUnit != null ? orgUnit.getUid() : null );
-        
+
+
         while ( rowSet.next() )
         {
             DataValue dataValue = dataValueSet.getDataValueInstance();
-            
+
             String periodType = rowSet.getString( "name" );
             Date startDate = rowSet.getDate( "startdate" );
             Period isoPeriod = PeriodType.getPeriodTypeByName( periodType ).createPeriod( startDate );
-            
+
             dataValue.setDataElement( rowSet.getString( "deuid" ) );
             dataValue.setPeriod( isoPeriod.getIsoDate() );
             dataValue.setOrgUnit( rowSet.getString( "ouuid" ) );
             dataValue.setCategoryOptionCombo( rowSet.getString( "cocuid" ) );
             dataValue.setValue( rowSet.getString( "value" ) );
             dataValue.setStoredBy( rowSet.getString( "storedby" ) );
-            dataValue.setTimestamp( getMediumDateString( rowSet.getDate( "lastupdated" ) ) );
+
+            java.sql.Date lastUpdated = rowSet.getDate( "lastupdated" );
+
+            if ( lastUpdated != null )
+            {
+                DateTime dt = new DateTime( lastUpdated );
+                dataValue.setLastUpdated( fmt.print( dt ) );
+            }
+
             dataValue.setComment( rowSet.getString( "comment" ) );
-            dataValue.setFollowup( rowSet.getBoolean( "followup" ) );            
+            dataValue.setFollowup( rowSet.getBoolean( "followup" ) );
             dataValue.close();
         }
-        
+
         dataValueSet.close();
     }
-    
+
     private String getDataValueSql( Collection<DataElement> dataElements, Collection<Period> periods, Collection<OrganisationUnit> orgUnits )
     {
         return
             "select de.uid as deuid, pe.startdate, pt.name, ou.uid as ouuid, coc.uid as cocuid, dv.value, dv.storedby, dv.lastupdated, dv.comment, dv.followup " +
-            "from datavalue dv " +
-            "join dataelement de on (dv.dataelementid=de.dataelementid) " +
-            "join period pe on (dv.periodid=pe.periodid) " +
-            "join periodtype pt on (pe.periodtypeid=pt.periodtypeid) " +
-            "join organisationunit ou on (dv.sourceid=ou.organisationunitid) " +
-            "join categoryoptioncombo coc on (dv.categoryoptioncomboid=coc.categoryoptioncomboid) " +
-            "where dv.dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " +
-            "and dv.periodid in (" + getCommaDelimitedString( getIdentifiers( Period.class, periods ) ) + ") " +
-            "and dv.sourceid in (" + getCommaDelimitedString( getIdentifiers( OrganisationUnit.class, orgUnits ) ) + ")";
+                "from datavalue dv " +
+                "join dataelement de on (dv.dataelementid=de.dataelementid) " +
+                "join period pe on (dv.periodid=pe.periodid) " +
+                "join periodtype pt on (pe.periodtypeid=pt.periodtypeid) " +
+                "join organisationunit ou on (dv.sourceid=ou.organisationunitid) " +
+                "join categoryoptioncombo coc on (dv.categoryoptioncomboid=coc.categoryoptioncomboid) " +
+                "where dv.dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " +
+                "and dv.periodid in (" + getCommaDelimitedString( getIdentifiers( Period.class, periods ) ) + ") " +
+                "and dv.sourceid in (" + getCommaDelimitedString( getIdentifiers( OrganisationUnit.class, orgUnits ) ) + ")";
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java	2013-12-10 18:10:47 +0000
@@ -51,11 +51,11 @@
     private static final String FIELD_COMPLETEDATE = "completeDate";
     private static final String FIELD_PERIOD = "period";
     private static final String FIELD_ORGUNIT = "orgUnit";
-    
+
     private XMLWriter writer;
-    
+
     private XMLReader reader;
-    
+
     //--------------------------------------------------------------------------
     // Constructor
     //--------------------------------------------------------------------------
@@ -63,7 +63,7 @@
     public StreamingDataValueSet( XMLWriter writer )
     {
         this.writer = writer;
-        
+
         this.writer.openDocument();
         this.writer.openElement( FIELD_DATAVALUESET );
         this.writer.writeAttribute( XMLNS, NS );
@@ -72,10 +72,9 @@
     public StreamingDataValueSet( XMLReader reader )
     {
         this.reader = reader;
-        
-        this.reader.moveToStartElement( FIELD_DATAVALUESET );        
+        this.reader.moveToStartElement( FIELD_DATAVALUESET );
     }
-    
+
     //--------------------------------------------------------------------------
     // Getters
     //--------------------------------------------------------------------------
@@ -91,11 +90,11 @@
     {
         return orgUnitIdScheme = orgUnitIdScheme == null ? reader.getAttributeValue( FIELD_ORGUNITIDSCHEME ) : orgUnitIdScheme;
     }
-    
+
     @Override
     public Boolean getDryRun()
     {
-        return dryRun = dryRun == null ? ( TRUE.equals( reader.getAttributeValue( FIELD_DRYRUN ) ) ? Boolean.TRUE : null ) : dryRun;
+        return dryRun = dryRun == null ? (TRUE.equals( reader.getAttributeValue( FIELD_DRYRUN ) ) ? Boolean.TRUE : null) : dryRun;
     }
 
     @Override
@@ -113,7 +112,7 @@
     @Override
     public String getCompleteDate()
     {
-        return completeDate = completeDate == null ? reader.getAttributeValue( FIELD_COMPLETEDATE ) : completeDate; 
+        return completeDate = completeDate == null ? reader.getAttributeValue( FIELD_COMPLETEDATE ) : completeDate;
     }
 
     @Override
@@ -131,9 +130,9 @@
     @Override
     public boolean hasNextDataValue()
     {
-        return reader.moveToStartElement( FIELD_DATAVALUE, FIELD_DATAVALUESET );        
+        return reader.moveToStartElement( FIELD_DATAVALUE, FIELD_DATAVALUESET );
     }
-    
+
     @Override
     public DataValue getNextDataValue()
     {
@@ -179,7 +178,7 @@
     {
         writer.writeAttribute( FIELD_ORGUNIT, orgUnit );
     }
-    
+
     @Override
     public DataValue getDataValueInstance()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java	2013-11-26 08:13:23 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java	2013-12-10 18:10:47 +0000
@@ -255,7 +255,7 @@
                         dataValue.setStoredBy( DATAVALUE_IMPORT_STOREBY );
                         dataValue.setComment( DATAVALUE_IMPORT_COMMENT );
                         dataValue.setFollowup( false );
-                        dataValue.setTimestamp( new SimpleDateFormat( DATAVALUE_IMPORT_TIMESTAMP_DATEFORMAT )
+                        dataValue.setLastUpdated( new SimpleDateFormat( DATAVALUE_IMPORT_TIMESTAMP_DATEFORMAT )
                             .format( new Date() ) );
 
                         dataValueList.add( dataValue );