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);
}
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);
}
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);
}
}
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);
}
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()));
}
}
Aggregations