DATAREST-384 - Fixed affordances and execution of sortable search resources.

Search resources are now considered sortable if they contain a Sort parameter. This is now reflected in MethodResourceMapping.isSortableResource().

Building on top of that, the RepositorySearchController now appends the sort template variable to links generated when listing search resources. It also now accepts resolved Sort instances to forward them to the query method execution. The controller now also uses DefaultedPageable so that request missing pagination information use the defaults configured for the PageableHandlerMethodArgumentResolver.
This commit is contained in:
Oliver Gierke
2014-10-15 13:30:53 +02:00
parent 0b5726ac41
commit 8504a8837c
9 changed files with 98 additions and 12 deletions

View File

@@ -23,6 +23,7 @@ import java.lang.reflect.Method;
import org.junit.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
@@ -104,6 +105,23 @@ public class RepositoryMethodResourceMappingUnitTests {
assertThat(mapping.getRel(), is("findByEmailAddress"));
}
/**
* @see DATAREST-384
*/
@Test
public void considersResourceSortableIfSortParameterIsPresent() throws Exception {
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Sort.class);
RepositoryMethodResourceMapping mapping = new RepositoryMethodResourceMapping(method, resourceMapping);
assertThat(mapping.isSortableResource(), is(true));
method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Pageable.class);
mapping = new RepositoryMethodResourceMapping(method, resourceMapping);
assertThat(mapping.isSortableResource(), is(false));
}
static class Person {}
interface PersonRepository extends Repository<Person, Long> {
@@ -118,5 +136,7 @@ public class RepositoryMethodResourceMappingUnitTests {
@RestResource(path = "fooPaged")
Page<Person> findByEmailAddress(String email, Pageable pageable);
Page<Person> findByEmailAddress(String email, Sort pageable);
}
}