@Test public void testGlobalExpressionParsing() throws Exception { MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>(); queryParams.add( "filter", "title==*foo*;authors.name==Hemingway" ); FilterExpression expression = dialect.parseGlobalExpression("/book", queryParams); assertEquals( "(book.title INFIX_CASE_INSENSITIVE [foo] AND book.authors.name IN_INSENSITIVE [Hemingway])", expression.toString() ); }
@Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { if (filterParams.size() != 1) { throw new ParseException(SINGLE_PARAMETER_ONLY); } MultivaluedMap.Entry<String, List<String>> entry = CollectionUtils.get(filterParams, 0); String queryParamName = entry.getKey(); if (!"filter".equals(queryParamName)) { throw new ParseException(INVALID_QUERY_PARAMETER + queryParamName); } List<String> queryParamValues = entry.getValue(); if (queryParamValues.size() != 1) { throw new ParseException(SINGLE_PARAMETER_ONLY); } String queryParamValue = queryParamValues.get(0); String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String lastPathComponent = pathComponents.length > 0 ? pathComponents[pathComponents.length - 1] : ""; Class entityType = dictionary.getEntityClass(lastPathComponent); if (entityType == null) { throw new ParseException("No such collection: " + lastPathComponent); } return parseFilterExpression(queryParamValue, entityType, true); }
RSQLFilterDialect implements SubqueryFilterDialect, JoinFilterDialect { @Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { if (filterParams.size() != 1) { throw new ParseException(SINGLE_PARAMETER_ONLY); } MultivaluedMap.Entry<String, List<String>> entry = CollectionUtils.get(filterParams, 0); String queryParamName = entry.getKey(); if (!"filter".equals(queryParamName)) { throw new ParseException(INVALID_QUERY_PARAMETER + queryParamName); } List<String> queryParamValues = entry.getValue(); if (queryParamValues.size() != 1) { throw new ParseException(SINGLE_PARAMETER_ONLY); } String queryParamValue = queryParamValues.get(0); String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String lastPathComponent = pathComponents.length > 0 ? pathComponents[pathComponents.length - 1] : ""; Class entityType = dictionary.getEntityClass(lastPathComponent); if (entityType == null) { throw new ParseException("No such collection: " + lastPathComponent); } return parseFilterExpression(queryParamValue, entityType, true); } }
RSQLFilterDialect implements SubqueryFilterDialect, JoinFilterDialect { @Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { if (filterParams.size() != 1) { throw new ParseException(SINGLE_PARAMETER_ONLY); } MultivaluedMap.Entry<String, List<String>> entry = CollectionUtils.get(filterParams, 0); String queryParamName = entry.getKey(); if (!"filter".equals(queryParamName)) { throw new ParseException(INVALID_QUERY_PARAMETER + queryParamName); } List<String> queryParamValues = entry.getValue(); if (queryParamValues.size() != 1) { throw new ParseException(SINGLE_PARAMETER_ONLY); } String queryParamValue = queryParamValues.get(0); String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String lastPathComponent = pathComponents.length > 0 ? pathComponents[pathComponents.length - 1] : ""; Class entityType = dictionary.getEntityClass(lastPathComponent); if (entityType == null) { throw new ParseException("No such collection: " + lastPathComponent); } return parseFilterExpression(queryParamValue, entityType, true); } RSQLFilterDialect(EntityDictionary dictionary);  RSQLFilterDialect(EntityDictionary dictionary, CaseSensitivityStrategy caseSensitivityStrategy); }
RSQLFilterDialect implements SubqueryFilterDialect, JoinFilterDialect { @Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { if (filterParams.size() != 1) { throw new ParseException(SINGLE_PARAMETER_ONLY); } MultivaluedMap.Entry<String, List<String>> entry = CollectionUtils.get(filterParams, 0); String queryParamName = entry.getKey(); if (!"filter".equals(queryParamName)) { throw new ParseException(INVALID_QUERY_PARAMETER + queryParamName); } List<String> queryParamValues = entry.getValue(); if (queryParamValues.size() != 1) { throw new ParseException(SINGLE_PARAMETER_ONLY); } String queryParamValue = queryParamValues.get(0); String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String lastPathComponent = pathComponents.length > 0 ? pathComponents[pathComponents.length - 1] : ""; Class entityType = dictionary.getEntityClass(lastPathComponent); if (entityType == null) { throw new ParseException("No such collection: " + lastPathComponent); } return parseFilterExpression(queryParamValue, entityType, true); } RSQLFilterDialect(EntityDictionary dictionary);  RSQLFilterDialect(EntityDictionary dictionary, CaseSensitivityStrategy caseSensitivityStrategy); @Override FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams); @Override Map<String, FilterExpression> parseTypedExpression(String path, MultivaluedMap<String, String> filterParams); FilterExpression parseFilterExpression(String expressionText,
                                                  Class<?> entityType,
                                                  boolean allowNestedToManyAssociations); }
RSQLFilterDialect implements SubqueryFilterDialect, JoinFilterDialect { @Override public FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams) throws ParseException { if (filterParams.size() != 1) { throw new ParseException(SINGLE_PARAMETER_ONLY); } MultivaluedMap.Entry<String, List<String>> entry = CollectionUtils.get(filterParams, 0); String queryParamName = entry.getKey(); if (!"filter".equals(queryParamName)) { throw new ParseException(INVALID_QUERY_PARAMETER + queryParamName); } List<String> queryParamValues = entry.getValue(); if (queryParamValues.size() != 1) { throw new ParseException(SINGLE_PARAMETER_ONLY); } String queryParamValue = queryParamValues.get(0); String normalizedPath = JsonApiParser.normalizePath(path); String[] pathComponents = normalizedPath.split("/"); String lastPathComponent = pathComponents.length > 0 ? pathComponents[pathComponents.length - 1] : ""; Class entityType = dictionary.getEntityClass(lastPathComponent); if (entityType == null) { throw new ParseException("No such collection: " + lastPathComponent); } return parseFilterExpression(queryParamValue, entityType, true); } RSQLFilterDialect(EntityDictionary dictionary);  RSQLFilterDialect(EntityDictionary dictionary, CaseSensitivityStrategy caseSensitivityStrategy); @Override FilterExpression parseGlobalExpression(String path, MultivaluedMap<String, String> filterParams); @Override Map<String, FilterExpression> parseTypedExpression(String path, MultivaluedMap<String, String> filterParams); FilterExpression parseFilterExpression(String expressionText,
                                                  Class<?> entityType,
                                                  boolean allowNestedToManyAssociations);  }