Search in sources :

Example 6 with WebMessageUtils.error

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

the class SmsController method sendSMSMessage.

@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(value = "/outbound", method = RequestMethod.POST, consumes = "application/json")
public void sendSMSMessage(HttpServletResponse response, HttpServletRequest request) throws WebMessageException, IOException {
    OutboundSms sms = renderService.fromJson(request.getInputStream(), OutboundSms.class);
    OutboundMessageResponse status = smsSender.sendMessage(null, sms.getMessage(), sms.getRecipients());
    if (status.isOk()) {
        webMessageService.send(WebMessageUtils.ok("SMS sent"), response, request);
    } else {
        throw new WebMessageException(WebMessageUtils.error(status.getDescription()));
    }
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) OutboundSms(org.hisp.dhis.sms.outbound.OutboundSms) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)4 ByteSource (com.google.common.io.ByteSource)3 IOException (java.io.IOException)3 FileResourceWebMessageResponse (org.hisp.dhis.dxf2.webmessage.responses.FileResourceWebMessageResponse)3 FileResource (org.hisp.dhis.fileresource.FileResource)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 File (java.io.File)2 InputStream (java.io.InputStream)2 URI (java.net.URI)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 Date (java.util.Date)1 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)1 DataValue (org.hisp.dhis.datavalue.DataValue)1 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)1 Event (org.hisp.dhis.dxf2.events.event.Event)1 LocationManagerException (org.hisp.dhis.external.location.LocationManagerException)1