Search in sources :

Example 6 with CollectionResult

use of com.linkedin.restli.server.CollectionResult in project rest.li by linkedin.

the class GreetingsResourceImpl method searchWithPostFilter.

@Finder("searchWithPostFilter")
public CollectionResult<Greeting, Empty> searchWithPostFilter(@PagingContextParam PagingContext ctx) {
    List<Greeting> greetings = new ArrayList<Greeting>();
    int idx = 0;
    int start = ctx.getStart();
    int stop = start + ctx.getCount();
    for (Greeting g : _db.values()) {
        if (idx++ >= ctx.getStart()) {
            greetings.add(g);
            if (idx == stop) {
                break;
            }
        }
    }
    // for testing, using a post-filter that just removes the first element
    if (greetings.size() > 0)
        greetings.remove(0);
    int total = _db.values().size();
    // this is to keep paging consistent even in the presence of a post filter.
    return new CollectionResult<Greeting, Empty>(greetings, total, null, PageIncrement.FIXED);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResult(com.linkedin.restli.server.CollectionResult) ArrayList(java.util.ArrayList) Finder(com.linkedin.restli.server.annotations.Finder)

Aggregations

CollectionResult (com.linkedin.restli.server.CollectionResult)6 DataMap (com.linkedin.data.DataMap)3 ArrayList (java.util.ArrayList)3 CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)2 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)2 Finder (com.linkedin.restli.server.annotations.Finder)2 HashMap (java.util.HashMap)2 ByteString (com.linkedin.data.ByteString)1 StringMap (com.linkedin.data.template.StringMap)1 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)1 Foo (com.linkedin.pegasus.generator.examples.Foo)1 RestResponse (com.linkedin.r2.message.rest.RestResponse)1 CollectionResponse (com.linkedin.restli.common.CollectionResponse)1 CreateStatus (com.linkedin.restli.common.CreateStatus)1 HttpStatus (com.linkedin.restli.common.HttpStatus)1 LinkArray (com.linkedin.restli.common.LinkArray)1 ResourceMethod (com.linkedin.restli.common.ResourceMethod)1 UpdateStatus (com.linkedin.restli.common.UpdateStatus)1 EmptyMap (com.linkedin.restli.examples.greetings.api.EmptyMap)1 SearchMetadata (com.linkedin.restli.examples.greetings.api.SearchMetadata)1