Search in sources :

Example 11 with WebMessageUtils.ok

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

the class EventController method postJsonEventForNote.

@RequestMapping(value = "/{uid}/note", method = RequestMethod.POST, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void postJsonEventForNote(@PathVariable("uid") String uid, HttpServletResponse response, HttpServletRequest request, 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 event = renderService.fromJson(inputStream, Event.class);
    event.setEvent(uid);
    eventService.updateEventForNote(event);
    webMessageService.send(WebMessageUtils.ok("Event updated: " + uid), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InputStream(java.io.InputStream) Event(org.hisp.dhis.dxf2.events.event.Event) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with WebMessageUtils.ok

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

the class UserSettingController method setUserSetting.

// -------------------------------------------------------------------------
// Resources
// -------------------------------------------------------------------------
@RequestMapping(value = "/{key}", method = RequestMethod.POST)
public void setUserSetting(@PathVariable(value = "key") String key, @RequestParam(value = "user", required = false) String username, @RequestParam(value = "value", required = false) String value, @RequestBody(required = false) String valuePayload, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    if (key == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Key must be specified"));
    }
    if (value == null && valuePayload == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Value must be specified as query param or as payload"));
    }
    value = ObjectUtils.firstNonNull(value, valuePayload);
    Optional<UserSettingKey> keyEnum = UserSettingKey.getByName(key);
    if (!keyEnum.isPresent()) {
        throw new WebMessageException(WebMessageUtils.conflict("Key is not supported: " + key));
    }
    Serializable valueObject = UserSettingKey.getAsRealClass(key, value);
    if (username == null) {
        userSettingService.saveUserSetting(keyEnum.get(), valueObject);
    } else {
        userSettingService.saveUserSetting(keyEnum.get(), valueObject, username);
    }
    webMessageService.send(WebMessageUtils.ok("User setting saved"), response, request);
}
Also used : Serializable(java.io.Serializable) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UserSettingKey(org.hisp.dhis.user.UserSettingKey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with WebMessageUtils.ok

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

the class SqlViewController method refreshMaterializedView.

@RequestMapping(value = "/{uid}/refresh", method = RequestMethod.POST)
public void refreshMaterializedView(@PathVariable("uid") String uid, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    SqlView sqlView = sqlViewService.getSqlViewByUid(uid);
    if (sqlView == null) {
        throw new WebMessageException(WebMessageUtils.notFound("SQL view not found"));
    }
    boolean result = sqlViewService.refreshMaterializedView(sqlView);
    if (!result) {
        throw new WebMessageException(WebMessageUtils.conflict("View could not be refreshed"));
    } else {
        webMessageService.send(WebMessageUtils.ok("Materialized view refreshed"), response, request);
    }
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with WebMessageUtils.ok

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

the class KeyJsonValueController method deleteKeyJsonValue.

/**
     * Delete a key from the given namespace.
     */
@RequestMapping(value = "/{namespace}/{key}", method = RequestMethod.DELETE, produces = "application/json")
public void deleteKeyJsonValue(@PathVariable String namespace, @PathVariable String key, HttpServletResponse response) throws WebMessageException {
    if (!hasAccess(namespace)) {
        throw new WebMessageException(WebMessageUtils.forbidden("The namespace '" + namespace + "' is protected, and you don't have the right authority to access it."));
    }
    KeyJsonValue keyJsonValue = keyJsonValueService.getKeyJsonValue(namespace, key);
    if (keyJsonValue == null) {
        throw new WebMessageException(WebMessageUtils.notFound("The key '" + key + "' was not found in the namespace '" + namespace + "'."));
    }
    keyJsonValueService.deleteKeyJsonValue(keyJsonValue);
    messageService.sendJson(WebMessageUtils.ok("Key '" + key + "' deleted from namespace '" + namespace + "'."), response);
}
Also used : KeyJsonValue(org.hisp.dhis.keyjsonvalue.KeyJsonValue) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with WebMessageUtils.ok

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

RequestMapping (org.springframework.web.bind.annotation.RequestMapping)19 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)17 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 Dashboard (org.hisp.dhis.dashboard.Dashboard)3 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)3 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)3 InputStream (java.io.InputStream)2 Serializable (java.io.Serializable)2 DashboardItem (org.hisp.dhis.dashboard.DashboardItem)2 Event (org.hisp.dhis.dxf2.events.event.Event)2 KeyJsonValue (org.hisp.dhis.keyjsonvalue.KeyJsonValue)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 BulkSmsGatewayConfig (org.hisp.dhis.sms.config.BulkSmsGatewayConfig)2 SmsGatewayConfig (org.hisp.dhis.sms.config.SmsGatewayConfig)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 Semver (com.vdurmont.semver4j.Semver)1 Map (java.util.Map)1 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 MinMaxDataElement (org.hisp.dhis.minmax.MinMaxDataElement)1