Search in sources :

Example 6 with Finder

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

the class AlbumEntryResource method search.

/**
   * Find all entries matching the given album and photo IDs. <code>null</code> is treated
   * as a wildcard.
   * 
   * @param albumId provides the id to match for albums to match,  if not provided, it is treated as a wildcard
   * @param photoId provides the id to match for photos to match,  if not provided, it is treated as a wildcard
   * @return a list of {@link AlbumEntry} matching the  given parameters
   */
@Finder("search")
public List<AlbumEntry> search(@Optional @QueryParam("albumId") Long albumId, @Optional @QueryParam("photoId") Long photoId) {
    List<AlbumEntry> result = new ArrayList<AlbumEntry>();
    for (Map.Entry<CompoundKey, AlbumEntry> entry : _db.getData().entrySet()) {
        CompoundKey key = entry.getKey();
        // (treat all values as a match)
        if (albumId != null && !key.getPart("albumId").equals(albumId))
            continue;
        if (photoId != null && !key.getPart("photoId").equals(photoId))
            continue;
        result.add(entry.getValue());
    }
    return result;
}
Also used : AlbumEntry(com.linkedin.restli.example.AlbumEntry) CompoundKey(com.linkedin.restli.common.CompoundKey) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) Finder(com.linkedin.restli.server.annotations.Finder)

Example 7 with Finder

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

the class CompressionResource method serveRepeatedGreeting.

@Finder("repeatedGreetings")
public List<Greeting> serveRepeatedGreeting(@QueryParam(value = "repeat", typeref = CustomLongRef.class) CustomLong l) {
    List<Greeting> result = new ArrayList<Greeting>();
    Greeting g = new Greeting();
    g.setId(1);
    StringBuilder msg = new StringBuilder();
    for (long i = 0; i < l.toLong(); i++) {
        msg.append("hello world ");
    }
    g.setMessage(msg.toString());
    result.add(g);
    return result;
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ArrayList(java.util.ArrayList) Finder(com.linkedin.restli.server.annotations.Finder)

Example 8 with Finder

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

the class WithContextResource method finder.

@Finder("finder")
public List<Greeting> finder(@HeaderParam("Expected-Header") String header, @ProjectionParam MaskTree projection, @PathKeysParam PathKeys keys) {
    List<Greeting> list = new ArrayList<Greeting>();
    Greeting greeting1 = createGreeting(projection, keys);
    greeting1.setId(1L);
    Greeting greeting2 = createGreeting(header);
    greeting2.setId(2L);
    list.add(greeting1);
    list.add(greeting2);
    return list;
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ArrayList(java.util.ArrayList) Finder(com.linkedin.restli.server.annotations.Finder)

Example 9 with Finder

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

the class AssociationsSubResource method findByTone.

@Finder("tone")
public List<Message> findByTone(@QueryParam("tone") Tone tone) {
    List<Message> messages = new ArrayList<Message>(2);
    Message message1 = new Message();
    message1.setId("one");
    message1.setMessage("one");
    message1.setTone(tone);
    Message message2 = new Message();
    message2.setId("two");
    message2.setMessage("two");
    message2.setTone(tone);
    messages.add(message1);
    messages.add(message2);
    return messages;
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) ArrayList(java.util.ArrayList) Finder(com.linkedin.restli.server.annotations.Finder)

Example 10 with Finder

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

the class StringKeysResource method search.

@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;
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) ArrayList(java.util.ArrayList) Finder(com.linkedin.restli.server.annotations.Finder)

Aggregations

Finder (com.linkedin.restli.server.annotations.Finder)13 ArrayList (java.util.ArrayList)10 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)7 CollectionResult (com.linkedin.restli.server.CollectionResult)3 Message (com.linkedin.restli.examples.greetings.api.Message)2 Tone (com.linkedin.restli.examples.greetings.api.Tone)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DataMap (com.linkedin.data.DataMap)1 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1 StringMap (com.linkedin.data.template.StringMap)1 CompoundKey (com.linkedin.restli.common.CompoundKey)1 AlbumEntry (com.linkedin.restli.example.AlbumEntry)1 Photo (com.linkedin.restli.example.Photo)1 EmptyMap (com.linkedin.restli.examples.greetings.api.EmptyMap)1 SearchMetadata (com.linkedin.restli.examples.greetings.api.SearchMetadata)1 ToneFacet (com.linkedin.restli.examples.greetings.api.ToneFacet)1 ToneFacetArray (com.linkedin.restli.examples.greetings.api.ToneFacetArray)1 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)1