use of com.linkedin.restli.common.BatchCreateIdResponse in project rest.li by linkedin.
the class BatchCreateResponseBuilder method buildResponse.
@Override
@SuppressWarnings("unchecked")
public RestLiResponse buildResponse(RoutingResult routingResult, RestLiResponseData<BatchCreateResponseEnvelope> responseData) {
List<BatchCreateResponseEnvelope.CollectionCreateResponseItem> collectionCreateResponses = responseData.getResponseEnvelope().getCreateResponses();
List<CreateIdStatus<Object>> formattedResponses = new ArrayList<>(collectionCreateResponses.size());
// Otherwise, add the result as is.
for (BatchCreateResponseEnvelope.CollectionCreateResponseItem response : collectionCreateResponses) {
if (response.isErrorResponse()) {
RestLiServiceException exception = response.getException();
formattedResponses.add(new CreateIdStatus<>(exception.getStatus().getCode(), response.getId(), _errorResponseBuilder.buildErrorResponse(exception), ProtocolVersionUtil.extractProtocolVersion(responseData.getHeaders())));
} else {
formattedResponses.add((CreateIdStatus<Object>) response.getRecord());
}
}
RestLiResponse.Builder builder = new RestLiResponse.Builder();
BatchCreateIdResponse<Object> batchCreateIdResponse = new BatchCreateIdResponse<>(formattedResponses);
return builder.headers(responseData.getHeaders()).cookies(responseData.getCookies()).entity(batchCreateIdResponse).build();
}
Aggregations