use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.
the class DashboardWidgetsResource method updateCacheTime.
@Deprecated
@PUT
@Timed
@ApiOperation(value = "Update cache time of a widget")
@Path("/{widgetId}/cachetime")
@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 updateCacheTime(@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 UpdateWidgetRequest uwr) 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);
}
dashboardService.updateWidgetCacheTime(dashboard, widget, uwr.cacheTime());
this.clusterEventBus.post(WidgetUpdatedEvent.create(widget));
LOG.info("Updated cache time of widget <" + widgetId + "> on dashboard <" + dashboardId + "> to " + "[" + uwr.cacheTime() + "]. Reason: REST request.");
}
use of org.graylog2.plugin.database.ValidationException 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.plugin.database.ValidationException 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.plugin.database.ValidationException in project graylog2-server by Graylog2.
the class BlacklistSourceResource method create.
@POST
@Timed
@ApiOperation(value = "Create a blacklist filter", notes = "It can take up to a second until the change is applied")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.BLACKLIST_FILTER_CREATE)
public Response create(@ApiParam(name = "filterEntry", required = true) @Valid @NotNull FilterDescription filterDescription) throws ValidationException {
checkPermission(RestPermissions.BLACKLISTENTRY_CREATE);
// force the user name to be consistent with the requesting user
final User currentUser = getCurrentUser();
if (currentUser == null) {
throw new InternalServerErrorException("Could not load user.");
}
filterDescription.creatorUserId = currentUser.getName();
final FilterDescription savedFilter = filterService.save(filterDescription);
clusterEventBus.post(FilterDescriptionUpdateEvent.create(savedFilter._id.toHexString()));
final URI filterUri = getUriBuilderToSelf().path(BlacklistSourceResource.class).path("{filterId}").build(savedFilter._id);
return Response.created(filterUri).entity(savedFilter).build();
}
use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.
the class SavedSearchesResource method create.
@POST
@Timed
@ApiOperation(value = "Create a new saved search")
@RequiresPermissions(RestPermissions.SAVEDSEARCHES_CREATE)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponse(code = 400, message = "Validation error")
@AuditEvent(type = AuditEventTypes.SAVED_SEARCH_CREATE)
public Response create(@ApiParam(name = "JSON body", required = true) @Valid CreateSavedSearchRequest cr) throws ValidationException {
if (!isTitleTaken("", cr.title())) {
final String msg = "Cannot save search " + cr.title() + ". Title is already taken.";
throw new BadRequestException(msg);
}
final SavedSearch search = savedSearchService.create(cr.title(), cr.query(), getCurrentUser().getName(), Tools.nowUTC());
final String id = savedSearchService.save(search);
final URI searchUri = getUriBuilderToSelf().path(SavedSearchesResource.class).path("{searchId}").build(id);
return Response.created(searchUri).entity(ImmutableMap.of("search_id", id)).build();
}
Aggregations