Search in sources :

Example 41 with WebMessageException

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());
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Grid(org.hisp.dhis.common.Grid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with WebMessageException

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);
}
Also used : Serializable(java.io.Serializable) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 43 with WebMessageException

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);
}
Also used : UserKeyJsonValue(org.hisp.dhis.userkeyjsonvalue.UserKeyJsonValue) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 44 with WebMessageException

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);
}
Also used : UserKeyJsonValue(org.hisp.dhis.userkeyjsonvalue.UserKeyJsonValue) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with WebMessageException

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();
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PushAnalysis(org.hisp.dhis.pushanalysis.PushAnalysis) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)134 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)118 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)31 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)28 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)27 DataSet (org.hisp.dhis.dataset.DataSet)21 Period (org.hisp.dhis.period.Period)21 User (org.hisp.dhis.user.User)20 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)18 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)15 ArrayList (java.util.ArrayList)14 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)14 Interpretation (org.hisp.dhis.interpretation.Interpretation)13 Date (java.util.Date)9 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)9 InputStream (java.io.InputStream)8 Grid (org.hisp.dhis.common.Grid)8 Event (org.hisp.dhis.dxf2.events.event.Event)8 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)8 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)8