/** * Translates {@link Sort} orders from Jackson-mapped field names to {@link PersistentProperty} names. Properties * that cannot be resolved are dropped. * * @param input must not be {@literal null}. * @param rootEntity must not be {@literal null}. * @return {@link Sort} with translated field names or {@literal null} if translation dropped all sort fields. */ public Sort translateSort(Sort input, PersistentEntity<?, ?> rootEntity) { Assert.notNull(input, "Sort must not be null!"); Assert.notNull(rootEntity, "PersistentEntity must not be null!"); List<Order> filteredOrders = new ArrayList<Order>(); for (Order order : input) { List<String> iteratorSource = new ArrayList<String>(); Matcher matcher = SPLITTER.matcher("_" + order.getProperty()); while (matcher.find()) { iteratorSource.add(matcher.group(1)); } String mappedPropertyPath = getMappedPropertyPath(rootEntity, iteratorSource); if (mappedPropertyPath != null) { filteredOrders.add(order.withProperty(mappedPropertyPath)); } } return filteredOrders.isEmpty() ? Sort.unsorted() : Sort.by(filteredOrders); }
/** * Translates {@link Sort} orders from Jackson-mapped field names to {@link PersistentProperty} names. Properties * that cannot be resolved are dropped. * * @param input must not be {@literal null}. * @param rootEntity must not be {@literal null}. * @return {@link Sort} with translated field names or {@literal null} if translation dropped all sort fields. */ public Sort translateSort(Sort input, PersistentEntity<?, ?> rootEntity) { Assert.notNull(input, "Sort must not be null!"); Assert.notNull(rootEntity, "PersistentEntity must not be null!"); List<Order> filteredOrders = new ArrayList<Order>(); for (Order order : input) { List<String> iteratorSource = new ArrayList<String>(); Matcher matcher = SPLITTER.matcher("_" + order.getProperty()); while (matcher.find()) { iteratorSource.add(matcher.group(1)); } String mappedPropertyPath = getMappedPropertyPath(rootEntity, iteratorSource); if (mappedPropertyPath != null) { filteredOrders.add(order.withProperty(mappedPropertyPath)); } } return filteredOrders.isEmpty() ? Sort.unsorted() : Sort.by(filteredOrders); }