=== 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 @@