Search in sources :

Example 11 with BatchCreateIdResponse

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();
}
Also used : UriBuilder(com.linkedin.jersey.api.uri.UriBuilder) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) ArrayList(java.util.ArrayList) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException)

Aggregations

BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)11 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)9 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)7 Test (org.testng.annotations.Test)6 GreetingsRequestBuilders (com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)4 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)3 ArrayList (java.util.ArrayList)3 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)2 HashSet (java.util.HashSet)2 UriBuilder (com.linkedin.jersey.api.uri.UriBuilder)1 BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)1 CollectionResponse (com.linkedin.restli.common.CollectionResponse)1 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1 CreateStatus (com.linkedin.restli.common.CreateStatus)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1 EntityResponse (com.linkedin.restli.common.EntityResponse)1 ErrorResponse (com.linkedin.restli.common.ErrorResponse)1 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)1 Message (com.linkedin.restli.examples.greetings.api.Message)1 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)1