public FilterPredicate negate() { Operator newOp = operator.negate(); return new FilterPredicate(this.path, newOp, this.values); }
public FilterPredicate negate() { Operator newOp = operator.negate(); return new FilterPredicate(this.path, newOp, this.values); }
private FilterExpression equalityExpression(String argument, Path path, List<Object> values) { boolean startsWith = argument.startsWith("*"); boolean endsWith = argument.endsWith("*"); if (startsWith && endsWith && argument.length() > 2) { String value = argument.substring(1, argument.length() - 1); return new FilterPredicate(path, caseSensitivityStrategy.mapOperator(Operator.INFIX), Collections.singletonList(value)); } if (startsWith && argument.length() > 1) { String value = argument.substring(1, argument.length()); return new FilterPredicate(path, caseSensitivityStrategy.mapOperator(Operator.POSTFIX), Collections.singletonList(value)); } if (endsWith && argument.length() > 1) { String value = argument.substring(0, argument.length() - 1); return new FilterPredicate(path, caseSensitivityStrategy.mapOperator(Operator.PREFIX), Collections.singletonList(value)); } Boolean isStringLike = path.lastElement() .map(e -> e.getFieldType().isAssignableFrom(String.class)) .orElse(false); if (isStringLike) { return new FilterPredicate(path, caseSensitivityStrategy.mapOperator(Operator.IN), values); } return new InPredicate(path, values); }
private FilterExpression equalityExpression(String argument, Path path, List<Object> values) { boolean startsWith = argument.startsWith("*"); boolean endsWith = argument.endsWith("*"); if (startsWith && endsWith && argument.length() > 2) { String value = argument.substring(1, argument.length() - 1); return new FilterPredicate(path, caseSensitivityStrategy.mapOperator(Operator.INFIX), Collections.singletonList(value)); } if (startsWith && argument.length() > 1) { String value = argument.substring(1, argument.length()); return new FilterPredicate(path, caseSensitivityStrategy.mapOperator(Operator.POSTFIX), Collections.singletonList(value)); } if (endsWith && argument.length() > 1) { String value = argument.substring(0, argument.length() - 1); return new FilterPredicate(path, caseSensitivityStrategy.mapOperator(Operator.PREFIX), Collections.singletonList(value)); } Boolean isStringLike = path.lastElement() .map(e -> e.getFieldType().isAssignableFrom(String.class)) .orElse(false); if (isStringLike) { return new FilterPredicate(path, caseSensitivityStrategy.mapOperator(Operator.IN), values); } return new InPredicate(path, values); }
/** * Create a copy of this filter that is scoped by scope. This is used in calculating page totals, we need to * scope this filter in the context of it's parent. * * @param scope the path element to add to the head of the path * @return the scoped filter expression. */ public FilterPredicate scopedBy(PathElement scope) { List<PathElement> pathElements = Lists.asList(scope, path.getPathElements().toArray(ELEMENT_ARRAY)); return new FilterPredicate(new Path(pathElements), operator, values); }
@Override public FilterPredicate getFilterExpression(Class entityClass, RequestScope requestScope) { Path.PathElement path1 = new Path.PathElement(FilterExpressionCheckObj.class, long.class, "id"); Operator op = Operator.LE; List<Object> value = new ArrayList<>(); value.add((long) 2); return new FilterPredicate(path1, op, value); }
public static FilterPredicate createFilterPredicate() { Path.PathElement path1 = new Path.PathElement(AnotherFilterExpressionCheckObj.class, long.class, "createDate"); Operator op = Operator.IN; List<Object> value = new ArrayList<>(); value.add(1999L); return new FilterPredicate(path1, op, value); }
/** * Create a copy of this filter that is scoped by scope. This is used in calculating page totals, we need to * scope this filter in the context of it's parent. * * @param scope the path element to add to the head of the path * @return the scoped filter expression. */ public FilterPredicate scopedBy(PathElement scope) { List<PathElement> pathElements = Lists.asList(scope, path.getPathElements().toArray(ELEMENT_ARRAY)); return new FilterPredicate(new Path(pathElements), operator, values); }
FilterPredicate filterPredicate = new FilterPredicate(path, operator, values);
FilterPredicate filterPredicate = new FilterPredicate(path, operator, values);
public static FilterPredicate createUserPredicate(RequestScope requestScope, boolean setUserId, long setId) { Path.PathElement path1 = new Path.PathElement(FilterExpressionCheckObj.class, long.class, "id"); Operator op = Operator.IN; List<Object> value = new ArrayList<>(); int userId = (int) requestScope.getUser().getOpaqueUser(); if (setUserId) { value.add(setId); } else { value.add((long) userId); } return new FilterPredicate(path1, op, value); }
return new FilterPredicate(path, OPERATOR_MAP.get(op), values);
@Test(expectedExceptions = InvalidValueException.class) public void testEmptyFieldOnPrefix() throws Exception { FilterPredicate pred = new FilterPredicate(new Path.PathElement(Book.class, Author.class, ""), Operator.PREFIX_CASE_INSENSITIVE, Arrays.asList("value")); HQLFilterOperation filterOp = new HQLFilterOperation(); filterOp.apply(pred); }
@Test(expectedExceptions = InvalidValueException.class) public void testEmptyFieldOnInfix() throws Exception { FilterPredicate pred = new FilterPredicate(new Path.PathElement(Book.class, Author.class, ""), Operator.INFIX_CASE_INSENSITIVE, Arrays.asList("value")); HQLFilterOperation filterOp = new HQLFilterOperation(); filterOp.apply(pred); }
return new FilterPredicate(path, OPERATOR_MAP.get(op), values);
@Test(expectedExceptions = InvalidValueException.class) public void testEmptyFieldOnPostfix() throws Exception { FilterPredicate pred = new FilterPredicate(new Path.PathElement(Book.class, Author.class, ""), Operator.POSTFIX_CASE_INSENSITIVE, Arrays.asList("value")); HQLFilterOperation filterOp = new HQLFilterOperation(); filterOp.apply(pred); } }