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