Search in sources :

Example 1 with LinkArray

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 } };
}
Also used : CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) LinkArray(com.linkedin.restli.common.LinkArray) ArrayList(java.util.ArrayList) LowLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.LowLevelRecordWithDefault) HighLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault) DataProvider(org.testng.annotations.DataProvider)

Example 2 with LinkArray

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 } };
}
Also used : CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) LinkArray(com.linkedin.restli.common.LinkArray) ArrayList(java.util.ArrayList) LowLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.LowLevelRecordWithDefault) HighLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault) DataProvider(org.testng.annotations.DataProvider)

Example 3 with LinkArray

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 } };
}
Also used : CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) LinkArray(com.linkedin.restli.common.LinkArray) ArrayList(java.util.ArrayList) LowLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.LowLevelRecordWithDefault) HighLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault) DataProvider(org.testng.annotations.DataProvider)

Example 4 with LinkArray

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;
}
Also used : CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) PagingContext(com.linkedin.restli.server.PagingContext) LinkArray(com.linkedin.restli.common.LinkArray) Parameter(com.linkedin.restli.internal.server.model.Parameter) Link(com.linkedin.restli.common.Link)

Example 5 with LinkArray

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();
}
Also used : CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) LinkArray(com.linkedin.restli.common.LinkArray) Link(com.linkedin.restli.common.Link)

Aggregations

CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)6 LinkArray (com.linkedin.restli.common.LinkArray)6 ArrayList (java.util.ArrayList)4 DataProvider (org.testng.annotations.DataProvider)4 HighLevelRecordWithDefault (com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault)3 LowLevelRecordWithDefault (com.linkedin.restli.examples.defaults.api.LowLevelRecordWithDefault)3 Link (com.linkedin.restli.common.Link)2 DataMap (com.linkedin.data.DataMap)1 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)1 Foo (com.linkedin.pegasus.generator.examples.Foo)1 ResourceMethod (com.linkedin.restli.common.ResourceMethod)1 Parameter (com.linkedin.restli.internal.server.model.Parameter)1 CollectionResult (com.linkedin.restli.server.CollectionResult)1 PagingContext (com.linkedin.restli.server.PagingContext)1 ProjectionMode (com.linkedin.restli.server.ProjectionMode)1