Search in sources :

Example 66 with PUT

use of javax.ws.rs.PUT in project graylog2-server by Graylog2.

the class DecoratorResource method update.

@PUT
@Path("/{decoratorId}")
@Timed
@ApiOperation(value = "Update a decorator")
@AuditEvent(type = AuditEventTypes.MESSAGE_DECORATOR_UPDATE)
public Decorator update(@ApiParam(name = "decorator id", required = true) @PathParam("decoratorId") final String decoratorId, @ApiParam(name = "JSON body", required = true) DecoratorImpl decorator) throws NotFoundException {
    final Decorator originalDecorator = decoratorService.findById(decoratorId);
    checkPermission(RestPermissions.DECORATORS_CREATE);
    if (originalDecorator.stream().isPresent()) {
        checkPermission(RestPermissions.STREAMS_EDIT, originalDecorator.stream().get());
    }
    return this.decoratorService.save(decorator.toBuilder().id(originalDecorator.id()).build());
}
Also used : SearchResponseDecorator(org.graylog2.plugin.decorators.SearchResponseDecorator) Decorator(org.graylog2.decorators.Decorator) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 67 with PUT

use of javax.ws.rs.PUT in project graylog2-server by Graylog2.

the class StreamAlertConditionResource method update.

@PUT
@Timed
@Path("{conditionId}")
@ApiOperation(value = "Modify an alert condition")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
@AuditEvent(type = AuditEventTypes.ALERT_CONDITION_UPDATE)
public void update(@ApiParam(name = "streamId", value = "The stream id the alert condition belongs to.", required = true) @PathParam("streamId") String streamid, @ApiParam(name = "conditionId", value = "The alert condition id.", required = true) @PathParam("conditionId") String conditionid, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateConditionRequest ccr) throws NotFoundException, ValidationException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);
    final Stream stream = streamService.load(streamid);
    AlertCondition alertCondition = streamService.getAlertCondition(stream, conditionid);
    try {
        final AlertCondition updatedCondition = alertService.updateFromRequest(alertCondition, convertConfigurationInRequest(ccr));
        streamService.updateAlertCondition(stream, updatedCondition);
    } catch (ConfigurationException e) {
        throw new BadRequestException("Invalid alert condition parameters", e);
    }
}
Also used : ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) BadRequestException(javax.ws.rs.BadRequestException) Stream(org.graylog2.plugin.streams.Stream) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 68 with PUT

use of javax.ws.rs.PUT in project graylog2-server by Graylog2.

the class DashboardWidgetsResource method updateDescription.

@Deprecated
@PUT
@Timed
@ApiOperation(value = "Update description of a widget")
@Path("/{widgetId}/description")
@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 updateDescription(@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.updateWidgetDescription(dashboard, widget, uwr.description());
    LOG.info("Updated description of widget <" + widgetId + "> on dashboard <" + dashboardId + ">. Reason: REST request.");
}
Also used : DashboardWidget(org.graylog2.dashboards.widgets.DashboardWidget) Dashboard(org.graylog2.dashboards.Dashboard) NotFoundException(org.graylog2.database.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 69 with PUT

use of javax.ws.rs.PUT in project graylog2-server by Graylog2.

the class DashboardsResource method update.

@PUT
@Timed
@ApiOperation(value = "Update the settings of a dashboard.")
@Produces(MediaType.APPLICATION_JSON)
@Path("/{dashboardId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found.") })
@AuditEvent(type = AuditEventTypes.DASHBOARD_UPDATE)
public void update(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "JSON body", required = true) UpdateDashboardRequest cr) throws ValidationException, NotFoundException {
    checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
    final Dashboard dashboard = dashboardService.load(dashboardId);
    if (cr.title() != null) {
        dashboard.setTitle(cr.title());
    }
    if (cr.description() != null) {
        dashboard.setDescription(cr.description());
    }
    // Validations are happening here.
    dashboardService.save(dashboard);
}
Also used : Dashboard(org.graylog2.dashboards.Dashboard) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 70 with PUT

use of javax.ws.rs.PUT in project graylog2-server by Graylog2.

the class BlacklistSourceResource method update.

@PUT
@Timed
@Path("/{filterId}")
@ApiOperation(value = "Update an existing blacklist filter", notes = "It can take up to a second until the change is applied")
@Consumes(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.BLACKLIST_FILTER_UPDATE)
public void update(@ApiParam(name = "filterId", required = true) @PathParam("filterId") String filterId, @ApiParam(name = "filterEntry", required = true) FilterDescription filterEntry) throws org.graylog2.database.NotFoundException, ValidationException {
    FilterDescription filter = filterService.load(filterId);
    // did the filter type change?
    if (!filter.getClass().equals(filterEntry.getClass())) {
        // copy the relevant fields from the saved filter and then use the new class
        filterEntry._id = filter._id;
        filterEntry.createdAt = filter.createdAt;
        filterEntry.creatorUserId = filter.creatorUserId;
        filter = filterEntry;
    } else {
        // just copy the changable fields
        filter.description = filterEntry.description;
        filter.fieldName = filterEntry.fieldName;
        filter.name = filterEntry.name;
        filter.pattern = filterEntry.pattern;
    }
    filterService.save(filter);
    clusterEventBus.post(FilterDescriptionUpdateEvent.create(filterId));
}
Also used : FilterDescription(org.graylog2.filters.blacklist.FilterDescription) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Aggregations

PUT (javax.ws.rs.PUT)203 Path (javax.ws.rs.Path)172 Consumes (javax.ws.rs.Consumes)108 Produces (javax.ws.rs.Produces)72 ApiOperation (io.swagger.annotations.ApiOperation)70 ApiResponses (io.swagger.annotations.ApiResponses)53 Timed (com.codahale.metrics.annotation.Timed)36 AuditEvent (org.graylog2.audit.jersey.AuditEvent)36 URI (java.net.URI)24 Response (javax.ws.rs.core.Response)23 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)19 IOException (java.io.IOException)18 BeanWrapper (org.springframework.beans.BeanWrapper)16 BadRequestException (javax.ws.rs.BadRequestException)14 NotFoundException (javax.ws.rs.NotFoundException)14 WebApplicationException (javax.ws.rs.WebApplicationException)12 UriBuilder (javax.ws.rs.core.UriBuilder)12 UUID (java.util.UUID)11 GET (javax.ws.rs.GET)11 POST (javax.ws.rs.POST)11