Search in sources :

Example 6 with WebMessage

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

the class EventController method putJsonEventForEventDate.

@PutMapping(value = "/{uid}/eventDate", consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage putJsonEventForEventDate(HttpServletRequest request, @PathVariable("uid") String uid, ImportOptions importOptions) throws IOException {
    if (!programStageInstanceService.programStageInstanceExists(uid)) {
        return notFound("Event not found for ID " + uid);
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Event updatedEvent = renderService.fromJson(inputStream, Event.class);
    updatedEvent.setEvent(uid);
    eventService.updateEventForEventDate(updatedEvent);
    return ok("Event updated " + uid);
}
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)

Example 7 with WebMessage

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

the class EventController method postJsonEventForNote.

@PostMapping(value = "/{uid}/note", consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage postJsonEventForNote(@PathVariable("uid") String uid, HttpServletRequest request, ImportOptions importOptions) throws IOException {
    if (!programStageInstanceService.programStageInstanceExists(uid)) {
        return notFound("Event not found for ID " + uid);
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Event event = renderService.fromJson(inputStream, Event.class);
    event.setEvent(uid);
    eventService.updateEventForNote(event);
    return ok("Event updated: " + uid);
}
Also used : InputStream(java.io.InputStream) Event(org.hisp.dhis.dxf2.events.event.Event) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with WebMessage

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

the class EventController method putXmlEvent.

// -------------------------------------------------------------------------
// Update
// -------------------------------------------------------------------------
@PutMapping(value = "/{uid}", consumes = { APPLICATION_XML_VALUE, TEXT_XML_VALUE })
@ResponseBody
public WebMessage putXmlEvent(HttpServletRequest request, @PathVariable("uid") String uid, ImportOptions importOptions) throws IOException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Event updatedEvent = renderService.fromXml(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)

Example 9 with WebMessage

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

the class EventController method startAsyncImport.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
 * Starts an asynchronous import task.
 *
 * @param importOptions the ImportOptions.
 * @param events the events to import.
 */
private WebMessage startAsyncImport(ImportOptions importOptions, List<Event> events) {
    JobConfiguration jobId = new JobConfiguration("inMemoryEventImport", EVENT_IMPORT, currentUserService.getCurrentUser().getUid(), true);
    taskExecutor.executeTask(new ImportEventsTask(events, eventService, importOptions, jobId));
    return jobConfigurationReport(jobId).setLocation("/system/tasks/" + EVENT_IMPORT);
}
Also used : ImportEventsTask(org.hisp.dhis.dxf2.events.event.ImportEventsTask) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 10 with WebMessage

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

the class EventController method putJsonEventSingleValue.

@PutMapping(value = "/{uid}/{dataElementUid}", consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage putJsonEventSingleValue(HttpServletRequest request, @PathVariable("uid") String uid, @PathVariable("dataElementUid") String dataElementUid) throws IOException {
    DataElement dataElement = dataElementService.getDataElement(dataElementUid);
    if (dataElement == null) {
        return notFound("DataElement not found for ID " + dataElementUid);
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Event updatedEvent = renderService.fromJson(inputStream, Event.class);
    updatedEvent.setEvent(uid);
    return updateEvent(updatedEvent, true, null);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) 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