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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations