Search in sources :

Example 1 with APPLICATION_XML_VALUE

use of org.springframework.http.MediaType.APPLICATION_XML_VALUE in project dhis2-core by dhis2.

the class EnrollmentController method postEnrollmentXml.

@PostMapping(value = "", consumes = APPLICATION_XML_VALUE, produces = APPLICATION_XML_VALUE)
@ResponseBody
public WebMessage postEnrollmentXml(@RequestParam(defaultValue = "CREATE_AND_UPDATE") ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request) throws IOException {
    importOptions.setStrategy(strategy);
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    if (!importOptions.isAsync()) {
        ImportSummaries importSummaries = enrollmentService.addEnrollmentsXml(inputStream, importOptions);
        importSummaries.setImportOptions(importOptions);
        importSummaries.getImportSummaries().stream().filter(importSummary -> !importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR) && !importOptions.getImportStrategy().isDelete() && (!importOptions.getImportStrategy().isSync() || importSummary.getImportCount().getDeleted() == 0)).forEach(importSummary -> importSummary.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + importSummary.getReference()));
        if (importSummaries.getImportSummaries().size() == 1) {
            ImportSummary importSummary = importSummaries.getImportSummaries().get(0);
            importSummary.setImportOptions(importOptions);
            if (!importSummary.getStatus().equals(ImportStatus.ERROR)) {
                importSummaries(importSummaries).setHttpStatus(HttpStatus.CREATED).setLocation("/api/" + "enrollments" + "/" + importSummary.getReference());
            }
        }
        return importSummaries(importSummaries).setHttpStatus(HttpStatus.CREATED);
    }
    return startAsyncImport(importOptions, enrollmentService.getEnrollmentsXml(inputStream));
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) PathVariable(org.springframework.web.bind.annotation.PathVariable) APPLICATION_XML_VALUE(org.springframework.http.MediaType.APPLICATION_XML_VALUE) RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) NodeUtils(org.hisp.dhis.node.NodeUtils) Model(org.springframework.ui.Model) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PutMapping(org.springframework.web.bind.annotation.PutMapping) Map(java.util.Map) PagerUtils(org.hisp.dhis.common.PagerUtils) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) PostMapping(org.springframework.web.bind.annotation.PostMapping) ImportEnrollmentsTask(org.hisp.dhis.dxf2.events.enrollment.ImportEnrollmentsTask) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) ContextService(org.hisp.dhis.webapi.service.ContextService) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) Set(java.util.Set) Collectors(java.util.stream.Collectors) Enrollments(org.hisp.dhis.dxf2.events.enrollment.Enrollments) EnrollmentCriteria(org.hisp.dhis.webapi.controller.event.webrequest.EnrollmentCriteria) List(java.util.List) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) AsyncTaskExecutor(org.hisp.dhis.common.AsyncTaskExecutor) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) RootNode(org.hisp.dhis.node.types.RootNode) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) WebMessageUtils.notFound(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ENROLLMENT_IMPORT(org.hisp.dhis.scheduling.JobType.ENROLLMENT_IMPORT) Controller(org.springframework.stereotype.Controller) StreamUtils(org.hisp.dhis.commons.util.StreamUtils) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) SlimPager(org.hisp.dhis.common.SlimPager) WebMessageUtils.importSummaries(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummaries) EnrollmentCriteriaMapper(org.hisp.dhis.webapi.controller.event.mapper.EnrollmentCriteriaMapper) WebMessageUtils.importSummary(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummary) GetMapping(org.springframework.web.bind.annotation.GetMapping) WebMessageUtils.jobConfigurationReport(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.jobConfigurationReport) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) IOException(java.io.IOException) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) HttpStatus(org.springframework.http.HttpStatus) CurrentUserService(org.hisp.dhis.user.CurrentUserService) InputStream(java.io.InputStream) TextUtils(org.hisp.dhis.commons.util.TextUtils) InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 AsyncTaskExecutor (org.hisp.dhis.common.AsyncTaskExecutor)1 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)1 PagerUtils (org.hisp.dhis.common.PagerUtils)1 SlimPager (org.hisp.dhis.common.SlimPager)1 StreamUtils (org.hisp.dhis.commons.util.StreamUtils)1 TextUtils (org.hisp.dhis.commons.util.TextUtils)1 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)1 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)1 EnrollmentService (org.hisp.dhis.dxf2.events.enrollment.EnrollmentService)1 Enrollments (org.hisp.dhis.dxf2.events.enrollment.Enrollments)1 ImportEnrollmentsTask (org.hisp.dhis.dxf2.events.enrollment.ImportEnrollmentsTask)1 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)1