Search in sources :

Example 1 with AtomicMode

use of org.hisp.dhis.dxf2.metadata.AtomicMode 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)

Example 2 with AtomicMode

use of org.hisp.dhis.dxf2.metadata.AtomicMode in project dhis2-core by dhis2.

the class DefaultMetadataImportService method getParamsFromMap.

@Override
@Transactional(readOnly = true)
public MetadataImportParams getParamsFromMap(Map<String, List<String>> parameters) {
    MetadataImportParams params = new MetadataImportParams();
    if (params.getUser() == null) {
        params.setUser(currentUserService.getCurrentUser());
    }
    params.setSkipSharing(getBooleanWithDefault(parameters, "skipSharing", false));
    params.setSkipTranslation(getBooleanWithDefault(parameters, "skipTranslation", false));
    params.setSkipValidation(getBooleanWithDefault(parameters, "skipValidation", false));
    params.setUserOverrideMode(getEnumWithDefault(UserOverrideMode.class, parameters, "userOverrideMode", UserOverrideMode.NONE));
    params.setImportMode(getEnumWithDefault(ObjectBundleMode.class, parameters, "importMode", ObjectBundleMode.COMMIT));
    params.setPreheatMode(getEnumWithDefault(PreheatMode.class, parameters, "preheatMode", PreheatMode.REFERENCE));
    params.setIdentifier(getEnumWithDefault(PreheatIdentifier.class, parameters, "identifier", PreheatIdentifier.UID));
    params.setImportStrategy(getEnumWithDefault(ImportStrategy.class, parameters, "importStrategy", ImportStrategy.CREATE_AND_UPDATE));
    params.setAtomicMode(getEnumWithDefault(AtomicMode.class, parameters, "atomicMode", AtomicMode.ALL));
    params.setMergeMode(getEnumWithDefault(MergeMode.class, parameters, "mergeMode", MergeMode.REPLACE));
    params.setFlushMode(getEnumWithDefault(FlushMode.class, parameters, "flushMode", FlushMode.AUTO));
    params.setImportReportMode(getEnumWithDefault(ImportReportMode.class, parameters, "importReportMode", ImportReportMode.ERRORS));
    params.setFirstRowIsHeader(getBooleanWithDefault(parameters, "firstRowIsHeader", true));
    if (getBooleanWithDefault(parameters, "async", false)) {
        JobConfiguration jobId = new JobConfiguration("metadataImport", JobType.METADATA_IMPORT, params.getUser().getUid(), true);
        notifier.clear(jobId);
        params.setId(jobId);
    }
    if (params.getUserOverrideMode() == UserOverrideMode.SELECTED) {
        User overrideUser = null;
        if (parameters.containsKey("overrideUser")) {
            List<String> overrideUsers = parameters.get("overrideUser");
            overrideUser = manager.get(User.class, overrideUsers.get(0));
        }
        if (overrideUser == null) {
            throw new MetadataImportException("UserOverrideMode.SELECTED is enabled, but overrideUser parameter does not point to a valid user.");
        } else {
            params.setOverrideUser(overrideUser);
        }
    }
    return params;
}
Also used : User(org.hisp.dhis.user.User) ObjectBundleMode(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleMode) PreheatIdentifier(org.hisp.dhis.preheat.PreheatIdentifier) ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) MergeMode(org.hisp.dhis.common.MergeMode) ImportReportMode(org.hisp.dhis.dxf2.metadata.feedback.ImportReportMode) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) PreheatMode(org.hisp.dhis.preheat.PreheatMode) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with AtomicMode

use of org.hisp.dhis.dxf2.metadata.AtomicMode in project dhis2-core by dhis2.

the class MetaDataImportAction method createMetadataImportParams.

private MetadataImportParams createMetadataImportParams(TaskId taskId, ImportStrategy strategy, AtomicMode atomicMode, boolean dryRun) {
    MetadataImportParams importParams = new MetadataImportParams();
    importParams.setTaskId(taskId);
    importParams.setImportMode(dryRun ? ObjectBundleMode.VALIDATE : ObjectBundleMode.COMMIT);
    importParams.setAtomicMode(atomicMode);
    importParams.setImportStrategy(strategy);
    return importParams;
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams)

Example 4 with AtomicMode

use of org.hisp.dhis.dxf2.metadata.AtomicMode in project dhis2-core by dhis2.

the class MetadataImportParams method toObjectBundleParams.

public ObjectBundleParams toObjectBundleParams() {
    ObjectBundleParams params = new ObjectBundleParams();
    params.setUser(user);
    params.setUserOverrideMode(userOverrideMode);
    params.setOverrideUser(overrideUser);
    params.setSkipSharing(skipSharing);
    params.setSkipTranslation(skipTranslation);
    params.setSkipValidation(skipValidation);
    params.setJobId(id);
    params.setImportStrategy(importStrategy);
    params.setAtomicMode(atomicMode);
    params.setObjects(objects);
    params.setPreheatIdentifier(identifier);
    params.setPreheatMode(preheatMode);
    params.setObjectBundleMode(importMode);
    params.setMergeMode(mergeMode);
    params.setFlushMode(flushMode);
    params.setImportReportMode(importReportMode);
    params.setMetadataSyncImport(metadataSyncImport);
    return params;
}
Also used : ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams)

Aggregations

MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)2 User (org.hisp.dhis.user.User)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 MergeMode (org.hisp.dhis.common.MergeMode)1 ImportReportMode (org.hisp.dhis.dxf2.metadata.feedback.ImportReportMode)1 ObjectBundleMode (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleMode)1 ObjectBundleParams (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams)1 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)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 PreheatIdentifier (org.hisp.dhis.preheat.PreheatIdentifier)1 PreheatMode (org.hisp.dhis.preheat.PreheatMode)1 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)1 TaskId (org.hisp.dhis.scheduling.TaskId)1 Transactional (org.springframework.transaction.annotation.Transactional)1