checkPermission(RestPermissions.SEARCHES_ABSOLUTE);
checkPermission(RestPermissions.SEARCHES_RELATIVE);
checkPermission(RestPermissions.SEARCHES_KEYWORD);
}
DashboardWidget widget;
try {
widget = DashboardWidget.fromRequest(metricRegistry, searches, awr, getCurrentUser().getName());
Dashboard dashboard = dashboardRegistry.get(dashboardId);
if (dashboard == null) {
LOG.error("Dashboard [{}] not found.", dashboardId);
throw new WebApplicationException(404);
}
dashboardService.addWidget(dashboard, widget);
} catch (ValidationException e1) {
LOG.error("Validation error.", e1);
throw new WebApplicationException(e1, Response.Status.BAD_REQUEST);
} catch (DashboardWidget.NoSuchWidgetTypeException e2) {
LOG.error("No such widget type.", e2);
throw new WebApplicationException(e2, Response.Status.BAD_REQUEST);
} catch (InvalidRangeParametersException e3) {
LOG.error("Invalid timerange parameters provided.", e3);
throw new WebApplicationException(e3, Response.Status.BAD_REQUEST);
} catch (InvalidWidgetConfigurationException e4) {
LOG.error("Invalid widget configuration.", e4);
throw new WebApplicationException(e4, Response.Status.BAD_REQUEST);
}
Map<String, Object> result = Maps.newHashMap();
result.put("widget_id", widget.getId());
return Response.status(Response.Status.CREATED).entity(json(result)).build();
}