From 7917f5c8df938b856de919954565d0a533aaa13e Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Tue, 26 Jul 2016 22:25:20 +0200 Subject: [PATCH] Spring JPA: spring-data-envers, serializing data --- SpringJava/JPA/spring-jpa-bom/pom.xml | 9 +++++ SpringJava/JPA/spring-jpa-resources/pom.xml | 8 ++++ .../example/rest/controllers/AdController.java | 44 ++++++++++++++++++++++ 3 files changed, 61 insertions(+) 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(",")))); + } + } } -- 2.1.4