Search in sources :

Example 11 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class BatchGetRequestBuilderTest method testBatchingWithNullProjectionLast.

@Test
public void testBatchingWithNullProjectionLast() {
    BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder1 = new BatchGetRequestBuilder<>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Integer.class, null, null, null, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
    batchRequestBuilder1.ids(1);
    batchRequestBuilder1.fields(FIELDS.message());
    BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder2 = new BatchGetRequestBuilder<>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Integer.class, null, null, null, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
    batchRequestBuilder2.ids(2, 3);
    BatchGetRequest<TestRecord> batchRequest1 = batchRequestBuilder1.build();
    @SuppressWarnings("unchecked") BatchGetRequest<TestRecord> batchingRequest = BatchGetRequestBuilder.batch(Arrays.asList(batchRequest1, batchRequestBuilder2.build()));
    Assert.assertEquals(batchingRequest.getBaseUriTemplate(), batchRequest1.getBaseUriTemplate());
    Assert.assertEquals(batchingRequest.getPathKeys(), batchRequest1.getPathKeys());
    Assert.assertEquals(batchingRequest.getFields(), Collections.emptySet());
    Assert.assertEquals(batchingRequest.getObjectIds(), new HashSet<>(Arrays.asList(1, 2, 3)));
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Example 12 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class ResourceSchemaToResourceSpecTranslator method toActionMetadata.

// this is dynamic, don't have concrete classes for the FieldDef
@SuppressWarnings({ "unchecked", "rawtypes" })
private ActionMetadata toActionMetadata(ActionSchema action) {
    ArrayList<FieldDef<?>> fieldDefs = new ArrayList<>();
    if (action.hasParameters()) {
        for (ParameterSchema parameterSchema : action.getParameters()) {
            DataSchema dataSchema = RestSpecCodec.textToSchema(parameterSchema.getType(), _schemaResolver);
            Class<?> paramClass = toType(dataSchema);
            FieldDef<?> fieldDef = new FieldDef(parameterSchema.getName(), paramClass, dataSchema);
            fieldDefs.add(fieldDef);
        }
    }
    Collection<FieldDef<?>> response;
    if (action.hasReturns()) {
        DataSchema returnType = RestSpecCodec.textToSchema(action.getReturns(), _schemaResolver);
        Class<?> returnClass = toType(returnType);
        response = Collections.<FieldDef<?>>singletonList(new FieldDef("value", returnClass, returnType));
    } else {
        response = Collections.emptyList();
    }
    return new ActionMetadata(action.getName(), new DynamicRecordMetadata(action.getName(), fieldDefs), new DynamicRecordMetadata(action.getName(), response));
}
Also used : DataSchema(com.linkedin.data.schema.DataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) FieldDef(com.linkedin.data.template.FieldDef) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ArrayList(java.util.ArrayList) ParameterSchema(com.linkedin.restli.restspec.ParameterSchema)

Example 13 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class ResourceSchemaToResourceSpecTranslator method buildResourceSpec.

private ResourceSpec buildResourceSpec(StringArray supports, TypeSpec<?> key, ComplexKeySpec<?, ?> complexKeyType, Map<String, ?> keyParts, String entitySchemaString, ActionSchemaArray actions, ActionSchemaArray entityActions) {
    Set<ResourceMethod> supportedMethods = toResourceMethods(supports);
    ActionCollectionMetadata actionCollectionMetadata = toDynamicRecordMetadata(actions, entityActions);
    Map<String, DynamicRecordMetadata> actionRequestMetadata = actionCollectionMetadata._request;
    Map<String, DynamicRecordMetadata> actionResponseMetadata = actionCollectionMetadata._response;
    DataSchema entitySchema = entitySchemaString == null ? null : RestSpecCodec.textToSchema(entitySchemaString, _schemaResolver);
    TypeSpec<? extends RecordTemplate> value = toValueType(entitySchema);
    return new ResourceSpecImpl(supportedMethods, actionRequestMetadata, actionResponseMetadata, key, complexKeyType, value, keyParts);
}
Also used : DataSchema(com.linkedin.data.schema.DataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Example 14 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class TestClientBuilders method testActionRequestInputIsReadOnly.

@Test
@SuppressWarnings("unchecked")
public void testActionRequestInputIsReadOnly() {
    FieldDef<TestRecord> pParam = new FieldDef<>("p", TestRecord.class, DataTemplateUtil.getSchema(TestRecord.class));
    Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<>();
    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<>();
    responseMetadataMap.put("action", responseMetadata);
    ResourceSpec resourceSpec = new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), requestMetadataMap, responseMetadataMap, ComplexResourceKey.class, TestRecord.class, TestRecord.class, TestRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap());
    ActionRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new ActionRequestBuilder<>(TEST_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
    TestRecord testRecord1 = new TestRecord();
    TestRecord testRecord2 = new TestRecord();
    ComplexResourceKey<TestRecord, TestRecord> key = new ComplexResourceKey<>(testRecord1, testRecord2);
    ActionRequest<TestRecord> request = builder.name("action").setParam(pParam, testRecord1).id(key).build();
    DynamicRecordTemplate inputParams = (DynamicRecordTemplate) request.getInputRecord();
    Assert.assertNotSame(inputParams.getValue(pParam).data(), testRecord1.data());
    Assert.assertTrue(inputParams.data().isReadOnly());
    Assert.assertTrue(inputParams.getValue(pParam).data().isMadeReadOnly());
    Assert.assertNotSame(request.getId(), key);
    Assert.assertTrue(((ComplexResourceKey<TestRecord, TestRecord>) request.getId()).isReadOnly());
    testRecord1.data().makeReadOnly();
    testRecord2.data().makeReadOnly();
    request = builder.build();
    inputParams = (DynamicRecordTemplate) request.getInputRecord();
    Assert.assertSame(inputParams.getValue(pParam).data(), testRecord1.data());
    Assert.assertTrue(inputParams.data().isReadOnly());
    Assert.assertSame(request.getId(), key);
}
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) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) Test(org.testng.annotations.Test)

Example 15 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class TestClientBuilders method getResourceSpecForBuilderPathKeys.

private ResourceSpec getResourceSpecForBuilderPathKeys() {
    List<FieldDef<?>> fieldDefs = new ArrayList<>();
    fieldDefs.add(new FieldDef<>("key1", Integer.class, DataTemplateUtil.getSchema(Integer.class)));
    fieldDefs.add(new FieldDef<>("key2", Integer.class, DataTemplateUtil.getSchema(Integer.class)));
    DynamicRecordMetadata requestMetadata = new DynamicRecordMetadata("action", fieldDefs);
    Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<>();
    requestMetadataMap.put("action", requestMetadata);
    DynamicRecordMetadata responseMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>emptyList());
    Map<String, DynamicRecordMetadata> responseMetadataMap = new HashMap<>();
    responseMetadataMap.put("action", responseMetadata);
    return new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), requestMetadataMap, responseMetadataMap);
}
Also used : FieldDef(com.linkedin.data.template.FieldDef) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ByteString(com.linkedin.data.ByteString) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl)

Aggregations

DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)21 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)14 TestRecord (com.linkedin.restli.client.test.TestRecord)13 Test (org.testng.annotations.Test)13 ResourceMethod (com.linkedin.restli.common.ResourceMethod)10 FieldDef (com.linkedin.data.template.FieldDef)6 HashMap (java.util.HashMap)6 ByteString (com.linkedin.data.ByteString)5 ResourceSpec (com.linkedin.restli.common.ResourceSpec)4 CompoundKey (com.linkedin.restli.common.CompoundKey)3 ActionSchema (com.linkedin.restli.restspec.ActionSchema)3 ArrayList (java.util.ArrayList)3 DataSchema (com.linkedin.data.schema.DataSchema)2 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)2 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)2 DynamicRecordTemplate (com.linkedin.data.template.DynamicRecordTemplate)2 ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)2 DataMap (com.linkedin.data.DataMap)1 ActionRequestBuilder (com.linkedin.restli.client.ActionRequestBuilder)1 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1