From e60bdac72e5c854000d9381b0aed015a41dd2dd0 Mon Sep 17 00:00:00 2001 From: mikoto2000 Date: Mon, 13 Nov 2023 20:17:19 +0000 Subject: [PATCH] DATAREST-1280 Add support sort collection resource by associated property. Closes #1641 Related tickets #1386 #1343 --- .../json/JacksonMappingAwareSortTranslator.java | 4 ---- .../webmvc/json/SortTranslatorUnitTests.java | 16 ++++++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JacksonMappingAwareSortTranslator.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JacksonMappingAwareSortTranslator.java index b6a1061d8..64b284940 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JacksonMappingAwareSortTranslator.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JacksonMappingAwareSortTranslator.java @@ -192,10 +192,6 @@ private List mapPropertyPath(PersistentEntity rootEntity, List persistentProperty : persistentProperties) { - if (associations.isLinkableAssociation(persistentProperty)) { - return Collections.emptyList(); - } - persistentPropertyPath.add(persistentProperty.getName()); } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/SortTranslatorUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/SortTranslatorUnitTests.java index a01654742..aec61111d 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/SortTranslatorUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/SortTranslatorUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 original author or authors. + * Copyright 2016-2023 original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,19 +117,19 @@ void shouldMapKnownNestedProperties() { assertThat(translatedSort.getOrderFor("embedded.someInterface")).isNotNull(); } - @Test // DATAREST-910 - void shouldSkipWrongNestedProperties() { + @Test // DATAREST-1280 + void shouldKnownAssociationProperties() { - Sort translatedSort = sortTranslator.translateSort(Sort.by("embedded.unknown"), + Sort translatedSort = sortTranslator.translateSort(Sort.by("association.name"), mappingContext.getRequiredPersistentEntity(Plain.class)); - assertThat(translatedSort).isEqualTo(Sort.unsorted()); + assertTrue(translatedSort.isSorted()); } - @Test // DATAREST-910, DATAREST-976 - void shouldSkipKnownAssociationProperties() { + @Test // DATAREST-910 + void shouldSkipWrongNestedProperties() { - Sort translatedSort = sortTranslator.translateSort(Sort.by("association.name"), + Sort translatedSort = sortTranslator.translateSort(Sort.by("embedded.unknown"), mappingContext.getRequiredPersistentEntity(Plain.class)); assertThat(translatedSort).isEqualTo(Sort.unsorted());