← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7429: Further tweaks of 1.4 XML import. Fixes faulty logic of previous commit + Codestyle

 

------------------------------------------------------------
revno: 7429
committer: Jason P. Pickering <jason.p.pickering@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-06-27 14:47:25 +0200
message:
  Further tweaks of 1.4 XML import. Fixes faulty logic of previous commit + Codestyle
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-27 09:14:59 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java	2012-06-27 12:47:25 +0000
@@ -73,7 +73,6 @@
     extends DataValueImporter
     implements CSVConverter
 {
-   
     private static final String SEPARATOR = ",";
 
     private static final String FILENAME = "RoutineData.txt";
@@ -234,13 +233,18 @@
                 value.setPeriod( period );
                 value.setSource( organisationUnit );
 
-                if ( values[4] != null  ) // Text
+                if ( !values[6].isEmpty() ) // Numeric
+                {
+                    value.setValue( handleNumericValue( values[6] ) );
+                    validValue = isValidNumeric( value.getValue() );
+
+                }
+                else if ( !values[4].isEmpty() ) // Text
                 {
                     value.setValue( values[4].trim() );
                 }
-                else if ( values[5] != null ) // Boolean
+                else if ( !values[5].isEmpty() ) // Boolean
                 {
-
                     value.setValue( "false" );
 
                     if ( values[5].trim().equals( "1" ) )
@@ -249,40 +253,27 @@
                     }
 
                 }
-                else if ( values[6] != null  ) // Numeric
-                {
-                    value.setValue( handleNumericValue( values[6] ) );
-                    validValue = isValidNumeric( value.getValue() );
-                }
-                else if ( values[7] != null ) // Date
-                {
-                    try
-                    {
-                        value.setValue(   DateUtils.getDefaultDate( Dhis14DateUtil.getDate( values[7] ).toString() ).toString() ); 
-                    }
-                    catch ( Exception e )
-                    {
-                        validValue = false;
-                    }
-                }
-                else if ( values[8] != null ) // Memo not supported
- 
+                else if ( !values[7].isEmpty() ) // Date
+                {
+                    value.setValue( values[7] );
+
+                }
+                else if ( !values[8].isEmpty() ) // Memo not supported
                 {
                     validValue = false;
                 }
 
-                else if ( values[9] != null  ) // OLE not supported
-                                                                      
+                else if ( !values[9].isEmpty() ) // OLE not supported
                 {
                     validValue = false;
                 }
 
                 value.setComment( values[13] );
-                value.setTimestamp( DateUtils.getDefaultDate( Dhis14DateUtil.getDate( values[15] ).toString() ) );
+                value.setTimestamp( DateUtils.getDefaultDate( values[15] ) );
                 value.setOptionCombo( proxyCategoryOptionCombo );
                 value.setStoredBy( owner );
 
-                if ( validValue && value.getValue() != null )
+                if ( validValue )
                 {
                     importObject( value, params );
                 }
@@ -307,7 +298,7 @@
             // Remove all quotes
             value = value.replaceAll( "\"", "" );
             // Strip trailing zeros
-            value = value.replaceFirst( "\\.0+$", "" );
+            value = value.replaceAll( "\\.0+$", "" );
         }
 
         return value;
@@ -338,22 +329,24 @@
             else if ( dataElementType.equals( DataElement.VALUE_TYPE_BOOL ) )
             {
                 String outputValue;
-                if ( value.getValue().equals( "true" ) )  {
+                if ( value.getValue().equals( "true" ) )
+                {
                     outputValue = "1";
                 }
-                else outputValue = "0";
+                else
+                    outputValue = "0";
                 out.write( SEPARATOR_B );
-                out.write( getCsvValue( csvEncode( outputValue) ) );
+                out.write( getCsvValue( csvEncode( outputValue ) ) );
                 out.write( SEPARATOR_B );
                 out.write( SEPARATOR_B );
                 out.write( SEPARATOR_B );
                 out.write( SEPARATOR_B );
             }
 
-            else if ( dataElementType.equals( DataElement.VALUE_TYPE_NUMBER) ||
-                      dataElementType.equals( DataElement.VALUE_TYPE_INT ) ||
-                      dataElementType.equals( DataElement.VALUE_TYPE_NEGATIVE_INT ) ||
-                      dataElementType.equals( DataElement.VALUE_TYPE_POSITIVE_INT ) )
+            else if ( dataElementType.equals( DataElement.VALUE_TYPE_NUMBER )
+                || dataElementType.equals( DataElement.VALUE_TYPE_INT )
+                || dataElementType.equals( DataElement.VALUE_TYPE_NEGATIVE_INT )
+                || dataElementType.equals( DataElement.VALUE_TYPE_POSITIVE_INT ) )
             {
                 out.write( SEPARATOR_B );
                 out.write( SEPARATOR_B );
@@ -368,7 +361,7 @@
                 out.write( SEPARATOR_B );
                 out.write( SEPARATOR_B );
                 out.write( SEPARATOR_B );
-                out.write( getCsvValue( csvEncode( DateUtils.getAccessDateString( DateUtils.getDefaultDate( value.getValue() ) ) ) ) );
+                out.write( getCsvValue( csvEncode( DateUtils.getDefaultDate( value.getValue() ) ) ) );
                 out.write( SEPARATOR_B );
                 out.write( SEPARATOR_B );
             }