Search in sources :

Example 36 with Message

use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.

the class StringKeysResource method batchGet.

@RestMethod.BatchGet
public Map<String, Message> batchGet(Set<String> ids) {
    Map<String, Message> batch = new HashMap<String, Message>();
    Map<String, RestLiServiceException> errors = new HashMap<String, RestLiServiceException>();
    for (String id : ids) {
        Message g = _db.get(id);
        if (g != null) {
            batch.put(id, g);
        } else {
            errors.put(id, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
        }
    }
    return new BatchResult<String, Message>(batch, errors);
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BatchResult(com.linkedin.restli.server.BatchResult)

Example 37 with Message

use of com.linkedin.restli.examples.greetings.api.Message 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)

Example 38 with Message

use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.

the class StringKeysSubResource method addExample.

private void addExample(String parentKey, String subKey, String text) {
    Message message = new Message();
    message.setId(keyToString(parentKey, subKey));
    message.setMessage(text);
    message.setTone(Tone.SINCERE);
    _db.put(keyToString(parentKey, subKey), message);
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message)

Aggregations

Message (com.linkedin.restli.examples.greetings.api.Message)38 Test (org.testng.annotations.Test)17 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)13 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)11 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)7 EntityResponse (com.linkedin.restli.common.EntityResponse)6 HashSet (java.util.HashSet)6 CompoundKey (com.linkedin.restli.common.CompoundKey)5 DataMap (com.linkedin.data.DataMap)4 EmptyRecord (com.linkedin.restli.common.EmptyRecord)4 Map (java.util.Map)4 CollectionResponse (com.linkedin.restli.common.CollectionResponse)3 UpdateStatus (com.linkedin.restli.common.UpdateStatus)3 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)3 UpdateResponse (com.linkedin.restli.server.UpdateResponse)3 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)2 StringKeysBuilders (com.linkedin.restli.examples.greetings.client.StringKeysBuilders)2 StringKeysRequestBuilders (com.linkedin.restli.examples.greetings.client.StringKeysRequestBuilders)2