Search in sources :

Example 1 with MetadataImportParams

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

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

the class MetadataSyncTask method runSyncTask.

public synchronized void runSyncTask(MetadataRetryContext context) throws MetadataSyncServiceException, DhisVersionMismatchException {
    metadataSyncPreProcessor.setUp(context);
    metadataSyncPreProcessor.handleAggregateDataPush(context);
    metadataSyncPreProcessor.handleEventDataPush(context);
    MetadataVersion metadataVersion = metadataSyncPreProcessor.handleCurrentMetadataVersion(context);
    List<MetadataVersion> metadataVersionList = metadataSyncPreProcessor.handleMetadataVersionsList(context, metadataVersion);
    if (metadataVersionList != null) {
        for (MetadataVersion dataVersion : metadataVersionList) {
            MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
            boolean isSyncRequired = metadataSyncService.isSyncRequired(syncParams);
            MetadataSyncSummary metadataSyncSummary = null;
            if (isSyncRequired) {
                metadataSyncSummary = handleMetadataSync(context, dataVersion);
            } else {
                metadataSyncPostProcessor.handleVersionAlreadyExists(context, dataVersion);
                break;
            }
            boolean abortStatus = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, context, dataVersion);
            if (abortStatus) {
                break;
            }
            systemSettingManager.saveSystemSetting(SettingKey.LAST_SUCCESSFUL_METADATA_SYNC, dataVersion.getImportDate());
            clearFailedVersionSettings();
        }
    }
    log.info("Metadata sync cron job ended ");
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)

Example 3 with MetadataImportParams

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

the class AbstractCrudController method deleteObject.

//--------------------------------------------------------------------------
// DELETE
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.OK)
public void deleteObject(@PathVariable("uid") String pvUid, HttpServletRequest request, HttpServletResponse response) throws Exception {
    List<T> objects = getEntity(pvUid);
    if (objects.isEmpty()) {
        throw new WebMessageException(WebMessageUtils.notFound(getEntityClass(), pvUid));
    }
    User user = currentUserService.getCurrentUser();
    if (!aclService.canDelete(user, objects.get(0))) {
        throw new DeleteAccessDeniedException("You don't have the proper permissions to delete this object.");
    }
    preDeleteEntity(objects.get(0));
    MetadataImportParams params = new MetadataImportParams().setImportReportMode(ImportReportMode.FULL).setUser(user).setImportStrategy(ImportStrategy.DELETE).addObject(objects.get(0));
    ImportReport importReport = importService.importMetadata(params);
    postDeleteEntity();
    webMessageService.send(WebMessageUtils.objectReport(importReport), response, request);
}
Also used : User(org.hisp.dhis.user.User) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) DeleteAccessDeniedException(org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with MetadataImportParams

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

the class AbstractCrudController method putJsonObject.

//--------------------------------------------------------------------------
// PUT
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void putJsonObject(@PathVariable("uid") String pvUid, HttpServletRequest request, HttpServletResponse response) throws Exception {
    List<T> objects = getEntity(pvUid);
    if (objects.isEmpty()) {
        throw new WebMessageException(WebMessageUtils.notFound(getEntityClass(), pvUid));
    }
    User user = currentUserService.getCurrentUser();
    if (!aclService.canUpdate(user, objects.get(0))) {
        throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
    }
    T parsed = deserializeJsonEntity(request, response);
    ((BaseIdentifiableObject) parsed).setUid(pvUid);
    preUpdateEntity(objects.get(0), parsed);
    MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap()).setImportReportMode(ImportReportMode.FULL).setUser(user).setImportStrategy(ImportStrategy.UPDATE).addObject(parsed);
    ImportReport importReport = importService.importMetadata(params);
    WebMessage webMessage = WebMessageUtils.objectReport(importReport);
    if (importReport.getStatus() == Status.OK) {
        T entity = manager.get(getEntityClass(), pvUid);
        postUpdateEntity(entity);
    } else {
        webMessage.setStatus(Status.ERROR);
    }
    webMessageService.send(webMessage, response, request);
}
Also used : User(org.hisp.dhis.user.User) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with MetadataImportParams

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

the class MetadataImportController method postXmlMetadata.

@RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML_VALUE)
public void postXmlMetadata(HttpServletRequest request, HttpServletResponse response) throws IOException {
    MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
    Metadata metadata = renderService.fromXml(StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream()), Metadata.class);
    params.addMetadata(schemaService.getMetadataSchemas(), metadata);
    if (params.hasTaskId()) {
        startAsync(params);
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    } else {
        ImportReport importReport = metadataImportService.importMetadata(params);
        renderService.toXml(response.getOutputStream(), importReport);
    }
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Metadata(org.hisp.dhis.dxf2.metadata.Metadata) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)58 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)49 List (java.util.List)38 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)38 Test (org.junit.jupiter.api.Test)38 ClassPathResource (org.springframework.core.io.ClassPathResource)31 User (org.hisp.dhis.user.User)30 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)29 DataSet (org.hisp.dhis.dataset.DataSet)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)10 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)9 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)8 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)8 HashMap (java.util.HashMap)6 UserGroup (org.hisp.dhis.user.UserGroup)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5