Search in sources :

Example 56 with WebMessage

use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method postCompleteRegistrationsXml.

// -------------------------------------------------------------------------
// POST
// -------------------------------------------------------------------------
@PostMapping(consumes = CONTENT_TYPE_XML, produces = CONTENT_TYPE_XML)
@ResponseBody
public WebMessage postCompleteRegistrationsXml(ImportOptions importOptions, HttpServletRequest request) throws IOException {
    if (importOptions.isAsync()) {
        return asyncImport(importOptions, ImportCompleteDataSetRegistrationsTask.FORMAT_XML, request);
    }
    ImportSummary summary = registrationExchangeService.saveCompleteDataSetRegistrationsXml(request.getInputStream(), importOptions);
    summary.setImportOptions(importOptions);
    return importSummary(summary).withPlainResponseBefore(DhisApiVersion.V38);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 57 with WebMessage

use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.

the class DataValueSetController method postDxf2DataValueSet.

// -------------------------------------------------------------------------
// Post
// -------------------------------------------------------------------------
@PostMapping(consumes = APPLICATION_XML_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
@ResponseBody
public WebMessage postDxf2DataValueSet(ImportOptions importOptions, HttpServletRequest request) throws IOException {
    if (importOptions.isAsync()) {
        return startAsyncImport(importOptions, ImportDataValueTask.FORMAT_XML, request);
    }
    ImportSummary summary = dataValueSetService.importDataValueSetXml(request.getInputStream(), importOptions);
    summary.setImportOptions(importOptions);
    return importSummary(summary).withPlainResponseBefore(V38);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 58 with WebMessage

use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.

the class DataValueSetController method postJsonDataValueSet.

@PostMapping(consumes = APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
@ResponseBody
public WebMessage postJsonDataValueSet(ImportOptions importOptions, HttpServletRequest request) throws IOException {
    if (importOptions.isAsync()) {
        return startAsyncImport(importOptions, ImportDataValueTask.FORMAT_JSON, request);
    }
    ImportSummary summary = dataValueSetService.importDataValueSetJson(request.getInputStream(), importOptions);
    summary.setImportOptions(importOptions);
    return importSummary(summary).withPlainResponseBefore(V38);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 59 with WebMessage

use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.

the class DataValueSetController method postPdfDataValueSet.

@PostMapping(consumes = CONTENT_TYPE_PDF)
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
@ResponseBody
public WebMessage postPdfDataValueSet(ImportOptions importOptions, HttpServletRequest request) throws IOException {
    if (importOptions.isAsync()) {
        return startAsyncImport(importOptions, ImportDataValueTask.FORMAT_PDF, request);
    }
    ImportSummary summary = dataValueSetService.importDataValueSetPdf(request.getInputStream(), importOptions);
    summary.setImportOptions(importOptions);
    return importSummary(summary).withPlainResponseBefore(V38);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 60 with WebMessage

use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.

the class DataValueSetController method startAsyncImport.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
 * Starts an asynchronous import task.
 *
 * @param importOptions the ImportOptions.
 * @param format the resource representation format.
 * @param request the HttpRequest.
 */
private WebMessage startAsyncImport(ImportOptions importOptions, String format, HttpServletRequest request) throws IOException {
    InputStream inputStream = saveTmp(request.getInputStream());
    JobConfiguration jobId = new JobConfiguration("dataValueImport", DATAVALUE_IMPORT, currentUserService.getCurrentUser().getUid(), true);
    taskExecutor.executeTask(new ImportDataValueTask(dataValueSetService, adxDataService, sessionFactory, inputStream, importOptions, jobId, format));
    return jobConfigurationReport(jobId).setLocation("/system/tasks/" + DATAVALUE_IMPORT);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) ImportDataValueTask(org.hisp.dhis.dxf2.datavalueset.tasks.ImportDataValueTask)

Aggregations

ResponseBody (org.springframework.web.bind.annotation.ResponseBody)49 PostMapping (org.springframework.web.bind.annotation.PostMapping)29 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)28 InputStream (java.io.InputStream)24 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)20 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)17 PutMapping (org.springframework.web.bind.annotation.PutMapping)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)10 User (org.hisp.dhis.user.User)10 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)10 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)9 List (java.util.List)8 Event (org.hisp.dhis.dxf2.events.event.Event)8 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)7 IOException (java.io.IOException)6 FileResourceWebMessageResponse (org.hisp.dhis.dxf2.webmessage.responses.FileResourceWebMessageResponse)6