Search in sources :

Example 31 with Message

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

the class TestTyperefPrimitiveLongAssociationKeyResource method testGet.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testGet(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    GetRequest<Message> req = new TyperefPrimitiveLongAssociationKeyResourceBuilders(requestOptions).get().id(new CompoundKey().append("src", 1).append("dest", 2)).build();
    Response<Message> resp = REST_CLIENT.sendRequest(req).getResponse();
    Message result = resp.getEntity();
    Assert.assertEquals(result.getId(), "1->2");
    Assert.assertEquals(result.getMessage(), "I need some $20");
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) CompoundKey(com.linkedin.restli.common.CompoundKey) TyperefPrimitiveLongAssociationKeyResourceBuilders(com.linkedin.restli.examples.greetings.client.TyperefPrimitiveLongAssociationKeyResourceBuilders) Test(org.testng.annotations.Test)

Example 32 with Message

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

the class ComplexKeysDataProvider method batchUpdate.

public BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchUpdate(BatchUpdateRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> entities) {
    final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse> results = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse>();
    final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, RestLiServiceException> errors = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, RestLiServiceException>();
    for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> entry : entities.getData().entrySet()) {
        if (_db.containsKey(keyToString(entry.getKey().getKey()))) {
            _db.put(keyToString(entry.getKey().getKey()), entry.getValue());
            results.put(entry.getKey(), new UpdateResponse(HttpStatus.S_200_OK));
        } else {
            errors.put(entry.getKey(), new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
        }
    }
    return new BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>(results, errors);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) UpdateResponse(com.linkedin.restli.server.UpdateResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) Message(com.linkedin.restli.examples.greetings.api.Message) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) HashMap(java.util.HashMap) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with Message

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

the class ComplexKeysResource method batchCreate.

@Override
public BatchCreateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchCreate(final BatchCreateRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> entities) {
    List<CreateResponse> createResponses = new ArrayList<CreateResponse>(entities.getInput().size());
    for (Message message : entities.getInput()) {
        ComplexResourceKey<TwoPartKey, TwoPartKey> key = _dataProvider.create(message);
        CreateResponse createResponse = new CreateResponse(key);
        createResponses.add(createResponse);
    }
    return new BatchCreateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>(createResponses);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) Message(com.linkedin.restli.examples.greetings.api.Message) CreateResponse(com.linkedin.restli.server.CreateResponse) ArrayList(java.util.ArrayList) BatchCreateResult(com.linkedin.restli.server.BatchCreateResult)

Example 34 with Message

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

the class AssociationsSubResource method get.

public Message get(String key) {
    PathKeys pathKeys = getContext().getPathKeys();
    String srcKey = pathKeys.getAsString("src");
    String destKey = pathKeys.getAsString("dest");
    Message message = new Message();
    message.setId(srcKey);
    message.setTone(Tone.FRIENDLY);
    message.setMessage(destKey);
    return message;
}
Also used : PathKeys(com.linkedin.restli.server.PathKeys) Message(com.linkedin.restli.examples.greetings.api.Message)

Example 35 with Message

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

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