Search in sources :

Example 11 with TwoPartKey

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

the class TestComplexKeysResource method testCreateMainOldBuilders.

private void testCreateMainOldBuilders(CreateRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> createRequestBuilder, GetRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> getRequestBuilder) throws RemoteInvocationException {
    final String messageText = "newMessage";
    Message message = new Message();
    message.setMessage(messageText);
    Request<EmptyRecord> request = createRequestBuilder.input(message).build();
    ResponseFuture<EmptyRecord> future = getClient().sendRequest(request);
    Response<EmptyRecord> response = future.getResponse();
    Assert.assertEquals(response.getStatus(), 201);
    ComplexResourceKey<TwoPartKey, TwoPartKey> expectedComplexKey = getComplexKey(messageText, messageText);
    try {
        @SuppressWarnings("deprecation") String stringId = response.getId();
        Assert.fail("getId() should throw an exception for complex resource keys!");
    } catch (UnsupportedOperationException e) {
    // expected
    }
    @SuppressWarnings("unchecked") CreateResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>> createResponse = (CreateResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>>) response.getEntity();
    Assert.assertEquals(createResponse.getId(), expectedComplexKey);
    // attempt to get the record you just created
    @SuppressWarnings("unchecked") Request<Message> getRequest = getRequestBuilder.id(expectedComplexKey).build();
    ResponseFuture<Message> getFuture = getClient().sendRequest(getRequest);
    Response<Message> getResponse = getFuture.getResponse();
    Assert.assertEquals(getResponse.getEntity().getMessage(), messageText);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) EmptyRecord(com.linkedin.restli.common.EmptyRecord) Message(com.linkedin.restli.examples.greetings.api.Message) CreateResponse(com.linkedin.restli.client.response.CreateResponse) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey)

Example 12 with TwoPartKey

use of com.linkedin.restli.examples.greetings.api.TwoPartKey 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 13 with TwoPartKey

use of com.linkedin.restli.examples.greetings.api.TwoPartKey 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 14 with TwoPartKey

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

the class ComplexKeysSubResource method get.

@RestMethod.Get
public TwoPartKey get(String key) {
    PathKeys pathKeys = getContext().getPathKeys();
    ComplexResourceKey<TwoPartKey, TwoPartKey> keys = pathKeys.get("keys");
    return convert(keys);
}
Also used : PathKeys(com.linkedin.restli.server.PathKeys) TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey)

Example 15 with TwoPartKey

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

the class ComplexKeysSubResource method convert.

private TwoPartKey convert(ComplexResourceKey<TwoPartKey, TwoPartKey> key) {
    TwoPartKey keyKey = key.getKey();
    TwoPartKey keyParam = key.getParams();
    TwoPartKey response = new TwoPartKey();
    response.setMajor(keyKey.getMajor() + "AND" + keyParam.getMajor());
    response.setMinor(keyKey.getMinor() + "AND" + keyParam.getMinor());
    return response;
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey)

Aggregations

TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)21 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)15 Message (com.linkedin.restli.examples.greetings.api.Message)13 HashMap (java.util.HashMap)7 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)5 DataMap (com.linkedin.data.DataMap)4 EntityResponse (com.linkedin.restli.common.EntityResponse)4 UpdateStatus (com.linkedin.restli.common.UpdateStatus)3 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)3 UpdateResponse (com.linkedin.restli.server.UpdateResponse)3 Test (org.testng.annotations.Test)3 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)2 EmptyRecord (com.linkedin.restli.common.EmptyRecord)2 PatchRequest (com.linkedin.restli.common.PatchRequest)2 CreateResponse (com.linkedin.restli.server.CreateResponse)2 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)2 HashSet (java.util.HashSet)2 FutureCallback (com.linkedin.common.callback.FutureCallback)1