Search in sources :

Example 11 with UpdateAccessDeniedException

use of org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException in project dhis2-core by dhis2.

the class DashboardController method deleteItemContent.

@RequestMapping(value = "/{dashboardUid}/items/{itemUid}/content/{contentUid}", method = RequestMethod.DELETE)
public void deleteItemContent(HttpServletResponse response, HttpServletRequest request, @PathVariable String dashboardUid, @PathVariable String itemUid, @PathVariable String contentUid) 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 = dashboard.getItemByUid(itemUid);
    if (item == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Dashboard item does not exist: " + dashboardUid));
    }
    if (item.removeItemContent(contentUid)) {
        if (item.getContentCount() == 0 && dashboard.getItems().remove(item)) {
            // Delete if empty                
            dashboardService.deleteDashboardItem(item);
        }
        dashboardService.updateDashboard(dashboard);
        webMessageService.send(WebMessageUtils.ok("Dashboard item content 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 12 with UpdateAccessDeniedException

use of org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException in project dhis2-core by dhis2.

the class DashboardController method moveItem.

@RequestMapping(value = "/{dashboardUid}/items/{itemUid}/position/{position}", method = RequestMethod.POST)
public void moveItem(HttpServletResponse response, HttpServletRequest request, @PathVariable String dashboardUid, @PathVariable String itemUid, @PathVariable int position) 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.");
    }
    if (dashboard.moveItem(itemUid, position)) {
        dashboardService.updateDashboard(dashboard);
        webMessageService.send(WebMessageUtils.ok("Dashboard item moved"), response, request);
    }
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) Dashboard(org.hisp.dhis.dashboard.Dashboard) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with UpdateAccessDeniedException

use of org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException in project dhis2-core by dhis2.

the class DashboardController method putJsonObject.

@Override
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json")
public void putJsonObject(@PathVariable("uid") 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.");
    }
    Dashboard newDashboard = renderService.fromJson(request.getInputStream(), Dashboard.class);
    // TODO Name only for now
    dashboard.setName(newDashboard.getName());
    dashboardService.updateDashboard(dashboard);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) Dashboard(org.hisp.dhis.dashboard.Dashboard) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with UpdateAccessDeniedException

use of org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException 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 15 with UpdateAccessDeniedException

use of org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException 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)

Aggregations

UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)17 User (org.hisp.dhis.user.User)14 Dashboard (org.hisp.dhis.dashboard.Dashboard)7 RootNode (org.hisp.dhis.node.types.RootNode)7 SimpleNode (org.hisp.dhis.node.types.SimpleNode)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)5 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)5 DashboardItem (org.hisp.dhis.dashboard.DashboardItem)5 CollectionNode (org.hisp.dhis.node.types.CollectionNode)5 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)4 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)4 Property (org.hisp.dhis.schema.Property)4 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)3 Schema (org.hisp.dhis.schema.Schema)3 MessageConversation (org.hisp.dhis.webapi.webdomain.MessageConversation)3 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2