@Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> queryParams) throws ParseException { if (joinDialects.isEmpty()) { throw new ParseException("Heterogeneous type filtering not supported"); } return parseExpression(joinDialects, (dialect) -> dialect.parseGlobalExpression(path, queryParams)); }
private static <T, R> R parseExpression(List<T> dialects, ParseFunction<T, R> parseFunction) throws ParseException { ParseException lastFailure = null; for (T dialect : dialects) { try { return parseFunction.apply(dialect); } catch (ParseException e) { if (log.isTraceEnabled()) { log.trace("Parse Failure: {}", e.getMessage()); } if (lastFailure != null) { lastFailure = new ParseException(e.getMessage() + "\n" + lastFailure.getMessage()); } else { lastFailure = e; } } } if (lastFailure == null) { lastFailure = new ParseException("No dialects"); } throw lastFailure; }
globalFilterExpression = filterDialect.parseGlobalExpression(path, filterParams); } catch (ParseException e) { errorMessage = e.getMessage(); errorMessage = e.getMessage(); } else if (! errorMessage.equals(e.getMessage())) { errorMessage = errorMessage + "\n" + e.getMessage();
globalFilterExpression = filterDialect.parseGlobalExpression(path, filterParams); } catch (ParseException e) { errorMessage = e.getMessage(); errorMessage = e.getMessage(); } else if (! errorMessage.equals(e.getMessage())) { errorMessage = errorMessage + "\n" + e.getMessage();
@Override public Map<String, FilterExpression> parseTypedExpression(String path, MultivaluedMap<String, String> queryParams) throws ParseException { if (subqueryDialects.isEmpty()) { throw new ParseException("Type filtering not supported"); } return parseExpression(subqueryDialects, (dialect) -> dialect.parseTypedExpression(path, queryParams)); }
private static <T, R> R parseExpression(List<T> dialects, ParseFunction<T, R> parseFunction) throws ParseException { ParseException lastFailure = null; for (T dialect : dialects) { try { return parseFunction.apply(dialect); } catch (ParseException e) { if (log.isTraceEnabled()) { log.trace("Parse Failure: {}", e.getMessage()); } if (lastFailure != null) { lastFailure = new ParseException(e.getMessage() + "\n" + lastFailure.getMessage()); } else { lastFailure = e; } } } if (lastFailure == null) { lastFailure = new ParseException("No dialects"); } throw lastFailure; }
@Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> queryParams) throws ParseException { if (joinDialects.isEmpty()) { throw new ParseException("Heterogeneous type filtering not supported"); } return parseExpression(joinDialects, (dialect) -> dialect.parseGlobalExpression(path, queryParams)); }
@Override public Map<String, FilterExpression> parseTypedExpression(String path, MultivaluedMap<String, String> queryParams) throws ParseException { if (subqueryDialects.isEmpty()) { throw new ParseException("Type filtering not supported"); } return parseExpression(subqueryDialects, (dialect) -> dialect.parseTypedExpression(path, queryParams)); }
String typeName = matcher.group(1); if (paramValues.size() != 1) { throw new ParseException("Exactly one RSQL expression must be defined for type : " + typeName); throw new ParseException(INVALID_QUERY_PARAMETER + paramName); expressionByType.put(typeName, filterExpression); } catch (RSQLParserException e) { throw new ParseException(e.getMessage()); throw new ParseException(INVALID_QUERY_PARAMETER + paramName);
String typeName = matcher.group(1); if (paramValues.size() != 1) { throw new ParseException("Exactly one RSQL expression must be defined for type : " + typeName); throw new ParseException(INVALID_QUERY_PARAMETER + paramName); expressionByType.put(typeName, filterExpression); } catch (RSQLParserException e) { throw new ParseException(e.getMessage()); throw new ParseException(INVALID_QUERY_PARAMETER + paramName);
throws ParseException { if (filterParams.size() != 1) { throw new ParseException(SINGLE_PARAMETER_ONLY); throw new ParseException(INVALID_QUERY_PARAMETER + queryParamName); throw new ParseException(SINGLE_PARAMETER_ONLY); throw new ParseException("No such collection: " + lastPathComponent); return ast.accept(visitor, entityType); } catch (RSQLParserException e) { throw new ParseException(e.getMessage());
throws ParseException { if (filterParams.size() != 1) { throw new ParseException(SINGLE_PARAMETER_ONLY); throw new ParseException(INVALID_QUERY_PARAMETER + queryParamName); throw new ParseException(SINGLE_PARAMETER_ONLY); throw new ParseException("No such collection: " + lastPathComponent); return ast.accept(visitor, entityType); } catch (RSQLParserException e) { throw new ParseException(e.getMessage());
throw new ParseException("Invalid filter expression"); throw new ParseException("Unknown entity in filter: " + type); : dictionary.getParameterizedType(entityClass, field); if (fieldType == null) { throw new ParseException("Unknown field in filter: " + field);
throw new ParseException("Invalid filter format: " + paramName); throw new ParseException("Invalid filter format: " + paramName);
throw new ParseException("Invalid filter expression"); throw new ParseException("Unknown entity in filter: " + type); : dictionary.getParameterizedType(entityClass, field); if (fieldType == null) { throw new ParseException("Unknown field in filter: " + field);
throw new ParseException("Invalid filter format: " + paramName); throw new ParseException("Invalid filter format: " + paramName);
@Override public Map<String, FilterExpression> parseTypedExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { Map<String, FilterExpression> expressionMap = new HashMap<>(); List<FilterPredicate> filterPredicates = extractPredicates(filterParams); for (FilterPredicate filterPredicate : filterPredicates) { if (FilterPredicate.toManyInPath(dictionary, filterPredicate.getPath())) { throw new ParseException("Invalid toMany join: " + filterPredicate); } String entityType = dictionary.getJsonAliasFor(filterPredicate.getEntityType()); FilterExpression filterExpression = expressionMap.get(entityType); if (filterExpression != null) { expressionMap.put(entityType, new AndFilterExpression(filterExpression, filterPredicate)); } else { expressionMap.put(entityType, filterPredicate); } } return expressionMap; }
@Override public Map<String, FilterExpression> parseTypedExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { Map<String, FilterExpression> expressionMap = new HashMap<>(); List<FilterPredicate> filterPredicates = extractPredicates(filterParams); for (FilterPredicate filterPredicate : filterPredicates) { if (FilterPredicate.toManyInPath(dictionary, filterPredicate.getPath())) { throw new ParseException("Invalid toMany join: " + filterPredicate); } String entityType = dictionary.getJsonAliasFor(filterPredicate.getEntityType()); FilterExpression filterExpression = expressionMap.get(entityType); if (filterExpression != null) { expressionMap.put(entityType, new AndFilterExpression(filterExpression, filterPredicate)); } else { expressionMap.put(entityType, filterPredicate); } } return expressionMap; }
@Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { List<FilterPredicate> filterPredicates; filterPredicates = extractPredicates(filterParams); /* Extract the first collection in the URL */ String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String firstPathComponent = ""; if (pathComponents.length > 0) { firstPathComponent = pathComponents[0]; } /* Comma separated filter parameters are joined with logical AND. */ FilterExpression joinedExpression = null; for (FilterPredicate filterPredicate : filterPredicates) { Class firstClass = filterPredicate.getPath().getPathElements().get(0).getType(); /* The first type in the predicate must match the first collection in the URL */ if (!dictionary.getJsonAliasFor(firstClass).equals(firstPathComponent)) { throw new ParseException(String.format("Invalid predicate: %s", filterPredicate)); } if (joinedExpression == null) { joinedExpression = filterPredicate; } else { joinedExpression = new AndFilterExpression(joinedExpression, filterPredicate); } } return joinedExpression; }
@Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { List<FilterPredicate> filterPredicates; filterPredicates = extractPredicates(filterParams); /* Extract the first collection in the URL */ String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String firstPathComponent = ""; if (pathComponents.length > 0) { firstPathComponent = pathComponents[0]; } /* Comma separated filter parameters are joined with logical AND. */ FilterExpression joinedExpression = null; for (FilterPredicate filterPredicate : filterPredicates) { Class firstClass = filterPredicate.getPath().getPathElements().get(0).getType(); /* The first type in the predicate must match the first collection in the URL */ if (!dictionary.getJsonAliasFor(firstClass).equals(firstPathComponent)) { throw new ParseException(String.format("Invalid predicate: %s", filterPredicate)); } if (joinedExpression == null) { joinedExpression = filterPredicate; } else { joinedExpression = new AndFilterExpression(joinedExpression, filterPredicate); } } return joinedExpression; }