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)));
}
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));
}
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);
}
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);
}
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);
}
Aggregations