Search in sources :

Example 6 with WebMessageUtils.importSummary

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

the class EventController method putXmlEvent.

// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = { "application/xml", "text/xml" })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void putXmlEvent(HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, ImportOptions importOptions) throws IOException, WebMessageException {
    if (!programStageInstanceService.programStageInstanceExists(uid)) {
        throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Event updatedEvent = renderService.fromXml(inputStream, Event.class);
    updatedEvent.setEvent(uid);
    ImportSummary importSummary = eventService.updateEvent(updatedEvent, false, importOptions);
    importSummary.setImportOptions(importOptions);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with WebMessageUtils.importSummary

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

the class EventController method putJsonEvent.

@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void putJsonEvent(HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, ImportOptions importOptions) throws IOException, WebMessageException {
    if (!programStageInstanceService.programStageInstanceExists(uid)) {
        throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Event updatedEvent = renderService.fromJson(inputStream, Event.class);
    updatedEvent.setEvent(uid);
    ImportSummary importSummary = eventService.updateEvent(updatedEvent, false, importOptions);
    importSummary.setImportOptions(importOptions);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with WebMessageUtils.importSummary

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

the class EventController method putJsonEventSingleValue.

@RequestMapping(value = "/{uid}/{dataElementUid}", method = RequestMethod.PUT, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void putJsonEventSingleValue(HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, @PathVariable("dataElementUid") String dataElementUid) throws IOException, WebMessageException {
    if (!programStageInstanceService.programStageInstanceExists(uid)) {
        throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
    }
    DataElement dataElement = dataElementService.getDataElement(dataElementUid);
    if (dataElement == null) {
        throw new WebMessageException(WebMessageUtils.notFound("DataElement not found for ID " + dataElementUid));
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Event updatedEvent = renderService.fromJson(inputStream, Event.class);
    updatedEvent.setEvent(uid);
    ImportSummary importSummary = eventService.updateEvent(updatedEvent, true);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with WebMessageUtils.importSummary

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

the class EventController method deleteEvent.

// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_DELETE')")
public void deleteEvent(HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid) throws WebMessageException {
    if (!programStageInstanceService.programStageInstanceExists(uid)) {
        throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
    }
    response.setStatus(HttpServletResponse.SC_OK);
    try {
        ImportSummary importSummary = eventService.deleteEvent(uid);
        webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
    } catch (Exception ex) {
        webMessageService.send(WebMessageUtils.conflict("Unable to delete event " + uid, ex.getMessage()), response, request);
    }
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) IOException(java.io.IOException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with WebMessageUtils.importSummary

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

the class TrackedEntityInstanceController method updateTrackedEntityInstanceJson.

@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_INSTANCE_ADD')")
public void updateTrackedEntityInstanceJson(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstanceJson(id, inputStream, importOptions);
    importSummary.setImportOptions(importOptions);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 InputStream (java.io.InputStream)8 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)5 Event (org.hisp.dhis.dxf2.events.event.Event)3 IOException (java.io.IOException)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1