|
57 | 57 | import java.util.stream.Collectors;
|
58 | 58 | import javax.annotation.Nonnull;
|
59 | 59 | import javax.annotation.Nullable;
|
| 60 | +import org.apache.commons.lang.StringUtils; |
60 | 61 | import org.springframework.beans.factory.annotation.Autowired;
|
61 | 62 | import org.springframework.beans.factory.annotation.Qualifier;
|
62 | 63 | import org.springframework.http.MediaType;
|
@@ -190,7 +191,8 @@ public ResponseEntity<S> getEntities(
|
190 | 191 | @RequestParam(value = "count", defaultValue = "10") Integer count,
|
191 | 192 | @RequestParam(value = "query", defaultValue = "*") String query,
|
192 | 193 | @RequestParam(value = "scrollId", required = false) String scrollId,
|
193 |
| - @RequestParam(value = "sort", required = false, defaultValue = "urn") String sortField, |
| 194 | + @RequestParam(value = "sort", required = false, defaultValue = "urn") @Deprecated |
| 195 | + String sortField, |
194 | 196 | @RequestParam(value = "sortCriteria", required = false) List<String> sortFields,
|
195 | 197 | @RequestParam(value = "sortOrder", required = false, defaultValue = "ASCENDING")
|
196 | 198 | String sortOrder,
|
@@ -222,14 +224,20 @@ public ResponseEntity<S> getEntities(
|
222 | 224 | authentication.getActor().toUrnStr() + " is unauthorized to " + READ + " entities.");
|
223 | 225 | }
|
224 | 226 |
|
| 227 | + SortOrder finalSortOrder = |
| 228 | + SortOrder.valueOf(Optional.ofNullable(sortOrder).orElse("ASCENDING")); |
| 229 | + |
225 | 230 | List<SortCriterion> sortCriteria;
|
226 |
| - if (!CollectionUtils.isEmpty(sortFields)) { |
| 231 | + if (!CollectionUtils.isEmpty(sortFields) |
| 232 | + && sortFields.stream().anyMatch(StringUtils::isNotBlank)) { |
227 | 233 | sortCriteria = new ArrayList<>();
|
228 |
| - sortFields.forEach( |
229 |
| - field -> sortCriteria.add(SearchUtil.sortBy(field, SortOrder.valueOf(sortOrder)))); |
| 234 | + sortFields.stream() |
| 235 | + .filter(StringUtils::isNotBlank) |
| 236 | + .forEach(field -> sortCriteria.add(SearchUtil.sortBy(field, finalSortOrder))); |
| 237 | + } else if (StringUtils.isNotBlank(sortField)) { |
| 238 | + sortCriteria = Collections.singletonList(SearchUtil.sortBy(sortField, finalSortOrder)); |
230 | 239 | } else {
|
231 |
| - sortCriteria = |
232 |
| - Collections.singletonList(SearchUtil.sortBy(sortField, SortOrder.valueOf(sortOrder))); |
| 240 | + sortCriteria = Collections.singletonList(SearchUtil.sortBy("urn", finalSortOrder)); |
233 | 241 | }
|
234 | 242 |
|
235 | 243 | ScrollResult result =
|
|
0 commit comments