@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="ID", updatable=false, nullable=false)
@RevisionNumber
- private Long id;
+ // BE CAREFUL!!!! spring-data-envers JUST WORKS (I couldn't make it work with anything else) WITH Integer. NOT WITH Long :(
+ private Integer id;
@Column(name="REVISION_DATE")
@Temporal(TemporalType.TIMESTAMP)
* WARNING: JPA REQUIRES GETTERS!!!
*/
- public Long getId() {
+ public Integer getId() {
return id;
}
* @param properties Ordered list of comma separeted properies used for sorting resulats. At least one property should be provided if direction is specified
* @return OK http status code if the request has been correctly processed, with the a paginated collection of all resource enclosed in the body.
*/
- @RequestMapping(value="{id}/revisions", method = RequestMethod.GET)
+ @RequestMapping(value="{id}/revisions/", method = RequestMethod.GET)
@ResponseBody
public Page<Revision<Integer, Ad>> findRevisionsPaginated(@PathVariable Long id,
@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
import javax.inject.Inject;
import org.resthub.web.controller.ServiceBasedRestController;
+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.AdDescription;
}
// I do not have to do anything here because all I need is implemented by ServiceBasedRestController :)
+
+
+ /** WE ARE EXTENDING ServiceBasedRestController WITH METHODS FOR RETRIEVING REVISION NUMBERS!!! **/
+
+
+ /**
+ * Returns a {@link Page} of revisions for the entity with the given id
+ *
+ * @param page Page number starting from 0. default to 0
+ * @param size Number of resources by pages. default to 10
+ * @param direction Optional sort direction, could be "asc" or "desc"
+ * @param properties Ordered list of comma separeted properies used for sorting resulats. At least one property should be provided if direction is specified
+ * @return OK http status code if the request has been correctly processed, with the a paginated collection of all resource enclosed in the body.
+ */
+ @RequestMapping(value="{id}/revisions/", method = RequestMethod.GET)
+ @ResponseBody
+ public Page<Revision<Integer, AdDescription>> 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.service.findRevisions(id, new PageRequest(page - 1, size));
+ } else {
+ Assert.notNull(properties);
+ return this.service.findRevisions(id, new PageRequest(page - 1, size, new Sort(Sort.Direction.fromString(direction.toUpperCase()), properties.split(","))));
+ }
+ }
}
import org.resthub.common.service.CrudService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
+import org.springframework.data.history.Revision;
import de.spring.example.persistence.domain.AdDescription;
public interface AdDescriptionService extends CrudService<AdDescription, Long> {
public Page<AdDescription> queryDslExample(Pageable pageRequest);
+
+ /**
+ * Returns a {@link Page} of revisions for the entity with the given id.
+ *
+ * @param id must not be {@literal null}.
+ * @param pageable
+ * @return
+ */
+ Page<Revision<Integer, AdDescription>> findRevisions(Long id, Pageable pageable);
}
--- /dev/null
+package de.spring.example.services;
+
+import java.io.Serializable;
+
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.history.Revision;
+
+public interface RevisionService<T, ID extends Serializable, N extends Number & Comparable<N>> {
+
+ /**
+ * Returns a {@link Page} of revisions for the entity with the given id.
+ *
+ * @param id must not be {@literal null}.
+ * @param pageable
+ * @return
+ */
+ Page<Revision<N, T>> findRevisions(ID id, Pageable pageable);
+}
import org.resthub.common.service.CrudServiceImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
+import org.springframework.data.history.Revision;
import com.querydsl.core.types.dsl.BooleanExpression;
*/
return null;
}
+
+ @Override
+ public Page<Revision<Integer, AdDescription>> findRevisions(Long id, Pageable pageable) {
+ return this.repository.findRevisions(id, pageable);
+ }
}
--- /dev/null
+package de.spring.example.services.impl;
+
+import java.io.Serializable;
+
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.history.Revision;
+
+import de.spring.example.services.RevisionService;
+
+public class RevisionServiceImpl<T, ID extends Serializable, N extends Number & Comparable<N>> implements RevisionService<T, ID, N> {
+
+ @Override
+ public Page<Revision<N, T>> findRevisions(Serializable id, Pageable pageable) {
+
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}