Search in sources :

Example 1 with ValidationResponse

use of org.graylog.plugins.views.search.validation.ValidationResponse in project graylog2-server by Graylog2.

the class QueryValidationResource method validateQuery.

@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Validate a search query")
@NoAuditEvent("Only validating query structure, not changing any data")
public ValidationResponseDTO validateQuery(@ApiParam(name = "validationRequest") ValidationRequestDTO validationRequest, @Context SearchUser searchUser) {
    final ValidationRequest.Builder q = ValidationRequest.Builder.builder().query(validationRequest.query()).timerange(validationRequest.timerange().orElse(defaultTimeRange())).streams(searchUser.streams().readableOrAllIfEmpty(validationRequest.streams())).parameters(resolveParameters(validationRequest));
    validationRequest.filter().ifPresent(q::filter);
    final ValidationResponse response = queryValidationService.validate(q.build());
    return ValidationResponseDTO.create(toStatus(response.status()), toExplanations(response));
}
Also used : ValidationResponse(org.graylog.plugins.views.search.validation.ValidationResponse) ValidationRequest(org.graylog.plugins.views.search.validation.ValidationRequest) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 2 with ValidationResponse

use of org.graylog.plugins.views.search.validation.ValidationResponse in project graylog2-server by Graylog2.

the class MessagesResource method retrieve.

@ApiOperation(value = "Export messages as CSV", notes = "Use this endpoint, if you want to configure export parameters freely instead of relying on an existing Search")
@POST
@Produces(MoreMediaTypes.TEXT_CSV)
@NoAuditEvent("Has custom audit events")
public ChunkedOutput<SimpleMessageChunk> retrieve(@ApiParam @Valid MessagesRequest rawrequest, @Context SearchUser searchUser) {
    final MessagesRequest request = fillInIfNecessary(rawrequest, searchUser);
    final ValidationRequest.Builder validationReq = ValidationRequest.builder();
    Optional.ofNullable(rawrequest.queryString()).ifPresent(validationReq::query);
    Optional.ofNullable(rawrequest.timeRange()).ifPresent(validationReq::timerange);
    Optional.ofNullable(rawrequest.streams()).ifPresent(validationReq::streams);
    final ValidationResponse validationResponse = queryValidationService.validate(validationReq.build());
    if (validationResponse.status().equals(ValidationStatus.ERROR)) {
        validationResponse.explanations().stream().findFirst().map(ValidationMessage::errorMessage).ifPresent(message -> {
            throw new BadRequestException("Request validation failed: " + message);
        });
    }
    executionGuard.checkUserIsPermittedToSeeStreams(request.streams(), searchUser::canReadStream);
    ExportMessagesCommand command = commandFactory.buildFromRequest(request);
    return asyncRunner.apply(chunkConsumer -> exporter().export(command, chunkConsumer));
}
Also used : ValidationResponse(org.graylog.plugins.views.search.validation.ValidationResponse) ValidationRequest(org.graylog.plugins.views.search.validation.ValidationRequest) MessagesRequest(org.graylog.plugins.views.search.export.MessagesRequest) BadRequestException(javax.ws.rs.BadRequestException) ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 ValidationRequest (org.graylog.plugins.views.search.validation.ValidationRequest)2 ValidationResponse (org.graylog.plugins.views.search.validation.ValidationResponse)2 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)2 BadRequestException (javax.ws.rs.BadRequestException)1 ExportMessagesCommand (org.graylog.plugins.views.search.export.ExportMessagesCommand)1 MessagesRequest (org.graylog.plugins.views.search.export.MessagesRequest)1