use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class SqlViewController method getViewHtml.
@RequestMapping(value = "/{uid}/data.html", method = RequestMethod.GET)
public void getViewHtml(@PathVariable("uid") String uid, @RequestParam(required = false) Set<String> criteria, @RequestParam(required = false) Set<String> var, HttpServletResponse response) throws Exception {
SqlView sqlView = sqlViewService.getSqlViewByUid(uid);
if (sqlView == null) {
throw new WebMessageException(WebMessageUtils.notFound("SQL view does not exist: " + uid));
}
List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
Grid grid = sqlViewService.getSqlViewGrid(sqlView, SqlView.getCriteria(criteria), SqlView.getCriteria(var), filters, fields);
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, sqlView.getCacheStrategy());
GridUtils.toHtml(grid, response.getWriter());
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class SystemSettingController method setSystemSetting.
@RequestMapping(value = "/{key}", method = RequestMethod.POST, consumes = { ContextUtils.CONTENT_TYPE_TEXT, ContextUtils.CONTENT_TYPE_HTML })
@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
public void setSystemSetting(@PathVariable(value = "key") String key, @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);
Serializable valueObject = SettingKey.getAsRealClass(key, value);
systemSettingManager.saveSystemSetting(key, valueObject);
webMessageService.send(WebMessageUtils.ok("System setting " + key + " set to value '" + valueObject + "'."), response, request);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class UserKeyJsonValueController method addUserKeyJsonValue.
/**
* Creates a new KeyJsonValue Object on the current user with the key, namespace and value supplied.
*/
@RequestMapping(value = "/{namespace}/{key}", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
public void addUserKeyJsonValue(@PathVariable String namespace, @PathVariable String key, @RequestBody String body, @RequestParam(defaultValue = "false") boolean encrypt, HttpServletResponse response) throws IOException, WebMessageException {
if (userKeyJsonValueService.getUserKeyJsonValue(currentUserService.getCurrentUser(), namespace, key) != null) {
throw new WebMessageException(WebMessageUtils.conflict("The key '" + key + "' already exists in the namespace '" + namespace + "'."));
}
if (!renderService.isValidJson(body)) {
throw new WebMessageException(WebMessageUtils.badRequest("The data is not valid JSON."));
}
UserKeyJsonValue userKeyJsonValue = new UserKeyJsonValue();
userKeyJsonValue.setKey(key);
userKeyJsonValue.setUser(currentUserService.getCurrentUser());
userKeyJsonValue.setNamespace(namespace);
userKeyJsonValue.setValue(body);
userKeyJsonValue.setEncrypted(encrypt);
userKeyJsonValueService.addUserKeyJsonValue(userKeyJsonValue);
response.setStatus(HttpServletResponse.SC_CREATED);
messageService.sendJson(WebMessageUtils.created("Key '" + key + "' in namespace '" + namespace + "' created."), response);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class UserKeyJsonValueController method deleteUserKeyJsonValue.
/**
* Delete a key.
*/
@RequestMapping(value = "/{namespace}/{key}", method = RequestMethod.DELETE, produces = "application/json")
public void deleteUserKeyJsonValue(@PathVariable String namespace, @PathVariable String key, HttpServletResponse response) throws WebMessageException {
UserKeyJsonValue userKeyJsonValue = userKeyJsonValueService.getUserKeyJsonValue(currentUserService.getCurrentUser(), namespace, key);
if (userKeyJsonValue == null) {
throw new WebMessageException(WebMessageUtils.notFound("The key '" + key + "' was not found in the namespace '" + namespace + "'."));
}
userKeyJsonValueService.deleteUserKeyJsonValue(userKeyJsonValue);
messageService.sendJson(WebMessageUtils.ok("Key '" + key + "' deleted from the namespace '" + namespace + "'."), response);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class PushAnalysisController method renderPushAnalytics.
@RequestMapping(value = "/{uid}/render", method = RequestMethod.GET)
public void renderPushAnalytics(@PathVariable() String uid, HttpServletResponse response) throws WebMessageException, IOException {
PushAnalysis pushAnalysis = pushAnalysisService.getByUid(uid);
if (pushAnalysis == null) {
throw new WebMessageException(WebMessageUtils.notFound("Push analysis with uid " + uid + " was not found"));
}
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.NO_CACHE);
log.info("User '" + currentUserService.getCurrentUser().getUsername() + "' started PushAnalysis for 'rendering'");
String result = pushAnalysisService.generateHtmlReport(pushAnalysis, currentUserService.getCurrentUser(), null);
response.getWriter().write(result);
response.getWriter().close();
}
Aggregations