/** * Extracts the values to be used in the JobRowFilter query from the query. * * @param tokenizedQuery The tokenized filter expression.. * @param filterQuery The raw query. Used for logging. * * @return The set of values to be used in the JobRowFilter query. * @throws BadFilterException If the fragment of the query that specifies the values is malformed. */ private Set<String> extractValues(Matcher tokenizedQuery, String filterQuery) throws BadFilterException { try { // replaceAll takes care of any leading ['s or trailing ]'s which might mess up the values set. return new LinkedHashSet<>( FilterTokenizer.split( tokenizedQuery.group(3) .replaceAll("\\[", "") .replaceAll("\\]", "") .trim() ) ); } catch (IllegalArgumentException e) { LOG.debug(FILTER_ERROR.logFormat(filterQuery, e.getMessage()), e); throw new BadFilterException(FILTER_ERROR.format(filterQuery, e.getMessage()), e); } }
/** * Extracts the operation to be performed by the ApiJobStore filter query. * * @param tokenizedQuery The tokenized filter expression. * * @return The operation to be performed by the ApiJobStore filter query. * @throws BadFilterException if the operation does not exist */ private FilterOperation extractOperation(Matcher tokenizedQuery) throws BadFilterException { String operationName = tokenizedQuery.group(2); try { return DefaultFilterOperation.fromString(operationName); } catch (IllegalArgumentException ignored) { LOG.debug(FILTER_OPERATOR_INVALID.logFormat(operationName)); throw new BadFilterException(FILTER_OPERATOR_INVALID.format(operationName)); } }
/** * Extracts the JobField to be examined from the tokenizedQuery. * * @param tokenizedQuery The tokenized filter expression. * * @return The JobField to be examined * @throws BadFilterException is the JobField does not exist */ private JobField extractJobField(Matcher tokenizedQuery) throws BadFilterException { String fieldName = tokenizedQuery.group(1); return Arrays.stream(DefaultJobField.values()) .filter(field -> field.getName().equals(fieldName)) .findFirst() .orElseThrow(() -> { LOG.debug(FILTER_JOBFIELD_UNDEFINED.logFormat(fieldName, DefaultJobField.values())); return new BadFilterException(FILTER_JOBFIELD_UNDEFINED.format( fieldName, DefaultJobField.values() )); }); }
/** * Parses the URL ApiJobStore filter query and generates the JobRowFilter object. * * @param filterQuery Expects a URL ApiJobStore filter query String in the format: * <p> * <code>(JobField name)-(operation)[?(value or comma separated values)]?</code> * * @throws BadFilterException when filter pattern is not matched or when any of its properties are not * valid. */ public JobRowFilter(@NotNull String filterQuery) throws BadFilterException { LOG.trace("filterQuery: {}", filterQuery); Matcher tokenizedQuery = QUERY_PATTERN.matcher(filterQuery); // if pattern match found, extract values else throw exception if (!tokenizedQuery.matches()) { LOG.debug(FILTER_INVALID.logFormat(filterQuery)); throw new BadFilterException(FILTER_INVALID.format(filterQuery)); } jobField = extractJobField(tokenizedQuery); operation = extractOperation(tokenizedQuery); values = extractValues(tokenizedQuery, filterQuery); }
throw new BadFilterException(FILTER_INVALID.format(filterQuery)); throw new BadFilterException(FILTER_DIMENSION_UNDEFINED.format(filterDimensionName)); } catch (IllegalArgumentException ignored) { LOG.debug(FILTER_FIELD_NOT_IN_DIMENSIONS.logFormat(dimensionFieldName, filterDimensionName)); throw new BadFilterException( FILTER_FIELD_NOT_IN_DIMENSIONS.format(dimensionFieldName, filterDimensionName) ); } catch (IllegalArgumentException ignored) { LOG.debug(FILTER_OPERATOR_INVALID.logFormat(operationName)); throw new BadFilterException(FILTER_OPERATOR_INVALID.format(operationName)); } catch (IllegalArgumentException e) { LOG.debug(FILTER_ERROR.logFormat(filterQuery, e.getMessage()), e); throw new BadFilterException(FILTER_ERROR.format(filterQuery, e.getMessage()), e);
table.getName() ); throw new BadApiRequestException(errorMessage, new BadFilterException(errorMessage));