Search in sources :

Example 6 with BatchEntityResponse

use of com.linkedin.restli.internal.client.response.BatchEntityResponse in project rest.li by linkedin.

the class MockBatchEntityResponseFactory method createWithComplexKey.

/**
 * Create a {@link BatchKVResponse} where the key is a {@link ComplexResourceKey}
 *
 * @param valueClass the value class
 * @param keyKeyClass the class of the key part of the {@link ComplexResourceKey}
 * @param keyParamsClass the class of the params part of the {@link ComplexResourceKey}
 * @param recordTemplates the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getResults()}
 *                        NOTE: the params part of the {@link ComplexResourceKey} is removed in this map. A new
 *                        instance of the params class is created with no data in it.
 * @param statuses The HTTP status codes that will be returned as part of {@link EntityResponse}s
 *                 returned in {@link com.linkedin.restli.client.response.BatchKVResponse#getResults()}
 * @param errorResponses the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getErrors()}
 *                       NOTE: the params part of the {@link ComplexResourceKey} is removed in this map. A new
 *                       instance of the params class is created with no data in it.
 * @param <V>
 */
@SuppressWarnings("rawtypes")
public static <KK extends RecordTemplate, KP extends RecordTemplate, V extends RecordTemplate> BatchKVResponse<ComplexResourceKey<KK, KP>, EntityResponse<V>> createWithComplexKey(Class<V> valueClass, Class<KK> keyKeyClass, Class<KP> keyParamsClass, Map<ComplexResourceKey<KK, KP>, V> recordTemplates, Map<ComplexResourceKey<KK, KP>, HttpStatus> statuses, Map<ComplexResourceKey<KK, KP>, ErrorResponse> errorResponses) {
    ProtocolVersion version = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;
    DataMap batchResponseDataMap = buildDataMap(recordTemplates, statuses, errorResponses, version);
    @SuppressWarnings("unchecked") BatchKVResponse<ComplexResourceKey<KK, KP>, EntityResponse<V>> response = (BatchKVResponse<ComplexResourceKey<KK, KP>, EntityResponse<V>>) (Object) new BatchEntityResponse<>(batchResponseDataMap, new TypeSpec<>(ComplexResourceKey.class), TypeSpec.forClassMaybeNull(valueClass), null, ComplexKeySpec.forClassesMaybeNull(keyKeyClass, keyParamsClass), version);
    return response;
}
Also used : BatchEntityResponse(com.linkedin.restli.internal.client.response.BatchEntityResponse) BatchEntityResponse(com.linkedin.restli.internal.client.response.BatchEntityResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) DataMap(com.linkedin.data.DataMap)

Aggregations

DataMap (com.linkedin.data.DataMap)6 BatchEntityResponse (com.linkedin.restli.internal.client.response.BatchEntityResponse)6 EntityResponse (com.linkedin.restli.common.EntityResponse)3 ProtocolVersion (com.linkedin.restli.common.ProtocolVersion)3 HashSet (java.util.HashSet)3 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)2 ErrorResponse (com.linkedin.restli.common.ErrorResponse)2 ResponseImpl (com.linkedin.restli.internal.client.ResponseImpl)2 Callback (com.linkedin.common.callback.Callback)1 PathSpec (com.linkedin.data.schema.PathSpec)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1 Batch (com.linkedin.parseq.batching.Batch)1 BatchEntry (com.linkedin.parseq.batching.BatchImpl.BatchEntry)1 Tuple3 (com.linkedin.parseq.function.Tuple3)1 Tuples (com.linkedin.parseq.function.Tuples)1 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)1 RequestContext (com.linkedin.r2.message.RequestContext)1 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)1 TestRecord (com.linkedin.restli.client.test.TestRecord)1 BatchResponse (com.linkedin.restli.common.BatchResponse)1