@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(); }
@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(); }
@Override public String toString() { return pathElements.size() == 0 ? "EMPTY" : pathElements.stream() .map(e -> '[' + EntityDictionary.getSimpleName(e.getType()) + ']' + PERIOD + e.getFieldName()) .collect(Collectors.joining("/")); }
/** * Get the comparator for sorting. * * @param path Path to field for sorting * @param order Order to sort * @param requestScope Request scope * @return Comparator for sorting */ private Comparator<Object> getComparator(Path path, Sorting.SortOrder order, RequestScope requestScope) { return (left, right) -> { Object leftCompare = left; Object rightCompare = right; // Drill down into path to find value for comparison for (Path.PathElement pathElement : path.getPathElements()) { leftCompare = PersistentResource.getValue(leftCompare, pathElement.getFieldName(), requestScope); rightCompare = PersistentResource.getValue(rightCompare, pathElement.getFieldName(), requestScope); } // Make sure value is comparable and perform comparison if (leftCompare instanceof Comparable) { int result = ((Comparable<Object>) leftCompare).compareTo(rightCompare); if (order == Sorting.SortOrder.asc) { return result; } return -result; } throw new IllegalStateException("Trying to comparing non-comparable types!"); }; }
String fieldName = pathElement.getFieldName(); Class<?> typeClass = dictionary.lookupEntityClass(pathElement.getType()); String typeAlias = FilterPredicate.getTypeAlias(typeClass);
/** * Get the comparator for sorting. * * @param path Path to field for sorting * @param order Order to sort * @param requestScope Request scope * @return Comparator for sorting */ private Comparator<Object> getComparator(Path path, Sorting.SortOrder order, RequestScope requestScope) { return (left, right) -> { Object leftCompare = left; Object rightCompare = right; // Drill down into path to find value for comparison for (Path.PathElement pathElement : path.getPathElements()) { leftCompare = PersistentResource.getValue(leftCompare, pathElement.getFieldName(), requestScope); rightCompare = PersistentResource.getValue(rightCompare, pathElement.getFieldName(), requestScope); } // Make sure value is comparable and perform comparison if (leftCompare instanceof Comparable) { int result = ((Comparable<Object>) leftCompare).compareTo(rightCompare); if (order == Sorting.SortOrder.asc) { return result; } return -result; } throw new IllegalStateException("Trying to comparing non-comparable types!"); }; }
/** * Validates that none of the provided path's relationships are to-many * @param path The path to validate * @param dictionary The elide entity dictionary * @return True if the path is valid. False otherwise. */ protected static boolean isValidSortRulePath(Path path, EntityDictionary dictionary) { //Validate that none of the relationships are to-many for (Path.PathElement pathElement : path.getPathElements()) { if (! dictionary.isRelation(pathElement.getType(), pathElement.getFieldName())) { continue; } if (dictionary.getRelationshipType(pathElement.getType(), pathElement.getFieldName()).isToMany()) { return false; } } return true; }
/** * Validates that none of the provided path's relationships are to-many * @param path The path to validate * @param dictionary The elide entity dictionary * @return True if the path is valid. False otherwise. */ protected static boolean isValidSortRulePath(Path path, EntityDictionary dictionary) { //Validate that none of the relationships are to-many for (Path.PathElement pathElement : path.getPathElements()) { if (! dictionary.isRelation(pathElement.getType(), pathElement.getFieldName())) { continue; } if (dictionary.getRelationshipType(pathElement.getType(), pathElement.getFieldName()).isToMany()) { return false; } } return true; }
/** * Returns an alias that uniquely identifies the last collection of entities in the path. * @return An alias for the path. */ public String getAlias() { List<PathElement> elements = path.getPathElements(); PathElement last = elements.get(elements.size() - 1); if (elements.size() == 1) { return getTypeAlias(last.getType()); } PathElement previous = elements.get(elements.size() - 2); return getTypeAlias(previous.getType()) + UNDERSCORE + previous.getFieldName(); }
/** * 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(); }
@Override public String toString() { return pathElements.size() == 0 ? "EMPTY" : pathElements.stream() .map(e -> '[' + EntityDictionary.getSimpleName(e.getType()) + ']' + PERIOD + e.getFieldName()) .collect(Collectors.joining("/")); }
/** * Returns an alias that uniquely identifies the last collection of entities in the path. * @return An alias for the path. */ public String getAlias() { List<PathElement> elements = path.getPathElements(); PathElement last = elements.get(elements.size() - 1); if (elements.size() == 1) { return getTypeAlias(last.getType()); } PathElement previous = elements.get(elements.size() - 2); return getTypeAlias(previous.getType()) + UNDERSCORE + previous.getFieldName(); }
/** * 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 static boolean toManyInPath(EntityDictionary dictionary, Path path) { return path.getPathElements().stream() .map(element -> dictionary.getRelationshipType(element.getType(), element.getFieldName())) .anyMatch(RelationshipType::isToMany); }
public static boolean toManyInPath(EntityDictionary dictionary, Path path) { return path.getPathElements().stream() .map(element -> dictionary.getRelationshipType(element.getType(), element.getFieldName())) .anyMatch(RelationshipType::isToMany); }