Search in sources :

Example 66 with WebMessage

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

the class EnrollmentController method startAsyncImport.

// -------------------------------------------------------------------------
// HELPERS
// -------------------------------------------------------------------------
/**
 * Starts an asynchronous enrollment task.
 *
 * @param importOptions the ImportOptions.
 * @param enrollments the enrollments to import.
 */
private WebMessage startAsyncImport(ImportOptions importOptions, List<Enrollment> enrollments) {
    JobConfiguration jobId = new JobConfiguration("inMemoryEventImport", ENROLLMENT_IMPORT, currentUserService.getCurrentUser().getUid(), true);
    taskExecutor.executeTask(new ImportEnrollmentsTask(enrollments, enrollmentService, importOptions, jobId));
    return jobConfigurationReport(jobId).setLocation("/system/tasks/" + ENROLLMENT_IMPORT);
}
Also used : ImportEnrollmentsTask(org.hisp.dhis.dxf2.events.enrollment.ImportEnrollmentsTask) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 67 with WebMessage

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

Example 68 with WebMessage

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

the class DataValueController method saveFileDataValue.

@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
@PostMapping(FILE_PATH)
@ResponseBody
public WebMessage saveFileDataValue(@RequestParam String de, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String ds, @RequestParam(required = false) String comment, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) boolean force, @RequestParam MultipartFile file, @CurrentUser User currentUser) throws WebMessageException, IOException {
    FileResource fileResource = fileResourceUtils.saveFileResource(file, FileResourceDomain.DATA_VALUE);
    saveDataValueInternal(de, co, cc, cp, pe, ou, ds, fileResource.getUid(), comment, followUp, force, currentUser);
    WebMessage webMessage = new WebMessage(Status.OK, HttpStatus.ACCEPTED);
    webMessage.setResponse(new FileResourceWebMessageResponse(fileResource));
    return webMessage;
}
Also used : FileResourceWebMessageResponse(org.hisp.dhis.dxf2.webmessage.responses.FileResourceWebMessageResponse) FileResource(org.hisp.dhis.fileresource.FileResource) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 69 with WebMessage

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

the class EventController method postEvent.

@SneakyThrows
private WebMessage postEvent(ImportStrategy strategy, HttpServletRequest request, ImportOptions importOptions, BiFunction<InputStream, ImportOptions, ImportSummaries> eventAdder, Function<InputStream, List<Event>> eventConverter) {
    importOptions.setImportStrategy(strategy);
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    importOptions.setIdSchemes(getIdSchemesFromParameters(importOptions.getIdSchemes(), contextService.getParameterValuesMap()));
    if (!importOptions.isAsync()) {
        ImportSummaries importSummaries = eventAdder.apply(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 (!importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR)) {
                return importSummaries(importSummaries).setLocation(RESOURCE_PATH + "/" + importSummary.getReference());
            }
        }
        return importSummaries(importSummaries);
    }
    return startAsyncImport(importOptions, eventConverter.apply(inputStream));
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) APPLICATION_XML_VALUE(org.springframework.http.MediaType.APPLICATION_XML_VALUE) EventRowService(org.hisp.dhis.dxf2.events.report.EventRowService) RequestParam(org.springframework.web.bind.annotation.RequestParam) EventService(org.hisp.dhis.dxf2.events.event.EventService) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) StringUtils(org.apache.commons.lang3.StringUtils) FileResourceStorageStatus(org.hisp.dhis.fileresource.FileResourceStorageStatus) NodeUtils(org.hisp.dhis.node.NodeUtils) Model(org.springframework.ui.Model) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) FileResourceService(org.hisp.dhis.fileresource.FileResourceService) Map(java.util.Map) PagerUtils(org.hisp.dhis.common.PagerUtils) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) PostMapping(org.springframework.web.bind.annotation.PostMapping) ImportEventsTask(org.hisp.dhis.dxf2.events.event.ImportEventsTask) ContextService(org.hisp.dhis.webapi.service.ContextService) OrganisationUnitSelectionMode(org.hisp.dhis.common.OrganisationUnitSelectionMode) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) Set(java.util.Set) CacheStrategy(org.hisp.dhis.common.cache.CacheStrategy) SchemaService(org.hisp.dhis.schema.SchemaService) Event(org.hisp.dhis.dxf2.events.event.Event) FileResourceUtils(org.hisp.dhis.webapi.utils.FileResourceUtils) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) EventCriteria(org.hisp.dhis.webapi.controller.event.webrequest.EventCriteria) ParseException(org.locationtech.jts.io.ParseException) GZIPOutputStream(java.util.zip.GZIPOutputStream) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) Joiner(com.google.common.base.Joiner) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) DataElementService(org.hisp.dhis.dataelement.DataElementService) StreamUtils(org.hisp.dhis.commons.util.StreamUtils) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) SlimPager(org.hisp.dhis.common.SlimPager) WebMessageUtils.importSummary(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummary) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) OrderParam(org.hisp.dhis.webapi.controller.event.mapper.OrderParam) IdSchemes(org.hisp.dhis.common.IdSchemes) MoreObjects(com.google.common.base.MoreObjects) IOException(java.io.IOException) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) QueryUtils(org.hisp.dhis.query.QueryUtils) FileResourceDomain(org.hisp.dhis.fileresource.FileResourceDomain) TextUtils(org.hisp.dhis.commons.util.TextUtils) PathVariable(org.springframework.web.bind.annotation.PathVariable) DataValue(org.hisp.dhis.dxf2.events.event.DataValue) SneakyThrows(lombok.SneakyThrows) Date(java.util.Date) BiFunction(java.util.function.BiFunction) RenderService(org.hisp.dhis.render.RenderService) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ProgramStageInstanceService(org.hisp.dhis.program.ProgramStageInstanceService) WebMessageUtils.ok(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.ok) OrderCriteria(org.hisp.dhis.webapi.controller.event.webrequest.OrderCriteria) PutMapping(org.springframework.web.bind.annotation.PutMapping) Preset(org.hisp.dhis.node.Preset) GridUtils(org.hisp.dhis.system.grid.GridUtils) InputUtils(org.hisp.dhis.dxf2.util.InputUtils) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) CsvEventService(org.hisp.dhis.dxf2.events.event.csv.CsvEventService) HttpHeaders(org.springframework.http.HttpHeaders) EventStatus(org.hisp.dhis.event.EventStatus) Collectors(java.util.stream.Collectors) EventRows(org.hisp.dhis.dxf2.events.report.EventRows) ImageFileDimension(org.hisp.dhis.fileresource.ImageFileDimension) List(java.util.List) Events(org.hisp.dhis.dxf2.events.event.Events) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) WebMessageUtils.conflict(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict) AssignedUserSelectionMode(org.hisp.dhis.common.AssignedUserSelectionMode) AsyncTaskExecutor(org.hisp.dhis.common.AsyncTaskExecutor) Schema(org.hisp.dhis.schema.Schema) RootNode(org.hisp.dhis.node.types.RootNode) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMessageUtils.notFound(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) Controller(org.springframework.stereotype.Controller) Function(java.util.function.Function) Program(org.hisp.dhis.program.Program) DataElement(org.hisp.dhis.dataelement.DataElement) WebMessageUtils.importSummaries(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummaries) WebMessageUtils.error(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.error) GetMapping(org.springframework.web.bind.annotation.GetMapping) WebMessageUtils.jobConfigurationReport(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.jobConfigurationReport) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) OutputStream(java.io.OutputStream) FileResource(org.hisp.dhis.fileresource.FileResource) HttpServletResponse(javax.servlet.http.HttpServletResponse) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) TEXT_XML_VALUE(org.springframework.http.MediaType.TEXT_XML_VALUE) Grid(org.hisp.dhis.common.Grid) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) EVENT_IMPORT(org.hisp.dhis.scheduling.JobType.EVENT_IMPORT) ProgramStatus(org.hisp.dhis.program.ProgramStatus) FileResourceWebMessageResponse(org.hisp.dhis.dxf2.webmessage.responses.FileResourceWebMessageResponse) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Collections(java.util.Collections) InputStream(java.io.InputStream) RequestToSearchParamsMapper(org.hisp.dhis.webapi.controller.event.mapper.RequestToSearchParamsMapper) InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) SneakyThrows(lombok.SneakyThrows)

Example 70 with WebMessage

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

the class EventController method putJsonEvent.

@PutMapping(value = "/{uid}", consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage putJsonEvent(HttpServletRequest request, @PathVariable("uid") String uid, ImportOptions importOptions) throws IOException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Event updatedEvent = renderService.fromJson(inputStream, Event.class);
    updatedEvent.setEvent(uid);
    return updateEvent(updatedEvent, false, importOptions);
}
Also used : InputStream(java.io.InputStream) Event(org.hisp.dhis.dxf2.events.event.Event) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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