← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6585: UI for csv data value import

 

------------------------------------------------------------
revno: 6585
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-04-15 21:45:25 +0200
message:
  UI for csv data value import
modified:
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/NoAction.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ImportDataValueAction.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/resources/struts.xml
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importDataValue.vm
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/index.vm
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/mainMenu.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-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/NoAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/NoAction.java	2012-04-13 22:38:23 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/NoAction.java	2012-04-15 19:45:25 +0000
@@ -47,16 +47,15 @@
         this.running = running;
     }
     
-    private String exportFormat;
+    private String importFormat;
     
-    public String getExportFormat()
+    public String getImportFormat()
     {
-        return exportFormat;
+        return importFormat;
     }
-    
-    public void setExportFormat( String exportFormat )
+    public void setImportFormat( String importFormat )
     {
-        this.exportFormat = exportFormat;
+        this.importFormat = importFormat;
     }
     
     public String execute()

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ImportDataValueAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ImportDataValueAction.java	2012-04-12 12:39:47 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ImportDataValueAction.java	2012-04-15 19:45:25 +0000
@@ -28,11 +28,16 @@
  */
 
 import java.io.BufferedInputStream;
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 
+import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
+import org.hisp.dhis.dxf2.metadata.ImportOptions;
 import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.importexport.action.util.ImportDataValueTask;
 import org.hisp.dhis.scheduling.TaskCategory;
@@ -43,6 +48,8 @@
 
 import com.opensymphony.xwork2.Action;
 
+import static org.hisp.dhis.importexport.action.util.ImportDataValueTask.FORMAT_CSV;
+
 /**
  * @author Lars Helge Overland
  */
@@ -82,6 +89,18 @@
     {
         this.strategy = ImportStrategy.valueOf( stgy );
     }
+    
+    private String importFormat;
+
+    public void setImportFormat( String importFormat )
+    {
+        this.importFormat = importFormat;
+    }
+
+    public String getImportFormat()
+    {
+        return importFormat;
+    }
 
     // -------------------------------------------------------------------------
     // Action implementation
@@ -91,10 +110,14 @@
         throws Exception
     {
         final TaskId taskId = new TaskId( TaskCategory.DATAVALUE_IMPORT, currentUserService.getCurrentUser() );
-        
-        final InputStream in = new BufferedInputStream( new FileInputStream( upload ) ); 
-
-        scheduler.executeTask( new ImportDataValueTask( dataValueSetService, in, dryRun, strategy, taskId ) );
+
+        final ImportOptions options = new ImportOptions( IdentifiableProperty.UID, IdentifiableProperty.UID, dryRun, strategy );
+        
+        final InputStream in = !FORMAT_CSV.equals( importFormat ) ? new BufferedInputStream( new FileInputStream( upload ) ) : null;
+        
+        final Reader reader = FORMAT_CSV.equals( importFormat ) ? new BufferedReader( new InputStreamReader( new FileInputStream( upload ) ) ) : null;
+
+        scheduler.executeTask( new ImportDataValueTask( dataValueSetService, in, reader, options, taskId, importFormat ) );
         
         return SUCCESS;
     }

=== 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-12 12:39:47 +0000
+++ 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
@@ -28,11 +28,10 @@
  */
 
 import java.io.InputStream;
+import java.io.Reader;
 
-import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
 import org.hisp.dhis.dxf2.metadata.ImportOptions;
-import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.scheduling.TaskId;
 
 /**
@@ -40,25 +39,37 @@
  */
 public class ImportDataValueTask
     implements Runnable
-{    
+{
+    public static final String FORMAT_CSV = "csv";
+    
     private DataValueSetService dataValueSetService;
     private InputStream in;
-    private boolean dryRun;
-    private ImportStrategy strategy;
+    private Reader reader;
+    private ImportOptions options;
     private TaskId taskId;
+    private String format;
     
-    public ImportDataValueTask( DataValueSetService dataValueSetService, InputStream in, boolean dryRun, ImportStrategy strategy, TaskId taskId )
+    public ImportDataValueTask( DataValueSetService dataValueSetService, InputStream in, Reader reader, ImportOptions options, TaskId taskId, String format )
     {
         this.dataValueSetService = dataValueSetService;
         this.in = in;
-        this.dryRun = dryRun;
-        this.strategy = strategy;
+        this.reader = reader;
+        this.options = options;
         this.taskId = taskId;
+        this.format = format;
     }
     
     @Override
     public void run()
     {
-        dataValueSetService.saveDataValueSet( in, new ImportOptions( IdentifiableProperty.UID, IdentifiableProperty.UID, dryRun, strategy ), taskId );
+        System.out.println( "F " + format);
+        if ( FORMAT_CSV.equals( format ) )
+        {
+            dataValueSetService.saveDataValueSetCsv( reader, options, taskId );
+        }
+        else
+        {
+            dataValueSetService.saveDataValueSet( in, 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-14 18:32:00 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties	2012-04-15 19:45:25 +0000
@@ -262,7 +262,8 @@
 intro_pdf_metadata_export=Portable Document Format (PDF) is a commonly used file format for document exchange.
 intro_xls_metadata_export=Excel Spreadsheet (XLS) is a commonly used spreadsheet file format from Microsoft.
 intro_import=This is the regular import function which imports data from the DHIS 2 exchange format called DXF.
-intro_data_import=Import data values on the DXF format, which is used for data exchange by DHIS and other third-party software. 
+intro_xml_data_import=Import data values on the DXF XML format which is used for data exchange by DHIS and other software.
+intro_csv_data_import=Import data values on the CSV format which is used for data exchange by DHIS and other third-party software.
 intro_dhis14_import=Import data from DHIS 1.4 installations. DHIS 1.4 is the predecessor of DHIS 2.
 intro_data_export=Export data values. This is the regular export function which exports data to the DHIS 2 exchange format called DXF.
 intro_metadata_export=Export meta data to the DHIS 2 exchange format. Meta meta implies data elements and other objects describing the data.
@@ -286,4 +287,8 @@
 type=Type
 count=Count
 export_as_xml=Export as XML
-export_as_csv=Export as CSV
\ No newline at end of file
+export_as_csv=Export as CSV
+csv=CSV
+xml=XML
+xml_data_import=XML Data Import
+csv_data_import=CSV Data Import
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/resources/struts.xml	2012-04-13 22:38:23 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/resources/struts.xml	2012-04-15 19:45:25 +0000
@@ -24,7 +24,7 @@
 	</action>
 		
 	<action name="importDataValue" class="org.hisp.dhis.importexport.action.datavalue.ImportDataValueAction">
-	  <result name="success" type="redirect">displayImportDataValueForm.action?running=true</result>
+	  <result name="success" type="redirect">displayImportDataValueForm.action?running=true&amp;importFormat=${importFormat}</result>
       <interceptor-ref name="fileUploadStack" />
 	</action>
 

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importDataValue.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importDataValue.vm	2012-04-14 21:03:54 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/importDataValue.vm	2012-04-15 19:45:25 +0000
@@ -1,8 +1,8 @@
 
-<h3>$i18n.getString( "data_import" )</h3>
+<h3>$!i18n.getString( $importFormat ) $i18n.getString( "data_import" )</h3>
 
 <div class="inputCriteria" style="height:130px">
-<form id="importForm" name="importForm" method="post" enctype="multipart/form-data" action="importDataValue.action">
+<form id="importForm" name="importForm" method="post" enctype="multipart/form-data" action="importDataValue.action?importFormat=$!{importFormat}">
 <table>
 <col width="80">
 <col>
@@ -51,4 +51,4 @@
 
 #end
 
-<div id="importSummaryDiv" class="page formSection" style="display:none; width:400px;"></div>
\ No newline at end of file
+<div id="importSummaryDiv" class="page formSection" style="display:none; width:400px; padding-bottom:20px;"></div>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/index.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/index.vm	2012-04-13 22:38:23 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/index.vm	2012-04-15 19:45:25 +0000
@@ -9,7 +9,8 @@
 
 <ul class="introList">
 	#introListImgItem( "setImportFormat.action?importFormat=DXF" "import" "import" )
-	#introListImgItem( "displayImportDataValueForm.action" "data_import" "import" )
+	#introListImgItem( "displayImportDataValueForm.action?importFormat=xml" "xml_data_import" "import" )
+	#introListImgItem( "displayImportDataValueForm.action?importFormat=csv" "csv_data_import" "import" )
 	#introListImgItem( "displayExternalImportMenu.action" "dhis14_import" "import" )
 	
     #introListImgItem( "displayDataValueExportForm.action?exportFormat=DXF" "data_export" "export" )

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/mainMenu.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/mainMenu.vm	2012-04-13 22:38:23 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/mainMenu.vm	2012-04-15 19:45:25 +0000
@@ -3,7 +3,8 @@
 
 <ul>
   <li><a href="setImportFormat.action?importFormat=DXF">$i18n.getString( "import" )&nbsp;</a></li>
-  <li><a href="displayImportDataValueForm.action">$i18n.getString( "data_import" )&nbsp;</a></li>
+  <li><a href="displayImportDataValueForm.action?importFormat=xml">$i18n.getString( "xml_data_import" )&nbsp;</a></li>
+  <li><a href="displayImportDataValueForm.action?importFormat=csv">$i18n.getString( "csv_data_import" )&nbsp;</a></li>
   <li><a href="displayExternalImportMenu.action">$i18n.getString( "dhis14_import" )&nbsp;</a></li>
 </ul>