@Override public FilterExpression visit(AndNode node, Class entityType) { List<Node> children = node.getChildren(); if (children.size() < 2) { throw new RSQLParseException("Logical AND requires two arguments"); } FilterExpression left = children.get(0).accept(this, entityType); FilterExpression right = children.get(1).accept(this, entityType); AndFilterExpression andFilterExpression = new AndFilterExpression(left, right); for (int idx = 2; idx < children.size(); idx++) { right = children.get(idx).accept(this, entityType); andFilterExpression = new AndFilterExpression(andFilterExpression, right); } return andFilterExpression; }
private Path buildPath(Class rootEntityType, String selector) { String[] associationNames = selector.split("\\."); List<Path.PathElement> path = new ArrayList<>(); Class entityType = rootEntityType; for (String associationName : associationNames) { String typeName = dictionary.getJsonAliasFor(entityType); Class fieldType = dictionary.getParameterizedType(entityType, associationName); if (fieldType == null) { throw new RSQLParseException( String.format("No such association %s for type %s", associationName, typeName)); } path.add(new Path.PathElement(entityType, fieldType, associationName)); entityType = fieldType; } return new Path(path); }
@Override public FilterExpression visit(OrNode node, Class entityType) { List<Node> children = node.getChildren(); if (children.size() < 2) { throw new RSQLParseException("Logical OR requires two arguments"); } FilterExpression left = children.get(0).accept(this, entityType); FilterExpression right = children.get(1).accept(this, entityType); OrFilterExpression orFilterExpression = new OrFilterExpression(left, right); for (int idx = 2; idx < children.size(); idx++) { right = children.get(idx).accept(this, entityType); orFilterExpression = new OrFilterExpression(orFilterExpression, right); } return orFilterExpression; }
throw new RSQLParseException(String.format("Invalid association %s", relationship)); throw new RSQLParseException(String.format("Invalid Operator %s", op.getSymbol()));
throw new RSQLParseException(String.format("Invalid association %s", relationship)); throw new RSQLParseException(String.format("Invalid Operator %s", op.getSymbol()));
/** * Returns Predicate for '=isnull=' case depending on its arguments. * <p> * NOTE: Filter Expression builder specially for '=isnull=' case. * * @return Returns Predicate for '=isnull=' case depending on its arguments. */ private FilterExpression buildIsNullOperator(Path path, List<String> arguments) { String arg = arguments.get(0); try { boolean wantsNull = CoerceUtil.coerce(arg, boolean.class); if (wantsNull) { return new IsNullPredicate(path); } return new NotNullPredicate(path); } catch (InvalidValueException ignored) { throw new RSQLParseException(String.format("Invalid value for operator =isnull= '%s'", arg)); } } }
/** * Returns Predicate for '=isnull=' case depending on its arguments. * <p> * NOTE: Filter Expression builder specially for '=isnull=' case. * * @return Returns Predicate for '=isnull=' case depending on its arguments. */ private FilterExpression buildIsNullOperator(Path path, List<String> arguments) { String arg = arguments.get(0); try { boolean wantsNull = CoerceUtil.coerce(arg, boolean.class); if (wantsNull) { return new IsNullPredicate(path); } return new NotNullPredicate(path); } catch (InvalidValueException ignored) { throw new RSQLParseException(String.format("Invalid value for operator =isnull= '%s'", arg)); } } }
private Path buildPath(Class rootEntityType, String selector) { String[] associationNames = selector.split("\\."); List<Path.PathElement> path = new ArrayList<>(); Class entityType = rootEntityType; for (String associationName : associationNames) { String typeName = dictionary.getJsonAliasFor(entityType); Class fieldType = dictionary.getParameterizedType(entityType, associationName); if (fieldType == null) { throw new RSQLParseException( String.format("No such association %s for type %s", associationName, typeName)); } path.add(new Path.PathElement(entityType, fieldType, associationName)); entityType = fieldType; } return new Path(path); }
@Override public FilterExpression visit(OrNode node, Class entityType) { List<Node> children = node.getChildren(); if (children.size() < 2) { throw new RSQLParseException("Logical OR requires two arguments"); } FilterExpression left = children.get(0).accept(this, entityType); FilterExpression right = children.get(1).accept(this, entityType); OrFilterExpression orFilterExpression = new OrFilterExpression(left, right); for (int idx = 2; idx < children.size(); idx++) { right = children.get(idx).accept(this, entityType); orFilterExpression = new OrFilterExpression(orFilterExpression, right); } return orFilterExpression; }
@Override public FilterExpression visit(AndNode node, Class entityType) { List<Node> children = node.getChildren(); if (children.size() < 2) { throw new RSQLParseException("Logical AND requires two arguments"); } FilterExpression left = children.get(0).accept(this, entityType); FilterExpression right = children.get(1).accept(this, entityType); AndFilterExpression andFilterExpression = new AndFilterExpression(left, right); for (int idx = 2; idx < children.size(); idx++) { right = children.get(idx).accept(this, entityType); andFilterExpression = new AndFilterExpression(andFilterExpression, right); } return andFilterExpression; }