@RestMethod.GetAll public CollectionResult<Greeting, Empty> getAllCollectionResult(@PagingContextParam PagingContext ctx) { return null; }
defaultContext = new PagingContext(pagingContextParam.defaultStart(), pagingContextParam.defaultCount(), false, false); parameter = Parameter.ParamType.PAGING_CONTEXT_PARAM;
@Override public List<Message> getAll(@PagingContextParam PagingContext pagingContext) { return _dataProvider.getAll(); }
@RestMethod.GetAll public List<Greeting> getAll(@PagingContextParam PagingContext ctx) { // Deterministic behaviour of getAll to make it easier to test as part of the integration test suite // Just return those greetings that have "GetAll" present in their message List<Greeting> greetings = new ArrayList<Greeting>(); for (Greeting greeting: _db.values()) { if (greeting.getMessage().contains("GetAll")) { greetings.add(greeting); } } return greetings; }
@Finder("searchReturnNullList") public List<Greeting> searchReturnNullList(@PagingContextParam PagingContext ctx, @QueryParam("tone") Tone tone) { if (tone == Tone.INSULTING) { //return a null list return null; } else { //return a list with a null element in it final List<Greeting> greetings = new ArrayList<Greeting>(); greetings.add(null); greetings.add(DB.get(1)); return greetings; } }
/** * This resource method is used to create additional paging metadata for fields such as links. Client side * tests can use this method to potentially project on fields inside of links. */ @Finder("searchWithLinksResult") public CollectionResult<Greeting, Empty> searchWithLinksResult(@PagingContextParam PagingContext ctx) { List<Greeting> greetings = new ArrayList<Greeting>(); for (int i = 0; i<5; i++) { greetings.add(GREETING_ONE); greetings.add(GREETING_TWO); } return new CollectionResult<Greeting, Empty>(greetings, 50); } }
@Finder("finderTaskNullList") public Task<List<Greeting>> finderTaskNullList(@PagingContextParam final PagingContext a, @QueryParam("tone") final Tone b) { return new BaseTask<List<Greeting>>() { protected Promise<List<Greeting>> run(final com.linkedin.parseq.Context context) throws Exception { //Depending on the tone, we return a null list or a list with a null element return Promises.value(searchReturnNullList(a, b)); } }; } }
@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; } } } if(greetings.size() > 0) greetings.remove(0); // for testing, using a post-filter that just removes the first element int total = _db.values().size(); // but we keep the numElements returned as the full count despite the fact that with the filter removed 1 // this is to keep paging consistent even in the presence of a post filter. return new CollectionResult<Greeting, Empty>(greetings, total, null, PageIncrement.FIXED); }
@Finder("searchReturnNullCollectionList") public CollectionResult<Greeting, SearchMetadata> searchReturnNullCollectionList(@PagingContextParam PagingContext ctx, @QueryParam("tone") Tone tone) { if (tone == Tone.INSULTING) { //return a null CollectionResult return null; } else if (tone == Tone.SINCERE) { //return a CollectionResult with a null list return new CollectionResult<Greeting, SearchMetadata>(null); } else { //return a CollectionResult with a list that has a null element in it final List<Greeting> greetings = new ArrayList<Greeting>(); greetings.add(null); greetings.add(DB.get(1)); return new CollectionResult<Greeting, SearchMetadata>(greetings); } }
@Finder("finderPromiseNullList") public Promise<List<Greeting>> finderPromiseNullList(@PagingContextParam final PagingContext a, @QueryParam("tone") final Tone b) { final SettablePromise<List<Greeting>> result = Promises.settable(); final Runnable requestHandler = new Runnable() { public void run() { try { //Depending on the tone, we return a null list or a list with a null element result.done(searchReturnNullList(a, b)); } catch (final Throwable throwable) { result.fail(throwable); } } }; SCHEDULER.schedule(requestHandler, DELAY, TimeUnit.MILLISECONDS); return result; }
@Finder("finderCallbackNullList") public void finderCallbackNull(@PagingContextParam final PagingContext a, @QueryParam("tone") final Tone b, @CallbackParam final Callback<List<Greeting>> callback) { final Runnable requestHandler = new Runnable() { public void run() { try { //Depending on the tone, we return a null list or a list with a null element callback.onSuccess(searchReturnNullList(a, b)); } catch (final Throwable throwable) { callback.onError(throwable); } } }; SCHEDULER.schedule(requestHandler, DELAY, TimeUnit.MILLISECONDS); }
@Finder("search") public List<Message> search(@PagingContextParam PagingContext ctx, @QueryParam("keyword") @Optional String keyword) { keyword = keyword.toLowerCase(); List<Message> messages = new ArrayList<Message>(); int idx = 0; int start = ctx.getStart(); int stop = start + ctx.getCount(); for (Message g : _db.values()) { if (keyword == null || g.getMessage().toLowerCase().contains(keyword)) { if (idx++ >= ctx.getStart()) { messages.add(g); } if (idx == stop) { break; } } } return messages; } }
@Finder("searchWithTones") public List<Greeting> searchWithTones(@PagingContextParam PagingContext ctx, @QueryParam("tones") @Optional Tone[] tones) { Set<Tone> toneSet = new HashSet<Tone>(Arrays.asList(tones)); 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()) { if (tones == null || toneSet.contains(g.getTone())) { greetings.add(g); } if (idx == stop) { break; } } } return greetings; }
@Finder("searchWithDefault") public List<Greeting> searchWithDefault(@PagingContextParam PagingContext ctx, @QueryParam("tone") @Optional("FRIENDLY") Tone tone) { return search(ctx, tone); }
/** * This resource method performs automatic projection for the root object entities and also the custom metadata. */ @Finder("rootAutomaticMetadataAutomatic") public CollectionResult<Greeting, Greeting> rootAutomaticMetadataAutomatic( final @PagingContextParam PagingContext ctx, final @ProjectionParam MaskTree rootObjectProjection, final @MetadataProjectionParam MaskTree metadataProjection, final @PagingProjectionParam MaskTree pagingProjection) { return new CollectionResult<Greeting, Greeting>(LIST, 2, CUSTOM_METADATA_GREETING); }
@Override public List<GroupMembership> getAll(@PagingContextParam PagingContext pagingContext) { return _app.getMembershipMgr() .search(new GroupMembershipSearchQuery(GroupMembershipSearchQuery.WILDCARD, pagingContext.getStart(), pagingContext.getCount())); } }
@Finder("search") public List<Greeting> search(@PagingContextParam PagingContext ctx, @QueryParam("tone") @Optional Tone tone) { 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()) { if (tone == null || g.getTone().equals(tone)) { greetings.add(g); } if (idx == stop) { break; } } } return greetings; }
/** * This resource method performs automatic projection for the custom metadata and complete automatic projection * for paging. This means that it will provide a total in its construction of CollectionResult. */ @Finder("metadataAutomaticPagingFullyAutomatic") public CollectionResult<Greeting, Greeting> metadataAutomaticPagingFullyAutomatic( final @PagingContextParam PagingContext ctx, final @ProjectionParam MaskTree rootObjectProjection, final @MetadataProjectionParam MaskTree metadataProjection, final @PagingProjectionParam MaskTree pagingProjection) { return new CollectionResult<Greeting, Greeting>(LIST, 2, CUSTOM_METADATA_GREETING); }
@Finder("searchWithFacets") public CollectionResult<Greeting, SearchMetadata> searchWithFacets(@PagingContextParam PagingContext ctx, @QueryParam("tone") @Optional Tone tone) { List<Greeting> greetings = search(ctx, tone); Map<Tone, Integer> toneCounts = new HashMap<Tone, Integer>(); for (Greeting g : greetings) { if (!toneCounts.containsKey(g.getTone())) { toneCounts.put(g.getTone(), 0); } toneCounts.put(g.getTone(), toneCounts.get(g.getTone()) + 1); } SearchMetadata metadata = new SearchMetadata(); metadata.setFacets(new ToneFacetArray()); for(Map.Entry<Tone, Integer> entry : toneCounts.entrySet()) { ToneFacet f = new ToneFacet(); f.setTone(entry.getKey()); f.setCount(entry.getValue()); metadata.getFacets().add(f); } return new CollectionResult<Greeting, SearchMetadata>(greetings, null, metadata); }
/** * This resource method performs automatic projection for the root object entities and automatic on the metadata * as well. The caveat here is that the metadata returned by the resource method is null. We want to make sure * restli doesn't fall over when it sees the null later on. */ @Finder("rootAutomaticMetadataAutomaticNull") public CollectionResult<Greeting, Greeting> rootAutomaticMetadataAutomaticNull( final @PagingContextParam PagingContext ctx, final @ProjectionParam MaskTree rootObjectProjection, final @MetadataProjectionParam MaskTree metadataProjection, final @PagingProjectionParam MaskTree pagingProjection) { return new CollectionResult<Greeting, Greeting>(LIST, 2, null); }