Search in sources :

Example 1 with CreateOutputRequest

use of org.graylog2.rest.models.streams.outputs.requests.CreateOutputRequest in project graylog2-server by Graylog2.

the class OutputResource method create.

@POST
@Timed
@ApiOperation(value = "Create an output")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid output specification in input.", response = OutputSummary.class) })
@AuditEvent(type = AuditEventTypes.MESSAGE_OUTPUT_CREATE)
public Response create(@ApiParam(name = "JSON body", required = true) CreateOutputRequest csor) throws ValidationException {
    checkPermission(RestPermissions.OUTPUTS_CREATE);
    final AvailableOutputSummary outputSummary = messageOutputFactory.getAvailableOutputs().get(csor.type());
    if (outputSummary == null) {
        throw new ValidationException("type", "Invalid output type");
    }
    // Make sure the config values will be stored with the correct type.
    final CreateOutputRequest createOutputRequest = CreateOutputRequest.create(csor.title(), csor.type(), ConfigurationMapConverter.convertValues(csor.configuration(), outputSummary.requestedConfiguration()), csor.streams());
    final Output output = outputService.create(createOutputRequest, getCurrentUser().getName());
    final URI outputUri = getUriBuilderToSelf().path(OutputResource.class).path("{outputId}").build(output.getId());
    return Response.created(outputUri).entity(OutputSummary.create(output.getId(), output.getTitle(), output.getType(), output.getCreatorUserId(), new DateTime(output.getCreatedAt()), new HashMap<>(output.getConfiguration()), output.getContentPack())).build();
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) AvailableOutputSummary(org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary) Output(org.graylog2.plugin.streams.Output) URI(java.net.URI) DateTime(org.joda.time.DateTime) CreateOutputRequest(org.graylog2.rest.models.streams.outputs.requests.CreateOutputRequest) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 URI (java.net.URI)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 AuditEvent (org.graylog2.audit.jersey.AuditEvent)1 ValidationException (org.graylog2.plugin.database.ValidationException)1 Output (org.graylog2.plugin.streams.Output)1 CreateOutputRequest (org.graylog2.rest.models.streams.outputs.requests.CreateOutputRequest)1 AvailableOutputSummary (org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary)1 DateTime (org.joda.time.DateTime)1