use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound in project dhis2-core by dhis2.
the class SmsGatewayController method removeGateway.
// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(value = "/{uid}", method = RequestMethod.DELETE)
public void removeGateway(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws WebMessageException {
SmsGatewayConfig gateway = gatewayAdminService.getGatewayConfigurationByUid(uid);
if (gateway == null) {
throw new WebMessageException(WebMessageUtils.notFound("No gateway found with id: " + uid));
}
gatewayAdminService.removeGatewayByUid(uid);
webMessageService.send(WebMessageUtils.ok("Gateway removed successfully"), response, request);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound in project dhis2-core by dhis2.
the class SmsGatewayController method setDefault.
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(value = "/default/{uid}", method = RequestMethod.PUT)
public void setDefault(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws WebMessageException {
SmsGatewayConfig gateway = gatewayAdminService.getGatewayConfigurationByUid(uid);
if (gateway == null) {
throw new WebMessageException(WebMessageUtils.notFound("No gateway found"));
}
gatewayAdminService.setDefaultGateway(uid);
webMessageService.send(WebMessageUtils.ok(gateway.getName() + " is set to default"), response, request);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound in project dhis2-core by dhis2.
the class SmsGatewayController method getDefault.
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(value = "/default", method = RequestMethod.GET)
public void getDefault(HttpServletRequest request, HttpServletResponse response) throws WebMessageException, IOException {
SmsGatewayConfig defaultGateway = gatewayAdminService.getDefaultGateway();
if (defaultGateway == null) {
throw new WebMessageException(WebMessageUtils.notFound("No default gateway found"));
}
renderService.toJson(response.getOutputStream(), defaultGateway);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound 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);
}
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound 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);
}
}
Aggregations