From: Gustavo Martin Morcuende Date: Tue, 26 Jul 2016 20:25:20 +0000 (+0200) Subject: Spring JPA: spring-data-envers, serializing data X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=7917f5c8df938b856de919954565d0a533aaa13e;p=JavaForFun Spring JPA: spring-data-envers, serializing data --- diff --git a/SpringJava/JPA/spring-jpa-bom/pom.xml b/SpringJava/JPA/spring-jpa-bom/pom.xml index a5d1208..ff4360e 100644 --- a/SpringJava/JPA/spring-jpa-bom/pom.xml +++ b/SpringJava/JPA/spring-jpa-bom/pom.xml @@ -253,6 +253,15 @@ jackson-datatype-jsr310 2.8.1 + + + com.fasterxml.jackson.datatype + jackson-datatype-joda + 2.8.1 + + + com.fasterxml.jackson.datatype + jackson-datatype-joda + diff --git a/SpringJava/JPA/spring-jpa-resources/src/main/java/de/spring/example/rest/controllers/AdController.java b/SpringJava/JPA/spring-jpa-resources/src/main/java/de/spring/example/rest/controllers/AdController.java index edbf37d..3a980f3 100644 --- a/SpringJava/JPA/spring-jpa-resources/src/main/java/de/spring/example/rest/controllers/AdController.java +++ b/SpringJava/JPA/spring-jpa-resources/src/main/java/de/spring/example/rest/controllers/AdController.java @@ -3,7 +3,16 @@ package de.spring.example.rest.controllers; import javax.inject.Inject; import org.resthub.web.controller.RepositoryBasedRestController; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.data.history.Revision; +import org.springframework.util.Assert; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import de.spring.example.persistence.domain.Ad; @@ -24,4 +33,39 @@ public class AdController extends RepositoryBasedRestController> findRevisionsPaginated(@PathVariable Long id, + @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, + @RequestParam(value = "size", required = false, defaultValue = "10") Integer size, + @RequestParam(value = "direction", required = false, defaultValue = "") String direction, + @RequestParam(value = "properties", required = false) String properties) { + Assert.isTrue(page > 0, "Page index must be greater than 0"); + Assert.isTrue(direction.isEmpty() || direction.equalsIgnoreCase(Sort.Direction.ASC.toString()) || direction.equalsIgnoreCase(Sort.Direction.DESC.toString()), "Direction should be ASC or DESC"); + if(direction.isEmpty()) { + return this.repository.findRevisions(id, new PageRequest(page - 1, size)); + } else { + Assert.notNull(properties); + return this.repository.findRevisions(id, new PageRequest(page - 1, size, new Sort(Sort.Direction.fromString(direction.toUpperCase()), properties.split(",")))); + } + } }