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();
}
Aggregations