use of com.linkedin.restli.common.ResourceSpec in project rest.li by linkedin.
the class BatchGetEntityRequestBuilder method batch.
/**
* Batches multiple requests into a single batch request.
*
* Requirements:
* <ul>
* <li>Base URIs of all requests must be the same</li>
* <li>if {@code batchFields} is {@code false}, then all requests must have the same projection</li>
* </ul>
*
* Batching is performed along one or two dimensions:
* <ol>
* <li>entity ids are always accumulated</li>
* <li>if {@code batchFields} is {@code true}, fields are also accumulated. If any of the batched requests has a
* null projection, then the resulting batch request will also have a null projection.</li>
* </ol>
*
*
*
* @param requests to batch
* @param batchFields whether field batching is desired
* @param <V> type of entity template
* @return batching request
*/
public static <K, V extends RecordTemplate> BatchGetEntityRequest<K, V> batch(List<BatchGetEntityRequest<K, V>> requests, boolean batchFields) {
final BatchGetEntityRequest<K, V> firstRequest = requests.get(0);
@SuppressWarnings("deprecation") final ResourceSpec firstResourceSpec = firstRequest.getResourceSpec();
final Map<String, Object> batchQueryParams = getReadOnlyQueryParameters(BatchGetRequestUtil.getBatchQueryParam(requests, batchFields));
return new BatchGetEntityRequest<K, V>(firstRequest.getHeaders(), firstRequest.getCookies(), firstRequest.getResponseDecoder(), batchQueryParams, firstRequest.getQueryParamClasses(), firstResourceSpec, firstRequest.getBaseUriTemplate(), firstRequest.getPathKeys(), firstRequest.getRequestOptions());
}
use of com.linkedin.restli.common.ResourceSpec in project rest.li by linkedin.
the class BatchGetRequestBuilder method batchKV.
/**
* Batches multiple requests into a single batch request.
*
* Requirements:
* <ul>
* <li>Base URIs of all requests must be the same</li>
* <li>if {@code batchFields} is {@code false}, then all requests must have the same projection</li>
* </ul>
*
* Batching is performed along one or two dimensions:
* <ol>
* <li>entity ids are always accumulated</li>
* <li>if {@code batchFields} is {@code true}, fields are also accumulated. If any of the batched requests has a
* null projection, then the resulting batch request will also have a null projection.</li>
* </ol>
*
*
*
* @param requests to batch
* @param batchFields whether field batching is desired
* @param <K> type of the key
* @param <RT> type of entity template
* @return batching request
*/
@SuppressWarnings("deprecation")
public static <K, RT extends RecordTemplate> BatchGetKVRequest<K, RT> batchKV(List<BatchGetKVRequest<K, RT>> requests, boolean batchFields) {
final BatchGetKVRequest<K, RT> firstRequest = requests.get(0);
final ResourceSpec firstResourceSpec = firstRequest.getResourceSpec();
final Map<String, Object> batchQueryParams = getReadOnlyQueryParameters(BatchGetRequestUtil.getBatchQueryParam(requests, batchFields));
return new BatchGetKVRequest<K, RT>(getReadOnlyHeaders(firstRequest.getHeaders()), getReadOnlyCookies(firstRequest.getCookies()), firstRequest.getResponseDecoder(), batchQueryParams, Collections.<String, Class<?>>emptyMap(), firstResourceSpec, firstRequest.getBaseUriTemplate(), getReadOnlyPathKeys(firstRequest.getPathKeys()), firstRequest.getRequestOptions());
}
use of com.linkedin.restli.common.ResourceSpec in project rest.li by linkedin.
the class BatchGetRequestBuilder method batch.
/**
* Batches multiple requests into a single batch request.
*
* Requirements:
* <ul>
* <li>Base URIs of all requests must be the same</li>
* <li>if {@code batchFields} is {@code false}, then all requests must have the same projection</li>
* </ul>
*
* Batching is performed along one or two dimensions:
* <ol>
* <li>entity ids are always accumulated</li>
* <li>if {@code batchFields} is {@code true}, fields are also accumulated. If any of the batched requests has a
* null projection, then the resulting batch request will also have a null projection.</li>
* </ol>
*
*
*
* @param requests to batch
* @param batchFields whether field batching is desired
* @param <RT> type of entity template
* @return batching request
*/
@SuppressWarnings("deprecation")
public static <RT extends RecordTemplate> BatchGetRequest<RT> batch(List<BatchGetRequest<RT>> requests, boolean batchFields) {
final BatchGetRequest<RT> firstRequest = requests.get(0);
Class<?> keyClass = firstRequest.getResourceSpec().getKeyClass();
throwIfClassCompoundOrComplex(keyClass, "batch", "batchKV");
final ResourceSpec firstResourceSpec = firstRequest.getResourceSpec();
final Map<String, Object> batchQueryParams = getReadOnlyQueryParameters(BatchGetRequestUtil.getBatchQueryParam(requests, batchFields));
return new BatchGetRequest<RT>(getReadOnlyHeaders(firstRequest.getHeaders()), getReadOnlyCookies(firstRequest.getCookies()), firstRequest.getResponseDecoder(), batchQueryParams, firstRequest.getQueryParamClasses(), firstResourceSpec, firstRequest.getBaseUriTemplate(), getReadOnlyPathKeys(firstRequest.getPathKeys()), firstRequest.getRequestOptions());
}
use of com.linkedin.restli.common.ResourceSpec in project rest.li by linkedin.
the class TestClientBuilders method testBuilderPathKeys1.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "subSubResourceAction1")
public void testBuilderPathKeys1(URIDetails expectedURIDetails) {
List<FieldDef<?>> fieldDefs = new ArrayList<FieldDef<?>>();
fieldDefs.add(new FieldDef<Integer>("key1", Integer.class, DataTemplateUtil.getSchema(Integer.class)));
fieldDefs.add(new FieldDef<Integer>("key2", Integer.class, DataTemplateUtil.getSchema(Integer.class)));
DynamicRecordMetadata requestMetadata = new DynamicRecordMetadata("action", fieldDefs);
Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<String, DynamicRecordMetadata>();
requestMetadataMap.put("action", requestMetadata);
DynamicRecordMetadata responseMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>emptyList());
Map<String, DynamicRecordMetadata> responseMetadataMap = new HashMap<String, DynamicRecordMetadata>();
responseMetadataMap.put("action", responseMetadata);
ResourceSpec resourceSpec = getResourceSpecForBuilderPathKeys();
Map<String, Integer> expectedPathKeys = new HashMap<String, Integer>();
expectedPathKeys.put("key1", 1);
expectedPathKeys.put("key2", 2);
Request<TestRecord> request = new ActionRequestBuilder<Void, TestRecord>(SUBRESOURCE_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS).name("action").pathKey("key1", 1).pathKey("key2", 2).build();
URIDetails.testUriGeneration(request, expectedURIDetails);
testPathKeys(request, SUBRESOURCE_URI, expectedPathKeys);
}
use of com.linkedin.restli.common.ResourceSpec in project rest.li by linkedin.
the class TestClientBuilders method testActionRequestNullOptionalParams.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "action")
public void testActionRequestNullOptionalParams(URIDetails expectedURIDetails) {
FieldDef<String> pParam = new FieldDef<String>("p", String.class, DataTemplateUtil.getSchema(String.class));
Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<String, DynamicRecordMetadata>();
DynamicRecordMetadata requestMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>singleton(pParam));
requestMetadataMap.put("action", requestMetadata);
DynamicRecordMetadata responseMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>emptyList());
Map<String, DynamicRecordMetadata> responseMetadataMap = new HashMap<String, DynamicRecordMetadata>();
responseMetadataMap.put("action", responseMetadata);
ResourceSpec resourceSpec = new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), requestMetadataMap, responseMetadataMap, Long.class, TestRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap());
ActionRequestBuilder<Long, TestRecord> builder = new ActionRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
pParam.getField().setOptional(true);
ActionRequest<TestRecord> requestNullOptionalValue = builder.name("action").setParam(pParam, null).id(2L).build();
Assert.assertEquals(requestNullOptionalValue.getMethod(), ResourceMethod.ACTION);
Assert.assertEquals(requestNullOptionalValue.getHeaders(), Collections.<String, String>emptyMap());
Assert.assertEquals(requestNullOptionalValue.isSafe(), false);
Assert.assertEquals(requestNullOptionalValue.isIdempotent(), false);
Assert.assertEquals(requestNullOptionalValue.getResponseDecoder().getEntityClass(), Void.class);
}
Aggregations