Search in sources :

Example 11 with WebMessageUtils.created

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

the class DashboardController method postJsonItemContent.

@RequestMapping(value = "/{dashboardUid}/items/content", method = RequestMethod.POST)
public void postJsonItemContent(HttpServletResponse response, HttpServletRequest request, @PathVariable String dashboardUid, @RequestParam DashboardItemType type, @RequestParam("id") String contentUid) throws Exception {
    Dashboard dashboard = dashboardService.getDashboard(dashboardUid);
    if (dashboard == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Dashboard does not exist: " + dashboardUid));
    }
    if (!aclService.canUpdate(currentUserService.getCurrentUser(), dashboard)) {
        throw new UpdateAccessDeniedException("You don't have the proper permissions to update this dashboard.");
    }
    DashboardItem item = dashboardService.addItemContent(dashboardUid, type, contentUid);
    if (item == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Max number of dashboard items reached: " + MAX_ITEMS));
    } else {
        response.addHeader("Location", DashboardItemSchemaDescriptor.API_ENDPOINT + "/" + item.getUid());
        webMessageService.send(WebMessageUtils.created("Dashboard item created"), response, request);
    }
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) Dashboard(org.hisp.dhis.dashboard.Dashboard) DashboardItem(org.hisp.dhis.dashboard.DashboardItem) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 Interpretation (org.hisp.dhis.interpretation.Interpretation)3 ArrayList (java.util.ArrayList)2 Dashboard (org.hisp.dhis.dashboard.Dashboard)2 DashboardItem (org.hisp.dhis.dashboard.DashboardItem)2 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 User (org.hisp.dhis.user.User)2 UserKeyJsonValue (org.hisp.dhis.userkeyjsonvalue.UserKeyJsonValue)2 DataSet (org.hisp.dhis.dataset.DataSet)1 LockException (org.hisp.dhis.dataset.LockException)1 ReadAccessDeniedException (org.hisp.dhis.hibernate.exception.ReadAccessDeniedException)1 InterpretationComment (org.hisp.dhis.interpretation.InterpretationComment)1 KeyJsonValue (org.hisp.dhis.keyjsonvalue.KeyJsonValue)1 Period (org.hisp.dhis.period.Period)1 SqlView (org.hisp.dhis.sqlview.SqlView)1 UserGroup (org.hisp.dhis.user.UserGroup)1