Search in sources :

Example 1 with UnboundParameterError

use of org.graylog.plugins.views.search.errors.UnboundParameterError in project graylog2-server by Graylog2.

the class QueryValidationServiceImpl method toExplanation.

private List<ValidationMessage> toExplanation(String query, SearchException searchException) {
    if (searchException.error() instanceof UnboundParameterError) {
        final UnboundParameterError error = (UnboundParameterError) searchException.error();
        final List<SubstringMultilinePosition> positions = SubstringMultilinePosition.compute(query, "$" + error.parameterName() + "$");
        if (!positions.isEmpty()) {
            return positions.stream().map(p -> ValidationMessage.builder().errorType("Parameter error").errorMessage(error.description()).beginLine(p.getLine()).endLine(p.getLine()).beginColumn(p.getBeginColumn()).endColumn(p.getEndColumn()).build()).collect(Collectors.toList());
        }
    }
    return Collections.singletonList(ValidationMessage.fromException(searchException));
}
Also used : ParseException(org.apache.lucene.queryparser.classic.ParseException) Query(org.graylog.plugins.views.search.Query) Set(java.util.Set) ParameterProvider(org.graylog.plugins.views.search.ParameterProvider) MappedFieldTypesService(org.graylog2.indexer.fieldtypes.MappedFieldTypesService) Streams(com.google.common.collect.Streams) Singleton(javax.inject.Singleton) StringUtils(org.apache.commons.lang3.StringUtils) SearchException(org.graylog.plugins.views.search.errors.SearchException) Collectors(java.util.stream.Collectors) UnboundParameterError(org.graylog.plugins.views.search.errors.UnboundParameterError) Inject(javax.inject.Inject) Objects(java.util.Objects) List(java.util.List) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Stream(java.util.stream.Stream) MappedFieldTypeDTO(org.graylog.plugins.views.search.rest.MappedFieldTypeDTO) Locale(java.util.Locale) Collections(java.util.Collections) UnboundParameterError(org.graylog.plugins.views.search.errors.UnboundParameterError)

Aggregations

Streams (com.google.common.collect.Streams)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Inject (javax.inject.Inject)1 Singleton (javax.inject.Singleton)1 StringUtils (org.apache.commons.lang3.StringUtils)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 ParameterProvider (org.graylog.plugins.views.search.ParameterProvider)1 Query (org.graylog.plugins.views.search.Query)1 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)1 SearchException (org.graylog.plugins.views.search.errors.SearchException)1 UnboundParameterError (org.graylog.plugins.views.search.errors.UnboundParameterError)1 MappedFieldTypeDTO (org.graylog.plugins.views.search.rest.MappedFieldTypeDTO)1 MappedFieldTypesService (org.graylog2.indexer.fieldtypes.MappedFieldTypesService)1