Search in sources :

Example 6 with DashboardItem

use of org.hisp.dhis.dashboard.DashboardItem in project dhis2-core by dhis2.

the class DashboardController method postJsonItem.

// -------------------------------------------------------------------------
// Dashboard items
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/items", method = RequestMethod.POST, consumes = "application/json")
public void postJsonItem(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Dashboard dashboard = dashboardService.getDashboard(uid);
    if (dashboard == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Dashboard does not exist: " + uid));
    }
    if (!aclService.canUpdate(currentUserService.getCurrentUser(), dashboard)) {
        throw new UpdateAccessDeniedException("You don't have the proper permissions to update this dashboard.");
    }
    DashboardItem item = renderService.fromJson(request.getInputStream(), DashboardItem.class);
    dashboardService.mergeDashboardItem(item);
    dashboard.getItems().add(0, item);
    dashboardService.updateDashboard(dashboard);
    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)

Example 7 with DashboardItem

use of org.hisp.dhis.dashboard.DashboardItem in project dhis2-core by dhis2.

the class DashboardController method deleteItem.

@RequestMapping(value = "/{dashboardUid}/items/{itemUid}", method = RequestMethod.DELETE)
public void deleteItem(HttpServletResponse response, HttpServletRequest request, @PathVariable String dashboardUid, @PathVariable String itemUid) throws WebMessageException {
    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.getDashboardItem(itemUid);
    if (item == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Dashboard item does not exist: " + dashboardUid));
    }
    if (dashboard.hasItems() && dashboard.getItems().remove(item)) {
        dashboardService.deleteDashboardItem(item);
        dashboardService.updateDashboard(dashboard);
        webMessageService.send(WebMessageUtils.ok("Dashboard item removed"), 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)

Example 8 with DashboardItem

use of org.hisp.dhis.dashboard.DashboardItem 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

DashboardItem (org.hisp.dhis.dashboard.DashboardItem)8 Dashboard (org.hisp.dhis.dashboard.Dashboard)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)5 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)5 User (org.hisp.dhis.user.User)2 StringWriter (java.io.StringWriter)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 VelocityContext (org.apache.velocity.VelocityContext)1 Chart (org.hisp.dhis.chart.Chart)1 Document (org.hisp.dhis.document.Document)1 EventChart (org.hisp.dhis.eventchart.EventChart)1 EventReport (org.hisp.dhis.eventreport.EventReport)1 Map (org.hisp.dhis.mapping.Map)1 TaskId (org.hisp.dhis.scheduling.TaskId)1 VelocityManager (org.hisp.dhis.system.velocity.VelocityManager)1 NotAuthenticatedException (org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException)1 Dashboard (org.hisp.dhis.webapi.webdomain.user.Dashboard)1