Search in sources :

Example 1 with ResourceSpec

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());
}
Also used : ResourceSpec(com.linkedin.restli.common.ResourceSpec)

Example 2 with ResourceSpec

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());
}
Also used : ResourceSpec(com.linkedin.restli.common.ResourceSpec)

Example 3 with ResourceSpec

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());
}
Also used : ResourceSpec(com.linkedin.restli.common.ResourceSpec)

Example 4 with ResourceSpec

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ByteString(com.linkedin.data.ByteString) FieldDef(com.linkedin.data.template.FieldDef) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 5 with ResourceSpec

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);
}
Also used : HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ByteString(com.linkedin.data.ByteString) FieldDef(com.linkedin.data.template.FieldDef) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Aggregations

ResourceSpec (com.linkedin.restli.common.ResourceSpec)21 Test (org.testng.annotations.Test)15 TestRecord (com.linkedin.restli.client.test.TestRecord)14 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)9 HashMap (java.util.HashMap)7 ByteString (com.linkedin.data.ByteString)5 CompoundKey (com.linkedin.restli.common.CompoundKey)5 ResourceMethod (com.linkedin.restli.common.ResourceMethod)5 DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)4 FieldDef (com.linkedin.data.template.FieldDef)4 DataMap (com.linkedin.data.DataMap)2 DynamicRecordTemplate (com.linkedin.data.template.DynamicRecordTemplate)2 ResourcePropertiesImpl (com.linkedin.restli.internal.common.ResourcePropertiesImpl)2 CollectionRequest (com.linkedin.restli.common.CollectionRequest)1 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1 ResourceProperties (com.linkedin.restli.common.ResourceProperties)1 RichResourceSchema (com.linkedin.restli.common.util.RichResourceSchema)1 RestLiTestAttachmentDataSource (com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource)1 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)1