@Test public void testGlobalExpressionParsing() throws Exception { MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>(); queryParams.add( "filter[author.books.title][in]", "foo,bar,baz" ); queryParams.add( "filter[author.name][infix]", "Hemingway" ); FilterExpression filterExpression = dialect.parseGlobalExpression("/author", queryParams); assertEquals( "(author.books.title IN [foo, bar, baz] AND author.name INFIX [Hemingway])", filterExpression.toString() ); }
@Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { List<FilterPredicate> filterPredicates; filterPredicates = extractPredicates(filterParams); String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String firstPathComponent = ""; if (pathComponents.length > 0) { firstPathComponent = pathComponents[0]; } FilterExpression joinedExpression = null; for (FilterPredicate filterPredicate : filterPredicates) { Class firstClass = filterPredicate.getPath().getPathElements().get(0).getType(); if (!dictionary.getJsonAliasFor(firstClass).equals(firstPathComponent)) { throw new ParseException(String.format("Invalid predicate: %s", filterPredicate)); } if ((filterPredicate.getOperator().equals(Operator.HASMEMBER) || filterPredicate.getOperator().equals(Operator.HASNOMEMBER)) && !FilterPredicate.isLastPathElementAssignableFrom( dictionary, filterPredicate.getPath(), Collection.class)) { throw new ParseException("Invalid Path: Last Path Element has to be a collection type"); } if (joinedExpression == null) { joinedExpression = filterPredicate; } else { joinedExpression = new AndFilterExpression(joinedExpression, filterPredicate); } } return joinedExpression; }
DefaultFilterDialect implements JoinFilterDialect, SubqueryFilterDialect { @Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { List<FilterPredicate> filterPredicates; filterPredicates = extractPredicates(filterParams); String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String firstPathComponent = ""; if (pathComponents.length > 0) { firstPathComponent = pathComponents[0]; } FilterExpression joinedExpression = null; for (FilterPredicate filterPredicate : filterPredicates) { Class firstClass = filterPredicate.getPath().getPathElements().get(0).getType(); if (!dictionary.getJsonAliasFor(firstClass).equals(firstPathComponent)) { throw new ParseException(String.format("Invalid predicate: %s", filterPredicate)); } if ((filterPredicate.getOperator().equals(Operator.HASMEMBER) || filterPredicate.getOperator().equals(Operator.HASNOMEMBER)) && !FilterPredicate.isLastPathElementAssignableFrom( dictionary, filterPredicate.getPath(), Collection.class)) { throw new ParseException("Invalid Path: Last Path Element has to be a collection type"); } if (joinedExpression == null) { joinedExpression = filterPredicate; } else { joinedExpression = new AndFilterExpression(joinedExpression, filterPredicate); } } return joinedExpression; } }
DefaultFilterDialect implements JoinFilterDialect, SubqueryFilterDialect { @Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { List<FilterPredicate> filterPredicates; filterPredicates = extractPredicates(filterParams); String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String firstPathComponent = ""; if (pathComponents.length > 0) { firstPathComponent = pathComponents[0]; } FilterExpression joinedExpression = null; for (FilterPredicate filterPredicate : filterPredicates) { Class firstClass = filterPredicate.getPath().getPathElements().get(0).getType(); if (!dictionary.getJsonAliasFor(firstClass).equals(firstPathComponent)) { throw new ParseException(String.format("Invalid predicate: %s", filterPredicate)); } if ((filterPredicate.getOperator().equals(Operator.HASMEMBER) || filterPredicate.getOperator().equals(Operator.HASNOMEMBER)) && !FilterPredicate.isLastPathElementAssignableFrom( dictionary, filterPredicate.getPath(), Collection.class)) { throw new ParseException("Invalid Path: Last Path Element has to be a collection type"); } if (joinedExpression == null) { joinedExpression = filterPredicate; } else { joinedExpression = new AndFilterExpression(joinedExpression, filterPredicate); } } return joinedExpression; } DefaultFilterDialect(EntityDictionary dictionary); }
DefaultFilterDialect implements JoinFilterDialect, SubqueryFilterDialect { @Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { List<FilterPredicate> filterPredicates; filterPredicates = extractPredicates(filterParams); String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String firstPathComponent = ""; if (pathComponents.length > 0) { firstPathComponent = pathComponents[0]; } FilterExpression joinedExpression = null; for (FilterPredicate filterPredicate : filterPredicates) { Class firstClass = filterPredicate.getPath().getPathElements().get(0).getType(); if (!dictionary.getJsonAliasFor(firstClass).equals(firstPathComponent)) { throw new ParseException(String.format("Invalid predicate: %s", filterPredicate)); } if ((filterPredicate.getOperator().equals(Operator.HASMEMBER) || filterPredicate.getOperator().equals(Operator.HASNOMEMBER)) && !FilterPredicate.isLastPathElementAssignableFrom( dictionary, filterPredicate.getPath(), Collection.class)) { throw new ParseException("Invalid Path: Last Path Element has to be a collection type"); } if (joinedExpression == null) { joinedExpression = filterPredicate; } else { joinedExpression = new AndFilterExpression(joinedExpression, filterPredicate); } } return joinedExpression; } DefaultFilterDialect(EntityDictionary dictionary); @Override FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams); @Override Map<String, FilterExpression> parseTypedExpression(String path, MultivaluedMap<String, String> filterParams); }
DefaultFilterDialect implements JoinFilterDialect, SubqueryFilterDialect { @Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { List<FilterPredicate> filterPredicates; filterPredicates = extractPredicates(filterParams); String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String firstPathComponent = ""; if (pathComponents.length > 0) { firstPathComponent = pathComponents[0]; } FilterExpression joinedExpression = null; for (FilterPredicate filterPredicate : filterPredicates) { Class firstClass = filterPredicate.getPath().getPathElements().get(0).getType(); if (!dictionary.getJsonAliasFor(firstClass).equals(firstPathComponent)) { throw new ParseException(String.format("Invalid predicate: %s", filterPredicate)); } if ((filterPredicate.getOperator().equals(Operator.HASMEMBER) || filterPredicate.getOperator().equals(Operator.HASNOMEMBER)) && !FilterPredicate.isLastPathElementAssignableFrom( dictionary, filterPredicate.getPath(), Collection.class)) { throw new ParseException("Invalid Path: Last Path Element has to be a collection type"); } if (joinedExpression == null) { joinedExpression = filterPredicate; } else { joinedExpression = new AndFilterExpression(joinedExpression, filterPredicate); } } return joinedExpression; } DefaultFilterDialect(EntityDictionary dictionary); @Override FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams); @Override Map<String, FilterExpression> parseTypedExpression(String path, MultivaluedMap<String, String> filterParams);  }