public LTPredicate(PathElement pathElement, Object value) { this(new Path(Collections.singletonList(pathElement)), value); } }
public Class getEntityType() { List<PathElement> elements = path.getPathElements(); PathElement first = elements.get(0); return first.getType(); }
/** * Returns an alias that uniquely identifies the last collection of entities in the path. * @return An alias for the path. */ public String getAlias() { if (pathElements.size() < 2) { return lastElement() .map(e -> getTypeAlias(e.getType())) .orElse(null); } PathElement previous = pathElements.get(pathElements.size() - 2); return getTypeAlias(previous.getType()) + UNDERSCORE + previous.getFieldName(); }
public FilterPredicate(Path path, Operator op, List<Object> values) { this.operator = op; this.path = new Path(path); this.values = ImmutableList.copyOf(values); this.field = path.lastElement() .map(PathElement::getFieldName) .orElse(null); this.fieldPath = path.getPathElements().stream() .map(PathElement::getFieldName) .collect(Collectors.joining(PERIOD)); }
/** * 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); }
/** * Given the sorting rules validate sorting rules against the entities bound to the entityClass. * @param entityClass The root class for sorting (eg. /book?sort=-title this would be package.Book) * @param dictionary The elide entity dictionary * @param <T> The entityClass * @return The valid sorting rules - validated through the entity dictionary, or empty dictionary * @throws InvalidValueException when sorting values are not valid for the jpa entity */ public <T> Map<Path, SortOrder> getValidSortingRules(final Class<T> entityClass, final EntityDictionary dictionary) throws InvalidValueException { Map<Path, SortOrder> returnMap = new LinkedHashMap<>(); for (Map.Entry<String, SortOrder> entry : replaceIdRule(dictionary.getIdFieldName(entityClass)).entrySet()) { String dotSeparatedPath = entry.getKey(); SortOrder order = entry.getValue(); //Creating a path validates that the dot separated path is valid. Path path = new Path(entityClass, dictionary, dotSeparatedPath); if (! isValidSortRulePath(path, dictionary)) { throw new InvalidValueException("Cannot sort across a to-many relationship: " + path.getFieldPath()); } returnMap.put(path, order); } return returnMap; }
Path path = entry.getKey(); String prefix = (prefixWithAlias) ? Path.getTypeAlias(sortClass) + PERIOD : ""; ordering.add(prefix + path.getFieldPath() + SPACE + (entry.getValue().equals(Sorting.SortOrder.desc) ? "desc" : "asc"));
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); }
public FilterPredicate(Path path, Operator op, List<Object> values) { this.operator = op; this.path = new Path(path); this.values = ImmutableList.copyOf(values); this.field = path.lastElement() .map(PathElement::getFieldName) .orElse(null); this.fieldPath = path.getPathElements().stream() .map(PathElement::getFieldName) .collect(Collectors.joining(PERIOD)); }
/** * 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); }
/** * Given the sorting rules validate sorting rules against the entities bound to the entityClass. * @param entityClass The root class for sorting (eg. /book?sort=-title this would be package.Book) * @param dictionary The elide entity dictionary * @param <T> The entityClass * @return The valid sorting rules - validated through the entity dictionary, or empty dictionary * @throws InvalidValueException when sorting values are not valid for the jpa entity */ public <T> Map<Path, SortOrder> getValidSortingRules(final Class<T> entityClass, final EntityDictionary dictionary) throws InvalidValueException { Map<Path, SortOrder> returnMap = new LinkedHashMap<>(); for (Map.Entry<String, SortOrder> entry : replaceIdRule(dictionary.getIdFieldName(entityClass)).entrySet()) { String dotSeparatedPath = entry.getKey(); SortOrder order = entry.getValue(); //Creating a path validates that the dot separated path is valid. Path path = new Path(entityClass, dictionary, dotSeparatedPath); if (! isValidSortRulePath(path, dictionary)) { throw new InvalidValueException("Cannot sort across a to-many relationship: " + path.getFieldPath()); } returnMap.put(path, order); } return returnMap; }
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); }
public GTPredicate(PathElement pathElement, Object value) { this(new Path(Collections.singletonList(pathElement)), value); } }
public Class getEntityType() { List<PathElement> elements = path.getPathElements(); PathElement first = elements.get(0); return first.getType(); }
/** * Returns an alias that uniquely identifies the last collection of entities in the path. * @return An alias for the path. */ public String getAlias() { if (pathElements.size() < 2) { return lastElement() .map(e -> getTypeAlias(e.getType())) .orElse(null); } PathElement previous = pathElements.get(pathElements.size() - 2); return getTypeAlias(previous.getType()) + UNDERSCORE + previous.getFieldName(); }
Class<?> relationshipType = path.lastElement() .map(Path.PathElement::getFieldType) .orElseThrow(() -> new IllegalStateException("Path must not be empty"));
public TruePredicate(PathElement pathElement) { this(new Path(Collections.singletonList(pathElement))); } }
@Override public String toString() { List<PathElement> elements = path.getPathElements(); StringBuilder formattedPath = new StringBuilder(); if (!elements.isEmpty()) { formattedPath.append(StringUtils.uncapitalize(EntityDictionary.getSimpleName(elements.get(0).getType()))); } for (PathElement element : elements) { formattedPath.append(PERIOD).append(element.getFieldName()); } return formattedPath.append(' ').append(operator).append(' ').append(values).toString(); }
Class<?> relationshipType = path.lastElement() .map(Path.PathElement::getFieldType) .orElseThrow(() -> new IllegalStateException("Path must not be empty"));
public IsNullPredicate(PathElement pathElement) { this(new Path(Collections.singletonList(pathElement))); } }