← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17443: Import, combined all meta-data import formats on same screen

 

------------------------------------------------------------
revno: 17443
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-11-11 21:57:25 +0100
message:
  Import, combined all meta-data import formats on same screen
modified:
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataTask.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataExport.vm
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataImport.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/javascript/importMetaData.js
  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/dxf2/MetaDataImportAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java	2014-10-10 14:07:30 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java	2014-11-11 20:57:25 +0000
@@ -168,21 +168,21 @@
 
         String userId = user != null ? user.getUid() : null;
 
-        switch( importFormat )
-        {
-            case "csv":
-                if( classKey != null && KEY_CLASS_MAP.get( classKey ) != null )
-                {
-                    scheduler.executeTask( new ImportMetaDataCsvTask( userId, importService, csvImportService,
-                        importOptions, in, taskId, KEY_CLASS_MAP.get( classKey ) ) );
-                }
-                break;
-            case "gml":
-                scheduler.executeTask( new ImportMetaDataGmlTask( userId, gmlImportService, importOptions, in, taskId ) );
-                break;
-            default:
-                scheduler.executeTask( new ImportMetaDataTask( userId, importService, importOptions, in, taskId ) );
-                break;
+        if ( "csv".equals( importFormat ) )
+        {
+            if( classKey != null && KEY_CLASS_MAP.get( classKey ) != null )
+            {
+                scheduler.executeTask( new ImportMetaDataCsvTask( userId, importService, csvImportService,
+                    importOptions, in, taskId, KEY_CLASS_MAP.get( classKey ) ) );
+            }
+        }
+        else if ( "gml".equals( importFormat ) )
+        {
+            scheduler.executeTask( new ImportMetaDataGmlTask( userId, gmlImportService, importOptions, in, taskId ) );
+        }
+        else if ( "json".equals( importFormat ) || "xml".equals( importFormat ) )
+        {
+            scheduler.executeTask( new ImportMetaDataTask( userId, importService, importOptions, in, taskId, importFormat ) );
         }
         
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataTask.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataTask.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataTask.java	2014-11-11 20:57:25 +0000
@@ -35,6 +35,7 @@
 import org.hisp.dhis.dxf2.metadata.MetaData;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.system.util.DebugUtils;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -47,6 +48,8 @@
 {
     private static final Log log = LogFactory.getLog( ImportMetaDataTask.class );
 
+    private String userUid;
+
     private ImportService importService;
 
     private ImportOptions importOptions;
@@ -55,16 +58,17 @@
 
     private TaskId taskId;
 
-    private String userUid;
+    private String format;
 
-    public ImportMetaDataTask( String userUid, ImportService importService, ImportOptions importOptions, InputStream inputStream,
-        TaskId taskId )
+    public ImportMetaDataTask( String userUid, ImportService importService, ImportOptions importOptions, 
+        InputStream inputStream, TaskId taskId, String format )
     {
+        this.userUid = userUid;
         this.importService = importService;
         this.importOptions = importOptions;
         this.inputStream = inputStream;
         this.taskId = taskId;
-        this.userUid = userUid;
+        this.format = format;
     }
 
     @Override
@@ -74,21 +78,21 @@
 
         try
         {
-            // TODO sniff if its xml or json, but this works for now
-            metaData = JacksonUtils.fromXml( inputStream, MetaData.class );
-        }
-        catch ( IOException ignored )
-        {
-            try
+            if ( "json".equals( format ) )
             {
                 metaData = JacksonUtils.fromJson( inputStream, MetaData.class );
             }
-            catch ( IOException ex )
+            else
             {
-                log.error( "(IOException) Unable to parse meta-data while reading input stream", ex );
-                return;
+                metaData = JacksonUtils.fromXml( inputStream, MetaData.class );
             }
         }
+        catch ( IOException ex )
+        {
+            log.error( DebugUtils.getStackTrace( ex ) );
+            
+            throw new RuntimeException( "Failed to parse meta data input stream", ex );
+        }
 
         importService.importMetaData( userUid, metaData, importOptions, taskId );
     }

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataExport.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataExport.vm	2014-08-26 10:30:33 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataExport.vm	2014-11-11 20:57:25 +0000
@@ -128,7 +128,7 @@
       <td colspan="2">
         <select id="format" style="width: 204px;">
           <option value="xml">XML</option>
-          <option value="json">Json</option>
+          <option value="json">JSON</option>
         </select>
       </td>
     </tr>

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataImport.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataImport.vm	2014-07-17 13:26:22 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataImport.vm	2014-11-11 20:57:25 +0000
@@ -1,8 +1,8 @@
 
-<h3>$!i18n.getString( $importFormat ) $i18n.getString( "metadata_import" )</h3>
+<h3>$i18n.getString( "metadata_import" )</h3>
 
 <div id="inputCriteria" class="inputCriteria" style="width: 380px">
-<form id="importForm" name="importForm" method="post" enctype="multipart/form-data" action="importMetaData.action?importFormat=$!{importFormat}">
+<form id="importForm" name="importForm" method="post" enctype="multipart/form-data" action="importMetaData.action">
 <table>
 <col width="140">
 <col>
@@ -10,8 +10,17 @@
 	<td>$i18n.getString( "file" )</td>
 	<td><input type="file" id="upload" name="upload" style="margin-left:0px"></td>
 </tr>
-#if ( "csv" == $importFormat )
 <tr>
+    <td>$i18n.getString( "format" )</td>
+    <td>
+        <select id="importFormat" name="importFormat" style="width: 190px;" onchange="metaDataImportFormatChanged()">
+            <option value="xml">XML</option>
+            <option value="json">JSON</option>
+            <option value="csv">CSV</option>
+        </select>
+    </td>
+</tr>
+<tr id="csvImportTr" style="display:none">
 	<td>$i18n.getString( "object_type" )</td>
 	<td><select id="classKey" name="classKey" style="width:190px">
         <option value="dataelement">$i18n.getString( "data_element" )</option>
@@ -23,8 +32,7 @@
         <option value="validationrule">$i18n.getString( "validation_rule" )</option>
         <option value="optionset">$i18n.getString( "option_set" )</option>
     </select></td>
-</tr>
-#end
+</tr>
 <tr>
 	<td>$i18n.getString( "dry_run" )</td>
 	<td><select id="dryRun" name="dryRun" style="width:190px">

=== 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	2014-11-11 20:22:58 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/index.vm	2014-11-11 20:57:25 +0000
@@ -1,11 +1,10 @@
 <h3>$i18n.getString( "dhis-web-importexport" )</h3>
 
 <ul class="introList">
-    #introListImgItem( "dxf2MetaDataImport.action?importFormat=xml" "xml_metadata_import" "import" )
-    #introListImgItem( "dxf2MetaDataImport.action?importFormat=csv" "csv_metadata_import" "import" )
+    #introListImgItem( "dxf2MetaDataImport.action" "metadata_import" "import" )
     #introListImgItem( "displayImportDataValueForm.action" "data_import" "import" )
+    #introListImgItem( "gmlImport.action" "gml_import" "import" )
     #introListImgItem( "displayEventImportForm.action" "event_data_import" "import" )
-    #introListImgItem( "gmlImport.action" "gml_import" "import" )
     #introListImgItem( "displayExternalImportMenu.action" "dhis14_import" "import" )
 
     #introListImgItem( "dxf2MetaDataExport.action" "metadata_export" "export" )

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/importMetaData.js'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/importMetaData.js	2014-10-10 14:56:28 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/importMetaData.js	2014-11-11 20:57:25 +0000
@@ -17,6 +17,18 @@
 	$( "#importForm" ).submit();
 }
 
+function metaDataImportFormatChanged()
+{
+	if ( $( "#importFormat" ).val() == "csv" )
+	{
+		$( "#csvImportTr" ).show();
+	}
+	else
+	{
+		$( "#csvImportTr" ).hide();
+	}
+}
+
 function pingNotificationsTimeout()
 {
 	pingNotifications( 'METADATA_IMPORT', 'notificationTable', displaySummaryLink );

=== 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	2014-11-11 20:22:58 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/mainMenu.vm	2014-11-11 20:57:25 +0000
@@ -2,9 +2,8 @@
 <h2>$i18n.getString( "import" )&nbsp;</h2>
 
 <ul>
-  <li><a href="dxf2MetaDataImport.action?importFormat=xml">$i18n.getString( "xml_metadata_import" )&nbsp;</a></li>
-  <li><a href="dxf2MetaDataImport.action?importFormat=csv">$i18n.getString( "csv_metadata_import" )&nbsp;</a></li>
-  <li><a href="displayImportDataValueForm.action?importFormat=xml">$i18n.getString( "data_import" )&nbsp;</a></li>
+  <li><a href="dxf2MetaDataImport.action">$i18n.getString( "metadata_import" )&nbsp;</a></li>
+  <li><a href="displayImportDataValueForm.action">$i18n.getString( "data_import" )&nbsp;</a></li>
   <li><a href="gmlImport.action">$i18n.getString( "gml_import" )&nbsp;</a></li>
   <li><a href="displayEventImportForm.action">$i18n.getString( "event_data_import" )&nbsp;</a></li>
   <li><a href="displayExternalImportMenu.action">$i18n.getString( "dhis14_import" )&nbsp;</a></li>