From 61d3d1c0bf0885bdc7f725654a46eed60bf393a5 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 23 Jan 2014 15:54:37 +0100 Subject: [PATCH] DATAREST-31 - Improved link rendering for search resources. If the search resource is capable of paging we now augment the link with pagination template variables. --- .../data/rest/webmvc/RepositorySearchController.java | 10 +++++++++- .../RepositorySearchControllerIntegrationTests.java | 7 ++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySearchController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySearchController.java index 2411fc448..c85bc0b1f 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySearchController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySearchController.java @@ -62,6 +62,7 @@ class RepositorySearchController extends AbstractRepositoryRestController { private final EntityLinks entityLinks; private final ResourceMappings mappings; + private final PagedResourcesAssembler assembler; /** * Creates a new {@link RepositorySearchController} using the given {@link PagedResourcesAssembler}, @@ -83,6 +84,7 @@ class RepositorySearchController extends AbstractRepositoryRestController { this.entityLinks = entityLinks; this.mappings = mappings; + this.assembler = assembler; } /** @@ -235,7 +237,13 @@ class RepositorySearchController extends AbstractRepositoryRestController { String parameterTemplateVariable = getParameterTemplateVariable(mapping.getParameterNames()); String href = builder.slash(mapping.getPath()).toString().concat(parameterTemplateVariable); - links.add(new Link(href, mapping.getRel())); + Link link = new Link(href, mapping.getRel()); + + if (mapping.isPagingResource()) { + link = assembler.appendPaginationParameterTemplates(link); + } + + links.add(link); } return new Links(links); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchControllerIntegrationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchControllerIntegrationTests.java index 3f98210b4..da0f6eb97 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchControllerIntegrationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchControllerIntegrationTests.java @@ -61,9 +61,10 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll ResourceTester tester = ResourceTester.of(resource); tester.assertNumberOfLinks(4); tester.assertHasLinkEndingWith("findFirstPersonByFirstName", "findFirstPersonByFirstName{?firstName}"); - tester.assertHasLinkEndingWith("firstname", "firstname{?firstName}"); - tester.assertHasLinkEndingWith("findByCreatedUsingISO8601Date", "findByCreatedUsingISO8601Date{?date}"); - tester.assertHasLinkEndingWith("findByCreatedGreaterThan", "findByCreatedGreaterThan{?date}"); + tester.assertHasLinkEndingWith("firstname", "firstname{?firstName,page,size,sort}"); + tester.assertHasLinkEndingWith("findByCreatedUsingISO8601Date", + "findByCreatedUsingISO8601Date{?date,page,size,sort}"); + tester.assertHasLinkEndingWith("findByCreatedGreaterThan", "findByCreatedGreaterThan{?date,page,size,sort}"); } @Test(expected = ResourceNotFoundException.class)