use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.
the class TestGreetingClientContentTypes method testBatchGet.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataBatchDataProvider")
public void testBatchGet(RestClient restClient, RestliRequestOptions requestOptions) throws RemoteInvocationException {
List<Long> ids = Arrays.asList(1L, 2L, 3L, 4L);
Request<BatchResponse<Greeting>> request = new GreetingsBuilders(requestOptions).batchGet().ids(ids).build();
Response<BatchResponse<Greeting>> response = restClient.sendRequest(request).getResponse();
BatchResponse<Greeting> batchResponse = response.getEntity();
Assert.assertEquals(batchResponse.getResults().size(), ids.size());
}
use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.
the class TestSimpleResourceHierarchy method testSubCollectionBatchGet.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testSubCollectionBatchGet(RestliRequestOptions requestOptions) throws RemoteInvocationException {
List<Long> ids = Arrays.asList(1L, 2L, 3L, 4L);
Request<BatchResponse<Greeting>> request = new SubgreetingsBuilders(requestOptions).batchGet().ids(ids).build();
Response<BatchResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
BatchResponse<Greeting> batchResponse = response.getEntity();
Assert.assertEquals(batchResponse.getResults().size(), ids.size());
}
use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.
the class MockBatchResponseFactory method create.
/**
* Creates a {@link com.linkedin.restli.common.BatchResponse}
*
* @param entryClass the class of the elements stored in this {@link com.linkedin.restli.common.BatchResponse}
* @param recordTemplates the elements to be stored in this {@link com.linkedin.restli.common.BatchResponse}
* @param <T> class of the elements stored in this {@link com.linkedin.restli.common.BatchResponse}
* @return a {@link com.linkedin.restli.common.BatchResponse} with the above properties
*/
public static <T extends RecordTemplate> BatchResponse<T> create(Class<T> entryClass, Map<String, T> recordTemplates) {
DataMap batchResponseDataMap = new DataMap();
DataMap rawBatchData = new DataMap();
batchResponseDataMap.put(BatchResponse.RESULTS, rawBatchData);
for (Map.Entry<String, T> entry : recordTemplates.entrySet()) {
rawBatchData.put(entry.getKey(), entry.getValue().data());
}
return new BatchResponse<T>(batchResponseDataMap, entryClass);
}
use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.
the class BatchGetResponseBuilder method toBatchResponse.
private static <K, V extends RecordTemplate> BatchResponse<AnyRecord> toBatchResponse(Map<K, EntityResponse<V>> entities, ProtocolVersion protocolVersion) {
final DataMap splitResponseData = new DataMap();
final DataMap splitResults = new DataMap();
final DataMap splitStatuses = new DataMap();
final DataMap splitErrors = new DataMap();
for (Map.Entry<K, EntityResponse<V>> resultEntry : entities.entrySet()) {
final DataMap entityResponseData = resultEntry.getValue().data();
final String stringKey = URIParamUtils.encodeKeyForBody(resultEntry.getKey(), false, protocolVersion);
final DataMap entityData = entityResponseData.getDataMap(EntityResponse.ENTITY);
if (entityData != null) {
CheckedUtil.putWithoutChecking(splitResults, stringKey, entityData);
}
final Integer status = entityResponseData.getInteger(EntityResponse.STATUS);
if (status != null) {
CheckedUtil.putWithoutChecking(splitStatuses, stringKey, status);
}
final DataMap error = entityResponseData.getDataMap(EntityResponse.ERROR);
if (error != null) {
CheckedUtil.putWithoutChecking(splitErrors, stringKey, error);
}
}
CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.RESULTS, splitResults);
CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.STATUSES, splitStatuses);
CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.ERRORS, splitErrors);
return new BatchResponse<AnyRecord>(splitResponseData, AnyRecord.class);
}
use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.
the class BatchUpdateResponseBuilder method toBatchResponse.
private static <K> BatchResponse<AnyRecord> toBatchResponse(Map<K, UpdateStatus> statuses, ProtocolVersion protocolVersion) {
final DataMap splitResponseData = new DataMap();
final DataMap splitStatuses = new DataMap();
final DataMap splitErrors = new DataMap();
for (Map.Entry<K, UpdateStatus> statusEntry : statuses.entrySet()) {
final DataMap statusData = statusEntry.getValue().data();
final String stringKey = URIParamUtils.encodeKeyForBody(statusEntry.getKey(), false, protocolVersion);
final DataMap error = statusData.getDataMap("error");
if (error == null) {
// status and error should be mutually exclusive for now
CheckedUtil.putWithoutChecking(splitStatuses, stringKey, statusData);
} else {
CheckedUtil.putWithoutChecking(splitErrors, stringKey, error);
}
}
CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.RESULTS, splitStatuses);
CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.ERRORS, splitErrors);
return new BatchResponse<AnyRecord>(splitResponseData, AnyRecord.class);
}
Aggregations