← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7378: (DHIS1.4) Import/Export WIP

 

------------------------------------------------------------
revno: 7378
committer: Jason P. Pickering <jason.p.pickering@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-06-25 10:34:16 +0200
message:
  (DHIS1.4) Import/Export WIP
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.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-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	2012-06-24 06:15:05 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java	2012-06-25 08:34:16 +0000
@@ -63,7 +63,7 @@
 {
     private static final String SEPARATOR = ",";
     private static final String FILENAME = "RoutineData.txt";
-    
+
     private DataElementCategoryService categoryService;
     private PeriodService periodService;
     private StatementManager statementManager;
@@ -153,7 +153,7 @@
                             values = aggregatedDataValueService.getDeflatedDataValues( element, period.getId(), params.getOrganisationUnits() );
                             
                             for ( final DeflatedDataValue value : values )
-                            {   
+                            {
                                 out.write( getCsvValue( 0 ) );
                                 out.write( getCsvValue( value.getSourceId() ) );
                                 out.write( getCsvValue( value.getDataElementId() ) );
@@ -215,7 +215,29 @@
                 value.setDataElement( dataElement );
                 value.setPeriod( period );
                 value.setSource( organisationUnit );
-                value.setValue( handleValue( values[6] ) );
+                //Text
+                if ( values[4] != null || !values[4].isEmpty() )
+                {
+                    value.setValue( values[4].trim() );
+                }
+                //Yes=1,No=0
+                if ( values[5] != null || !values[5].isEmpty() )
+                {
+                    value.setValue("false");
+
+                    if  ( values[5].trim() == "1" )
+                    {
+                        value.setValue("true");
+                    }
+
+                }
+                //Numbers
+                if ( values[6] != null  || !values[6].isEmpty() )
+                {
+                value.setValue( handleNumericValue( values[6] ) );
+
+                }
+
                 value.setComment( values[13] );
                 value.setOptionCombo( proxyCategoryOptionCombo );
                 
@@ -232,16 +254,59 @@
     // CSVConverter implementation
     // -------------------------------------------------------------------------
     
-    private String handleValue( String value )
+    private String handleNumericValue( String value )
     {
-        if ( value != null )
+        if ( value != null  )
         {
+            //Remove all spaces
+            value = value.replaceAll(" ", "");
+            //Remove all quotes
             value = value.replaceAll( "\"", "" );
-            //FIXME We need to have more robust handling of values
-            //Import them as is for now.
-            //value = value.replace( ".", "" );
+            //Strip trailing zeros
+            value = value.replaceAll( "\\.0+$", "" );
         }
+
         
         return value;
     }
+
+    private static boolean isValidNumeric (String value)
+    {
+        if ( value == null )
+        {
+            return false;
+        }
+        else
+        {
+            return value.matches("-?\\d+(\\.\\d+)?");
+        }
+    }
+
+    private static Integer exportCSVField (DataElement dataElement)
+    {
+        String dataElementType = dataElement.getType();
+        Integer csvField = null;
+
+        if ( dataElementType == DataElement.VALUE_TYPE_STRING)
+        {
+            csvField =   4;
+        }
+
+        if ( dataElementType == DataElement.VALUE_TYPE_BOOL )
+        {
+            csvField = 5;
+        }
+
+        if ( dataElementType == DataElement.VALUE_TYPE_NUMBER )
+        {
+            csvField =  6;
+        }
+
+        if ( dataElementType == DataElement.VALUE_TYPE_DATE )
+        {
+            csvField =  7;
+        }
+
+        return csvField;
+    }
 }