ordering.add(prefix + path.getFieldPath() + SPACE + (entry.getValue().equals(Sorting.SortOrder.desc) ? "desc" : "asc"));
/** * 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; }
/** * 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; }