Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Add OffsetPaginatedListDto interface to the pagination module (#114) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleroush authored and nathanschile committed Sep 24, 2018
1 parent 804ff8d commit 491eb37
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 122 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# Beadledom Changelog

## 3.2 - In development

### Additions
* Add OffsetPaginatedListDto interface to the pagination module.

## 3.1 - 12 September 2018

### Additions
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Expand Up @@ -20,6 +20,7 @@ This file contains the list of developers who contributed to this repository
* Cal Fisher [@cbfshr][cal-fisher]
* Ian Kottman [@ikottman][ian-kottman]
* Will Pruyn [@lulzWill][will-pruyn]
* Kyle Roush [@kyleroush][kyle-roush]

[john-leacox]: https://github.com/johnlcox
[jacob-williams]: https://github.com/brokensandals
Expand All @@ -37,5 +38,6 @@ This file contains the list of developers who contributed to this repository
[cal-fisher]: https://github.com/cbfshr
[ian-kottman]: https://github.com/ikottman
[will-pruyn]: https://github.com/lulzWill
[kyle-roush]: https://github.com/kyleroush

Thanks to everyone who helped in building this repository.
@@ -1,5 +1,6 @@
package com.cerner.beadledom.client.example.model;

import com.cerner.beadledom.pagination.models.OffsetPaginatedListDto;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down

This file was deleted.

@@ -0,0 +1,54 @@
package com.cerner.beadledom.pagination;

import com.cerner.beadledom.pagination.models.OffsetPaginatedListDto;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.google.auto.value.AutoValue;
import java.util.ArrayList;

/**
* Offset based pagination list.
*
* <p>Represents an offset based paginated list in a rest response.
*
* @author John Leacox
* @since 3.2
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@AutoValue
@JsonPropertyOrder({
"items",
"totalResults",
"firstLink",
"lastLink",
"nextLink",
"prevLink"
})
@JsonDeserialize(builder = OffsetPaginatedListDtoImpl.Builder.class)
abstract class OffsetPaginatedListDtoImpl<T> implements OffsetPaginatedListDto<T> {

/**
* Creates a builder for {@link OffsetPaginatedListDtoImpl}.
*
* @return instance of {@link Builder}
*/
public static <T> Builder<T> builder() {
return new AutoValue_OffsetPaginatedListDtoImpl.Builder<T>()
.items(new ArrayList<>());
}

@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "")
public abstract static class Builder<T> implements OffsetPaginatedListDto.Builder<Builder<T>, T> {
@JsonCreator
private static OffsetPaginatedListDtoImpl.Builder create() {
return OffsetPaginatedListDtoImpl.builder();
}

public abstract OffsetPaginatedListDtoImpl<T> build();

}
}
Expand Up @@ -32,7 +32,7 @@ public void aroundWriteTo(WriterInterceptorContext context)

// Must use raw types because of erasure
@SuppressWarnings("unchecked")
OffsetPaginatedListDto listWithLinks = OffsetPaginatedListDto.builder()
OffsetPaginatedListDto listWithLinks = OffsetPaginatedListDtoImpl.builder()
.items(list.items())
.totalResults(list.metadata().totalResults())
.firstLink(links.firstLink())
Expand Down
@@ -1,97 +1,61 @@
package com.cerner.beadledom.pagination.models;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.cerner.beadledom.pagination.OffsetPaginatedList;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.google.auto.value.AutoValue;
import com.wordnik.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;

/**
* Offset based pagination list.
*
* <p>Represents an offset based paginated list in a rest response.
*
* @author John Leacox
* @since 3.1
* <p>Represents an offset based paginated list in a rest response. Is used on the client side
* instead of {@link OffsetPaginatedList} to circumvent type erasure.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@AutoValue
@JsonPropertyOrder({
"items",
"totalResults",
"firstLink",
"lastLink",
"nextLink",
"prevLink"
})
@JsonDeserialize(builder = OffsetPaginatedListDto.Builder.class)
public abstract class OffsetPaginatedListDto<T> {
@JsonProperty("items")
@ApiModelProperty(value = "Array of items for the current page")
public abstract List<T> items();
public interface OffsetPaginatedListDto<T> {

@Nullable
@JsonProperty("totalResults")
@ApiModelProperty(value = "Total count of items across all pages")
public abstract Long totalResults();
@Nullable
Long totalResults();

@JsonProperty("firstLink")
public abstract String firstLink();
String firstLink();

@JsonProperty("lastLink")
@Nullable
public abstract String lastLink();
String lastLink();

@JsonProperty("prevLink")
@Nullable
public abstract String prevLink();
String prevLink();

@JsonProperty("nextLink")
@Nullable
public abstract String nextLink();

/**
* Creates a builder for {@link OffsetPaginatedListDto}.
*
* @return instance of {@link Builder}
*/
public static <T> Builder<T> builder() {
return new AutoValue_OffsetPaginatedListDto.Builder<T>()
.items(new ArrayList<>());
}
String nextLink();

@JsonProperty("items")
List<T> items();

@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "")
public abstract static class Builder<T> {
@JsonCreator
private static OffsetPaginatedListDto.Builder create() {
return OffsetPaginatedListDto.builder();
}
interface Builder<B extends Builder<B, T>, T> {

@JsonProperty("items")
public abstract Builder<T> items(List<T> items);
B items(List<T> items);

@JsonProperty("totalResults")
public abstract Builder<T> totalResults(Long totalResults);
B totalResults(Long totalResults);

@JsonProperty("firstLink")
public abstract Builder<T> firstLink(String firstLink);
B firstLink(String firstLink);

@JsonProperty("lastLink")
public abstract Builder<T> lastLink(String lastLink);
B lastLink(String lastLink);

@JsonProperty("nextLink")
public abstract Builder<T> nextLink(String nextLink);
B nextLink(String nextLink);

@JsonProperty("prevLink")
public abstract Builder<T> prevLink(String prevLink);
B prevLink(String prevLink);

public abstract OffsetPaginatedListDto<T> build();
OffsetPaginatedListDto<T> build();
}
}
@@ -1,15 +1,13 @@
package com.cerner.beadledom.pagination

import javax.ws.rs.core.UriInfo

import com.cerner.beadledom.pagination.models.OffsetPaginatedListDto
import javax.ws.rs.core.UriInfo
import org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext
import org.jboss.resteasy.spi.ResteasyUriInfo
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{FunSpec, MustMatchers}

import scala.collection.JavaConverters._

/**
Expand All @@ -20,7 +18,7 @@ import scala.collection.JavaConverters._
class OffsetPaginatedListLinksWriterInterceptorSpec extends FunSpec with MustMatchers with MockitoSugar {
describe("OffsetPaginatedListLinksWriterInterceptor") {
describe("#aroundWriteTo") {
it("replaces an OffsetPaginatedList entity with an OffsetPaginatedListDto entity") {
it("replaces an OffsetPaginatedList entity with an OffsetPaginatedListDtoImpl entity") {
val list = OffsetPaginatedList.builder()
.items(List("a", "b").asJava)
.metadata("limit", 20, "offset", 0L, null, true)
Expand Down

0 comments on commit 491eb37

Please sign in to comment.