Search in sources :

Example 1 with ImportMetaDataTask

use of org.hisp.dhis.importexport.action.util.ImportMetaDataTask in project dhis2-core by dhis2.

the class MetaDataImportAction method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    strategy = strategy != null ? strategy : ImportStrategy.NEW_AND_UPDATES;
    User user = currentUserService.getCurrentUser();
    TaskId taskId = new TaskId(TaskCategory.METADATA_IMPORT, user);
    notifier.clear(taskId);
    InputStream in = StreamUtils.wrapAndCheckCompressionFormat(new FileInputStream(upload));
    MetadataImportParams importParams = createMetadataImportParams(taskId, strategy, atomicMode, dryRun).setFilename(uploadFileName);
    if ("csv".equals(importFormat)) {
        if (classKey != null && CSV_SUPPORTED_CLASSES.containsKey(classKey)) {
            scheduler.executeTask(new ImportMetaDataCsvTask(importService, csvImportService, schemaService, importParams, in, CSV_SUPPORTED_CLASSES.get(classKey)));
        }
    } else if ("gml".equals(importFormat)) {
        scheduler.executeTask(new ImportMetaDataGmlTask(gmlImportService, importParams, in));
    } else if ("json".equals(importFormat) || "xml".equals(importFormat)) {
        scheduler.executeTask(new ImportMetaDataTask(importService, schemaService, importParams, in, importFormat));
    }
    return SUCCESS;
}
Also used : User(org.hisp.dhis.user.User) TaskId(org.hisp.dhis.scheduling.TaskId) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ImportMetaDataTask(org.hisp.dhis.importexport.action.util.ImportMetaDataTask) ImportMetaDataCsvTask(org.hisp.dhis.importexport.action.util.ImportMetaDataCsvTask) FileInputStream(java.io.FileInputStream) ImportMetaDataGmlTask(org.hisp.dhis.importexport.action.util.ImportMetaDataGmlTask)

Aggregations

FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)1 ImportMetaDataCsvTask (org.hisp.dhis.importexport.action.util.ImportMetaDataCsvTask)1 ImportMetaDataGmlTask (org.hisp.dhis.importexport.action.util.ImportMetaDataGmlTask)1 ImportMetaDataTask (org.hisp.dhis.importexport.action.util.ImportMetaDataTask)1 TaskId (org.hisp.dhis.scheduling.TaskId)1 User (org.hisp.dhis.user.User)1