use of org.graylog2.dashboards.Dashboard in project graylog2-server by Graylog2.
the class DashboardWidgetsResource method updateWidget.
@PUT
@Timed
@ApiOperation(value = "Update a widget")
@Path("/{widgetId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found."), @ApiResponse(code = 404, message = "Widget not found.") })
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.DASHBOARD_WIDGET_UPDATE)
public void updateWidget(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "widgetId", required = true) @PathParam("widgetId") String widgetId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull AddWidgetRequest awr) throws ValidationException, NotFoundException {
checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
final Dashboard dashboard = dashboardService.load(dashboardId);
final DashboardWidget widget = dashboard.getWidget(widgetId);
if (widget == null) {
final String msg = "Widget " + widgetId + " on dashboard " + dashboardId + " not found.";
LOG.error(msg);
throw new javax.ws.rs.NotFoundException(msg);
}
try {
final DashboardWidget updatedWidget = dashboardWidgetCreator.fromRequest(widgetId, awr, widget.getCreatorUserId());
updatedWidget.setCacheTime(awr.cacheTime());
dashboardService.removeWidget(dashboard, widget);
dashboardService.addWidget(dashboard, updatedWidget);
this.clusterEventBus.post(WidgetUpdatedEvent.create(updatedWidget));
} catch (DashboardWidget.NoSuchWidgetTypeException e2) {
LOG.error("No such widget type.", e2);
throw new BadRequestException(e2);
} catch (InvalidRangeParametersException e3) {
LOG.error("Invalid timerange parameters provided.", e3);
throw new BadRequestException(e3);
} catch (InvalidWidgetConfigurationException e4) {
LOG.error("Invalid widget configuration.", e4);
throw new BadRequestException(e4);
}
LOG.info("Updated widget <" + widgetId + "> on dashboard <" + dashboardId + ">. Reason: REST request.");
}
use of org.graylog2.dashboards.Dashboard in project graylog2-server by Graylog2.
the class DashboardsResource method setPositions.
@PUT
@Timed
@ApiOperation(value = "Update/set the positions of dashboard widgets.")
@Produces(MediaType.APPLICATION_JSON)
@Path("/{dashboardId}/positions")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found.") })
@AuditEvent(type = AuditEventTypes.DASHBOARD_WIDGET_POSITIONS_UPDATE)
public void setPositions(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "JSON body", required = true) @Valid WidgetPositionsRequest uwpr) throws NotFoundException, ValidationException {
checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
final Dashboard dashboard = dashboardService.load(dashboardId);
dashboardService.updateWidgetPositions(dashboard, uwpr);
}
use of org.graylog2.dashboards.Dashboard in project graylog2-server by Graylog2.
the class DashboardsResource method delete.
@DELETE
@Timed
@ApiOperation(value = "Delete a dashboard and all its widgets")
@Produces(MediaType.APPLICATION_JSON)
@Path("/{dashboardId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found.") })
@AuditEvent(type = AuditEventTypes.DASHBOARD_DELETE)
public void delete(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId) throws NotFoundException {
checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
final Dashboard dashboard = dashboardService.load(dashboardId);
dashboard.getWidgets().values().forEach((widget) -> this.clusterEventBus.post(WidgetUpdatedEvent.create(widget)));
dashboardService.destroy(dashboard);
final String msg = "Deleted dashboard <" + dashboard.getId() + ">. Reason: REST request.";
LOG.info(msg);
activityWriter.write(new Activity(msg, DashboardsResource.class));
this.serverEventBus.post(DashboardDeletedEvent.create(dashboard.getId()));
}
use of org.graylog2.dashboards.Dashboard in project graylog2-server by Graylog2.
the class DashboardServiceImpl method load.
@Override
public Dashboard load(String id) throws NotFoundException {
final BasicDBObject o = (BasicDBObject) get(DashboardImpl.class, id);
if (o == null) {
throw new NotFoundException("Couldn't find dashboard with ID " + id);
}
final Dashboard dashboard = this.create((ObjectId) o.get("_id"), o.toMap());
return dashboard;
}
use of org.graylog2.dashboards.Dashboard in project graylog2-server by Graylog2.
the class DashboardServiceImpl method create.
private Dashboard create(ObjectId id, Map<String, Object> fields) {
final Dashboard dashboard = new DashboardImpl(id, fields);
// Add all widgets of this dashboard.
if (fields.containsKey(DashboardImpl.EMBEDDED_WIDGETS)) {
if (fields.get(DashboardImpl.EMBEDDED_WIDGETS) instanceof List) {
for (BasicDBObject widgetFields : (List<BasicDBObject>) fields.get(DashboardImpl.EMBEDDED_WIDGETS)) {
try {
final DashboardWidget widget = dashboardWidgetCreator.fromPersisted(widgetFields);
dashboard.addPersistedWidget(widget);
} catch (DashboardWidget.NoSuchWidgetTypeException e) {
LOG.error("No such widget type: [" + widgetFields.get("type") + "] - Dashboard: [" + dashboard.getId() + "]", e);
} catch (InvalidRangeParametersException e) {
LOG.error("Invalid range parameters of widget in dashboard: [" + dashboard.getId() + "]", e);
} catch (InvalidWidgetConfigurationException e) {
LOG.error("Invalid configuration of widget in dashboard: [" + dashboard.getId() + "]", e);
}
}
}
}
return dashboard;
}
Aggregations