← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6586: Improved error handling in import

 

------------------------------------------------------------
revno: 6586
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-04-15 22:21:18 +0200
message:
  Improved error handling in import
modified:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportDataValueTask.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importSummary.vm


--
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-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2012-04-15 15:05:28 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2012-04-15 20:21:18 +0000
@@ -32,6 +32,7 @@
 import static org.hisp.dhis.importexport.ImportStrategy.UPDATES;
 import static org.hisp.dhis.scheduling.TaskCategory.DATAVALUE_IMPORT;
 import static org.hisp.dhis.system.notification.NotificationLevel.INFO;
+import static org.hisp.dhis.system.notification.NotificationLevel.ERROR;
 import static org.hisp.dhis.system.util.ConversionUtils.wrap;
 import static org.hisp.dhis.system.util.DateUtils.getDefaultDate;
 
@@ -179,16 +180,30 @@
     
     public ImportSummary saveDataValueSet( InputStream in, ImportOptions importOptions, TaskId id )
     {
-        DataValueSet dataValueSet = new StreamingDataValueSet( XMLFactory.getXMLReader( in ) );
-        
-        return saveDataValueSet( importOptions, id, dataValueSet );
+        try
+        {
+            DataValueSet dataValueSet = new StreamingDataValueSet( XMLFactory.getXMLReader( in ) );        
+            return saveDataValueSet( importOptions, id, dataValueSet );
+        }
+        catch ( RuntimeException ex )
+        {
+            notifier.notify( id, DATAVALUE_IMPORT, ERROR, "Unfortunately the process failed, check the logs", true );            
+            throw ex;
+        }
     }
 
     public ImportSummary saveDataValueSetCsv( Reader reader, ImportOptions importOptions, TaskId id )
     {
-        DataValueSet dataValueSet = new StreamingCsvDataValueSet( new CSVReader( reader ) );
-        
-        return saveDataValueSet( importOptions, id, dataValueSet );
+        try
+        {
+            DataValueSet dataValueSet = new StreamingCsvDataValueSet( new CSVReader( reader ) );        
+            return saveDataValueSet( importOptions, id, dataValueSet );
+        }
+        catch ( RuntimeException ex )
+        {
+            notifier.clear( id, DATAVALUE_IMPORT ).notify( id, DATAVALUE_IMPORT, ERROR, "Unfortunately the process failed, check the logs", true );            
+            throw ex;
+        }
     }
     
     private ImportSummary saveDataValueSet( ImportOptions importOptions, TaskId id, DataValueSet dataValueSet )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java	2012-04-13 14:09:59 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java	2012-04-15 20:21:18 +0000
@@ -36,6 +36,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.api.webdomain.DataValueSets;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSet;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
@@ -46,6 +47,7 @@
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -98,4 +100,11 @@
         response.setContentType( CONTENT_TYPE_XML );        
         JacksonUtils.toXml( response.getOutputStream(), summary );
     }
+    
+    @ExceptionHandler(IllegalArgumentException.class)
+    public void handleError( IllegalArgumentException ex, HttpServletResponse response )
+        throws IOException
+    {
+        ContextUtils.conflictResponse( response, ex.getMessage() );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java	2012-04-14 15:02:08 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java	2012-04-15 20:21:18 +0000
@@ -124,10 +124,10 @@
         }
     }
 
-    public static void errorResponse( HttpServletResponse response, String message )
+    public static void conflictResponse( HttpServletResponse response, String message )
         throws IOException
     {
-        response.setStatus( HttpServletResponse.SC_BAD_REQUEST );
+        response.setStatus( HttpServletResponse.SC_CONFLICT );
         response.setContentType( CONTENT_TYPE_TEXT );
 
         PrintWriter writer = response.getWriter();

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportDataValueTask.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportDataValueTask.java	2012-04-15 19:45:25 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportDataValueTask.java	2012-04-15 20:21:18 +0000
@@ -62,7 +62,6 @@
     @Override
     public void run()
     {
-        System.out.println( "F " + format);
         if ( FORMAT_CSV.equals( format ) )
         {
             dataValueSetService.saveDataValueSetCsv( reader, options, taskId );

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties	2012-04-15 19:45:25 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties	2012-04-15 20:21:18 +0000
@@ -291,4 +291,5 @@
 csv=CSV
 xml=XML
 xml_data_import=XML Data Import
-csv_data_import=CSV Data Import
\ No newline at end of file
+csv_data_import=CSV Data Import
+no_data_values_found=No data values found
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importSummary.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importSummary.vm	2012-04-14 21:03:54 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importSummary.vm	2012-04-15 20:21:18 +0000
@@ -1,7 +1,7 @@
 
 <h3>$i18n.getString( "import_summary" )</h3>
 
-#if( ${summary.dataSetComplete} != "false" )
+#if( ${summary.dataSetComplete} && ${summary.dataSetComplete} != "false" )
 <p>$i18n.getString( "data_set_completed_on" ) ${summary.dataSetComplete}</p>
 #end