use of com.linkedin.restli.common.BatchCreateIdResponse in project rest.li by linkedin.
the class BatchCreateResponseBuilder method buildResponse.
@Override
@SuppressWarnings("unchecked")
public PartialRestResponse buildResponse(RoutingResult routingResult, RestLiResponseData responseData) {
List<BatchCreateResponseEnvelope.CollectionCreateResponseItem> collectionCreateResponses = responseData.getBatchCreateResponseEnvelope().getCreateResponses();
List<CreateIdStatus<Object>> formattedResponses = new ArrayList<CreateIdStatus<Object>>(collectionCreateResponses.size());
// Otherwise, add the result as is.
for (BatchCreateResponseEnvelope.CollectionCreateResponseItem response : collectionCreateResponses) {
if (response.isErrorResponse()) {
RestLiServiceException exception = response.getException();
formattedResponses.add(new CreateIdStatus<Object>(exception.getStatus().getCode(), response.getId(), _errorResponseBuilder.buildErrorResponse(exception), ProtocolVersionUtil.extractProtocolVersion(responseData.getHeaders())));
} else {
formattedResponses.add((CreateIdStatus<Object>) response.getRecord());
}
}
PartialRestResponse.Builder builder = new PartialRestResponse.Builder();
BatchCreateIdResponse<Object> batchCreateIdResponse = new BatchCreateIdResponse<Object>(formattedResponses);
return builder.headers(responseData.getHeaders()).cookies(responseData.getCookies()).entity(batchCreateIdResponse).build();
}
use of com.linkedin.restli.common.BatchCreateIdResponse in project rest.li by linkedin.
the class TestScatterGather method prepareData.
private static Long[] prepareData(List<Greeting> entities, RestliRequestOptions requestOptions) throws RemoteInvocationException {
GreetingsRequestBuilders builders = new GreetingsRequestBuilders(requestOptions);
BatchCreateIdRequest<Long, Greeting> request = builders.batchCreate().inputs(entities).build();
Response<BatchCreateIdResponse<Long>> response = REST_CLIENT.sendRequest(request).getResponse();
List<CreateIdStatus<Long>> statuses = response.getEntity().getElements();
final Long[] requestIds = new Long[entities.size()];
for (int i = 0; i < statuses.size(); ++i) {
CreateIdStatus<Long> status = statuses.get(i);
Assert.assertFalse(status.hasError());
requestIds[i] = status.getKey();
}
return requestIds;
}
use of com.linkedin.restli.common.BatchCreateIdResponse in project rest.li by linkedin.
the class TestRestLiScatterGather method prepareData.
private static Long[] prepareData(RestClient restClient, List<Greeting> entities) throws RemoteInvocationException {
GreetingsRequestBuilders builders = new GreetingsRequestBuilders();
BatchCreateIdRequest<Long, Greeting> request = builders.batchCreate().inputs(entities).build();
Response<BatchCreateIdResponse<Long>> response = restClient.sendRequest(request).getResponse();
List<CreateIdStatus<Long>> statuses = response.getEntity().getElements();
final Long[] requestIds = new Long[entities.size()];
for (int i = 0; i < statuses.size(); ++i) {
CreateIdStatus<Long> status = statuses.get(i);
Assert.assertFalse(status.hasError());
requestIds[i] = status.getKey();
}
return requestIds;
}
use of com.linkedin.restli.common.BatchCreateIdResponse in project rest.li by linkedin.
the class TestCompressionServer method testNewCookbookInBatch.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsCookbookDataProvider")
public void testNewCookbookInBatch(RestClient client, RestliRequestOptions requestOptions) throws Exception {
final GreetingsRequestBuilders builders = new GreetingsRequestBuilders(requestOptions);
// GET
Greeting greetingResult = getNewCookbookBatchGetResult(client, requestOptions);
// POST
Greeting greeting = new Greeting(greetingResult.data().copy());
greeting.setMessage("This is a new message!");
Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(1L, greeting).build();
client.sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
getNewCookbookBatchGetResult(client, requestOptions);
// batch Create
Greeting repeatedGreeting = new Greeting();
repeatedGreeting.setMessage("Hello Hello");
repeatedGreeting.setTone(Tone.SINCERE);
List<Greeting> entities = Arrays.asList(repeatedGreeting, repeatedGreeting);
Request<BatchCreateIdResponse<Long>> batchCreateRequest = builders.batchCreate().inputs(entities).build();
List<CreateIdStatus<Long>> statuses = client.sendRequest(batchCreateRequest).getResponse().getEntity().getElements();
for (CreateIdStatus<Long> status : statuses) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
@SuppressWarnings("deprecation") String id = status.getId();
Assert.assertEquals(status.getKey().longValue(), Long.parseLong(id));
Assert.assertNotNull(status.getKey());
}
}
use of com.linkedin.restli.common.BatchCreateIdResponse in project rest.li by linkedin.
the class TestReturnEntityWithCreate method testBatchCreateId.
/**
* Test for backward compatibility of batch create id request.
* @param restClient
* @param expectedContentType
* @param builders
* @throws RemoteInvocationException
*/
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
public void testBatchCreateId(RestClient restClient, String expectedContentType, CreateGreetingRequestBuilders builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("first time!");
greeting.setTone(Tone.FRIENDLY);
BatchCreateIdRequest<Long, Greeting> batchCreateIdRequest = builders.batchCreate().inputs(Arrays.asList(greeting, greeting)).build();
Response<BatchCreateIdResponse<Long>> response = restClient.sendRequest(batchCreateIdRequest).getResponse();
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType);
List<CreateIdStatus<Long>> elems = response.getEntity().getElements();
Assert.assertEquals(elems.get(0).getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
Assert.assertEquals(elems.get(0).getLocation(), "/" + builders.getPrimaryResource() + "/" + elems.get(0).getKey());
Assert.assertEquals(elems.get(1).getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
Assert.assertEquals(elems.get(1).getLocation(), "/" + builders.getPrimaryResource() + "/" + elems.get(1).getKey());
}
Aggregations