use of com.linkedin.restli.common.LinkArray in project rest.li by linkedin.
the class TestFillInDefaultValue method testGetAllData.
@DataProvider(name = "testGetAllData")
private Object[][] testGetAllData() throws CloneNotSupportedException {
final int count = 3;
List<HighLevelRecordWithDefault> elements = new ArrayList<>();
for (int i = 0; i < count; i++) {
elements.add(new HighLevelRecordWithDefault(expectedTestData.clone()).setNoDefaultFieldA(i));
}
CollectionMetadata collectionMetadata = new CollectionMetadata().setCount(10).setTotal(3).setStart(0).setLinks(new LinkArray());
LowLevelRecordWithDefault metadata = new LowLevelRecordWithDefault();
metadata.setNameWithDefault(metadata.getNameWithDefault());
return new Object[][] { { elements, collectionMetadata, metadata } };
}
use of com.linkedin.restli.common.LinkArray in project rest.li by linkedin.
the class TestFillInDefaultValue method testFinderData.
@DataProvider(name = "testFinderData")
private Object[][] testFinderData() throws CloneNotSupportedException {
final int total = 3;
List<HighLevelRecordWithDefault> elements = new ArrayList<>();
for (int i = 0; i < total; i++) {
elements.add(new HighLevelRecordWithDefault(expectedTestData.clone()).setNoDefaultFieldA(2));
}
CollectionMetadata collectionMetadata = new CollectionMetadata().setLinks(new LinkArray()).setCount(10).setTotal(3).setStart(0);
LowLevelRecordWithDefault metadata = new LowLevelRecordWithDefault();
metadata.setNameWithDefault(metadata.getNameWithDefault());
return new Object[][] { { 2, elements, collectionMetadata, metadata } };
}
use of com.linkedin.restli.common.LinkArray in project rest.li by linkedin.
the class TestFillInDefaultValue method testGetAllDataWithoutRequireDefault.
@DataProvider(name = "testGetAllDataWithoutRequireDefault")
private Object[][] testGetAllDataWithoutRequireDefault() throws CloneNotSupportedException {
final int count = 3;
List<HighLevelRecordWithDefault> elements = new ArrayList<>();
for (int i = 0; i < count; i++) {
elements.add(new HighLevelRecordWithDefault().setNoDefaultFieldA(i));
}
CollectionMetadata collectionMetadata = new CollectionMetadata().setLinks(new LinkArray()).setCount(10).setStart(0).setTotal(3);
LowLevelRecordWithDefault metadata = new LowLevelRecordWithDefault();
return new Object[][] { { elements, collectionMetadata, metadata } };
}
use of com.linkedin.restli.common.LinkArray in project rest.li by linkedin.
the class RestUtils method buildMetadata.
public static CollectionMetadata buildMetadata(final URI requestUri, final ResourceContext resourceContext, final ResourceMethodDescriptor methodDescriptor, final List<?> resultElements, final PageIncrement pageIncrement, final Integer totalResults) {
CollectionMetadata metadata = new CollectionMetadata();
List<Parameter<?>> pagingContextParams = methodDescriptor.getParametersWithType(Parameter.ParamType.PAGING_CONTEXT_PARAM);
PagingContext defaultPagingContext = pagingContextParams.isEmpty() ? null : (PagingContext) pagingContextParams.get(0).getDefaultValue();
PagingContext pagingContext = getPagingContext(resourceContext, defaultPagingContext);
metadata.setCount(pagingContext.getCount());
metadata.setStart(pagingContext.getStart());
if (totalResults != null) {
metadata.setTotal(totalResults);
} else {
metadata.removeTotal();
}
LinkArray links = new LinkArray();
String bestEncoding = pickBestEncoding(resourceContext.getRequestHeaders().get(RestConstants.HEADER_ACCEPT), Collections.emptySet());
if (pagingContext.getCount() > 0) {
// prev link
if (pagingContext.getStart() > 0) {
int prevStart = Math.max(0, pagingContext.getStart() - pagingContext.getCount());
String prevUri = buildPaginatedUri(requestUri, prevStart, pagingContext.getCount());
Link prevLink = new Link();
prevLink.setRel("prev");
prevLink.setHref(prevUri);
prevLink.setType(bestEncoding);
links.add(prevLink);
}
// next link if there are more results, or we returned a full page
Integer nextStart = getNextPageStart(resultElements.size(), totalResults, pagingContext, pageIncrement);
if (nextStart != null) {
// R2 doesn't expose host/port => can't build absolute URI (this is ok, as
// relative URIs internally
String nextUri = buildPaginatedUri(requestUri, nextStart, pagingContext.getCount());
Link nextLink = new Link();
nextLink.setRel("next");
nextLink.setHref(nextUri);
nextLink.setType(bestEncoding);
links.add(nextLink);
}
}
// even when we are getting count = 0, we should honor that links
// is a required field in the CollectionMetadata record
metadata.setLinks(links);
return metadata;
}
use of com.linkedin.restli.common.LinkArray in project rest.li by linkedin.
the class TestDataMapConverter method createTestDataMap.
private DataMap createTestDataMap() {
CollectionMetadata someRecord = new CollectionMetadata();
someRecord.setCount(1);
someRecord.setStart(0);
someRecord.setTotal(10);
LinkArray links = new LinkArray();
Link link = new Link();
link.setHref("prevUri");
link.setRel("prev");
link.setType("en");
links.add(link);
someRecord.setLinks(links);
return someRecord.data();
}
Aggregations