DATAREST-910 - Support nested Sort properties.

We now support nested Sort properties considering Jackson mapping. Sort translation is optional and skipped if the domain class is not resolvable. Translation in the scope of a domain class maps property paths to apply sorting using embedded properties.

A sort string `nested-name` resolves to a property path `anotherWrap.embedded.name`.

class Aggregate {

	@JsonUnwrapped
	public UnwrapEmbedded anotherWrap;
}

class UnwrapEmbedded {

	@JsonUnwrapped(prefix = "nested-")
	public Embedded embedded;
}

class Embedded {
	public String name;
}

Original pull request: #232.
This commit is contained in:
Mark Paluch
2016-09-28 11:06:04 +02:00
committed by Oliver Gierke
parent 7880bef68c
commit 357bb7a28b
10 changed files with 861 additions and 41 deletions

View File

@@ -17,8 +17,12 @@ package org.springframework.data.rest.webmvc.jpa;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.rest.webmvc.BasePathAwareController;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.data.rest.webmvc.support.DefaultedPageable;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.PathVariable;
@@ -30,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
*
* @author Jon Brisbin
* @author Oliver Gierke
* @author Mark Paluch
*/
@Configuration
@EnableJpaRepositories
@@ -50,6 +55,14 @@ public class JpaRepositoryConfig extends JpaInfrastructureConfig {
static class BooksHtmlController {
@RequestMapping(value = "/books/{id}", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
void person(@PathVariable String id) {}
void someMethod(@PathVariable String id) {}
}
@RepositoryRestController
@RequestMapping("orders")
static class OrdersJsonController {
@RequestMapping(value = "/search/sort", method = RequestMethod.POST, produces = "application/hal+json")
void someMethodWithArgs(Sort sort, Pageable pageable, DefaultedPageable defaultedPageable) {}
}
}

View File

@@ -702,6 +702,16 @@ public class JpaWebTests extends CommonWebTests {
andExpect(client.hasLinkWithRel("self"));
}
/**
* @see DATAREST-910
*/
@Test
public void callUnmappedCustomRepositoryController() throws Exception {
mvc.perform(post("/orders/search/sort")).andExpect(status().isOk());
mvc.perform(post("/orders/search/sort?sort=type&page=1&size=10")).andExpect(status().isOk());
}
private List<Link> preparePersonResources(Person primary, Person... persons) throws Exception {
Link peopleLink = client.discoverUnique("people");