use of com.google.api.codegen.config.PageStreamingConfig in project toolkit by googleapis.
the class ApiCallableTransformer method generatePagedApiCallable.
private ApiCallableView generatePagedApiCallable(MethodContext context) {
MethodConfig methodConfig = context.getMethodConfig();
SurfaceNamer namer = context.getNamer();
MethodModel method = context.getMethodModel();
PageStreamingConfig pageStreaming = methodConfig.getPageStreaming();
ApiCallableView.Builder pagedApiCallableBuilder = ApiCallableView.newBuilder();
pagedApiCallableBuilder.type(ApiCallableImplType.PagedApiCallable);
pagedApiCallableBuilder.interfaceTypeName(namer.getApiCallableTypeName(ServiceMethodType.UnaryMethod));
String pagedResponseTypeName = namer.getAndSavePagedResponseTypeName(context, pageStreaming.getResourcesFieldConfig());
pagedApiCallableBuilder.requestTypeName(method.getAndSaveRequestTypeName(context.getTypeTable(), context.getNamer()));
pagedApiCallableBuilder.responseTypeName(pagedResponseTypeName);
pagedApiCallableBuilder.name(namer.getPagedCallableName(method));
pagedApiCallableBuilder.methodName(namer.getApiMethodName(method, context.getMethodConfig().getVisibility()));
pagedApiCallableBuilder.asyncMethodName(namer.getAsyncApiMethodName(method, VisibilityConfig.PUBLIC));
pagedApiCallableBuilder.memberName(namer.getSettingsMemberName(method));
pagedApiCallableBuilder.settingsFunctionName(namer.getSettingsFunctionName(method));
pagedApiCallableBuilder.grpcClientVarName(namer.getReroutedGrpcClientVarName(methodConfig));
setCommonApiCallableFields(context, pagedApiCallableBuilder);
return pagedApiCallableBuilder.build();
}
use of com.google.api.codegen.config.PageStreamingConfig in project toolkit by googleapis.
the class PageStreamingTransformer method generateDescriptor.
public PageStreamingDescriptorView generateDescriptor(InterfaceContext context, MethodModel method) {
MethodConfig methodConfig = context.getMethodConfig(method);
PageStreamingConfig pageStreaming = methodConfig.getPageStreaming();
PageStreamingDescriptorView.Builder descriptor = PageStreamingDescriptorView.newBuilder();
descriptor.varName(context.getNamer().getPageStreamingDescriptorName(method));
descriptor.requestTokenFieldName(context.getNamer().getRequestTokenFieldName(pageStreaming));
descriptor.requestTokenGetMethodName(context.getNamer().getFieldGetFunctionName(pageStreaming.getRequestTokenField()));
descriptor.requestTokenSetMethodName(context.getNamer().getFieldSetFunctionName(pageStreaming.getRequestTokenField()));
if (pageStreaming.hasPageSizeField()) {
descriptor.requestPageSizeFieldName(context.getNamer().getPageSizeFieldName(pageStreaming));
descriptor.requestPageSizeGetMethodName(context.getNamer().getFieldGetFunctionName(pageStreaming.getPageSizeField()));
descriptor.requestPageSizeSetMethodName(context.getNamer().getFieldSetFunctionName(pageStreaming.getPageSizeField()));
}
descriptor.responseTokenFieldName(context.getNamer().getResponseTokenFieldName(pageStreaming));
descriptor.responseTokenGetMethodName(context.getNamer().getFieldGetFunctionName(pageStreaming.getResponseTokenField()));
descriptor.resourcesFieldName(context.getNamer().getResourcesFieldName(pageStreaming));
descriptor.resourcesGetMethodName(context.getNamer().getFieldGetFunctionName(pageStreaming.getResourcesField()));
descriptor.methodName(context.getNamer().getMethodKey(method));
descriptor.transportMethodName(context.getNamer().getGrpcMethodName(method));
return descriptor.build();
}
use of com.google.api.codegen.config.PageStreamingConfig in project toolkit by googleapis.
the class PageStreamingTransformer method generateDescriptorClass.
private PageStreamingDescriptorClassView generateDescriptorClass(MethodContext context) {
SurfaceNamer namer = context.getNamer();
ImportTypeTable typeTable = context.getTypeTable();
MethodModel method = context.getMethodModel();
PageStreamingConfig pageStreaming = context.getMethodConfig().getPageStreaming();
PageStreamingDescriptorClassView.Builder desc = PageStreamingDescriptorClassView.newBuilder();
FieldModel resourceField = pageStreaming.getResourcesField();
FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
desc.name(namer.getPageStreamingDescriptorConstName(method));
desc.typeName(namer.getAndSavePagedResponseTypeName(context, resourceFieldConfig));
desc.requestTypeName(method.getAndSaveRequestTypeName(typeTable, namer));
desc.responseTypeName(method.getAndSaveResponseTypeName(typeTable, namer));
desc.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceField));
desc.tokenTypeName(typeTable.getAndSaveNicknameFor(pageStreaming.getResponseTokenField()));
desc.defaultTokenValue(typeTable.getSnippetZeroValueAndSaveNicknameFor(pageStreaming.getResponseTokenField()));
desc.requestTokenSetFunction(namer.getFieldSetFunctionName(pageStreaming.getRequestTokenField()));
if (pageStreaming.hasPageSizeField()) {
desc.requestPageSizeSetFunction(namer.getFieldSetFunctionName(pageStreaming.getPageSizeField()));
desc.requestPageSizeGetFunction(namer.getFieldGetFunctionName(pageStreaming.getPageSizeField()));
}
desc.responseTokenGetFunction(namer.getFieldGetFunctionName(pageStreaming.getResponseTokenField()));
ImmutableList.Builder<String> resourcesFieldGetFunctionList = new ImmutableList.Builder<>();
for (FieldModel field : resourceFieldConfig.getFieldPath()) {
resourcesFieldGetFunctionList.add(namer.getFieldGetFunctionName(field));
}
desc.resourcesFieldGetFunctions(resourcesFieldGetFunctionList.build());
return desc.build();
}
use of com.google.api.codegen.config.PageStreamingConfig in project toolkit by googleapis.
the class TestCaseTransformer method createMockResponseAdditionalSubTrees.
private Iterable<InitCodeNode> createMockResponseAdditionalSubTrees(MethodContext context) {
List<InitCodeNode> additionalSubTrees = new ArrayList<>();
if (context.getMethodConfig().isPageStreaming()) {
// Initialize one resource element if it is page-streaming.
PageStreamingConfig config = context.getMethodConfig().getPageStreaming();
if (config.getResourcesFieldConfig().getFieldPath().size() == 1) {
String resourceFieldName = config.getResourcesFieldName();
additionalSubTrees.add(InitCodeNode.createSingletonList(resourceFieldName));
} else {
// Initialize all the objects between the response type and the resource element.
List<FieldModel> fieldGetters = Lists.reverse(config.getResourcesFieldConfig().getFieldPath());
InitCodeNode initCodeNode = null;
for (FieldModel field : fieldGetters) {
if (config.getResourcesField().isRepeated()) {
initCodeNode = InitCodeNode.createSingletonList(config.getResourcesFieldName());
} else {
initCodeNode = InitCodeNode.create(config.getResourcesFieldName());
}
InitCodeLineType lineType = field.isRepeated() ? ListInitLine : StructureInitLine;
initCodeNode = InitCodeNode.createWithChildren(field.getSimpleName(), lineType, initCodeNode);
}
additionalSubTrees.add(initCodeNode);
}
// Set the initial value of the page token to empty, in order to indicate that no more pages
// are available
String responseTokenName = config.getResponseTokenField().getSimpleName();
additionalSubTrees.add(InitCodeNode.createWithValue(responseTokenName, InitValueConfig.createWithValue(InitValue.createLiteral(""))));
}
if (context.getMethodConfig().isBatching()) {
// Initialize one batching element if it is batching.
BatchingConfig config = context.getMethodConfig().getBatching();
if (config.getSubresponseField() != null) {
String subResponseFieldName = config.getSubresponseField().getSimpleName();
additionalSubTrees.add(InitCodeNode.createSingletonList(subResponseFieldName));
}
}
if (context.getMethodConfig().isGrpcStreaming()) {
GrpcStreamingConfig streamingConfig = context.getMethodConfig().getGrpcStreaming();
if (streamingConfig.hasResourceField()) {
String resourceFieldName = streamingConfig.getResourcesField().getSimpleName();
additionalSubTrees.add(InitCodeNode.createSingletonList(resourceFieldName));
}
}
return additionalSubTrees;
}
use of com.google.api.codegen.config.PageStreamingConfig in project toolkit by googleapis.
the class CSharpGapicSnippetsTransformer method generatePagedFlattenedAsyncMethod.
private StaticLangApiMethodSnippetView generatePagedFlattenedAsyncMethod(MethodContext methodContext, String suffix, boolean requiresNamedArguments) {
StaticLangApiMethodView method = apiMethodTransformer.generatePagedFlattenedAsyncMethod(methodContext, csharpCommonTransformer.pagedMethodAdditionalParams());
SurfaceNamer namer = methodContext.getNamer();
PageStreamingConfig pageStreaming = methodContext.getMethodConfig().getPageStreaming();
FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
String callerResponseTypeName = namer.getAndSaveCallerAsyncPagedResponseTypeName(methodContext, resourceFieldConfig);
return StaticLangApiMethodSnippetView.newBuilder().method(method).snippetMethodName(method.name() + suffix).callerResponseTypeName(callerResponseTypeName).apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())).apiVariableName(method.apiVariableName()).requiresNamedArguments(requiresNamedArguments).build();
}
Aggregations