Search in sources :

Example 1 with PageStreamingConfig

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();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) ApiCallableView(com.google.api.codegen.viewmodel.ApiCallableView) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig)

Example 2 with PageStreamingConfig

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();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) PageStreamingDescriptorView(com.google.api.codegen.viewmodel.PageStreamingDescriptorView)

Example 3 with PageStreamingConfig

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();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) FieldConfig(com.google.api.codegen.config.FieldConfig) ImmutableList(com.google.common.collect.ImmutableList) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) FieldModel(com.google.api.codegen.config.FieldModel) PageStreamingDescriptorClassView(com.google.api.codegen.viewmodel.PageStreamingDescriptorClassView)

Example 4 with PageStreamingConfig

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;
}
Also used : InitCodeNode(com.google.api.codegen.metacode.InitCodeNode) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) ArrayList(java.util.ArrayList) BatchingConfig(com.google.api.codegen.config.BatchingConfig) InitCodeLineType(com.google.api.codegen.metacode.InitCodeLineType) FieldModel(com.google.api.codegen.config.FieldModel) GrpcStreamingConfig(com.google.api.codegen.config.GrpcStreamingConfig)

Example 5 with PageStreamingConfig

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();
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) FieldConfig(com.google.api.codegen.config.FieldConfig) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)11 FieldConfig (com.google.api.codegen.config.FieldConfig)8 MethodModel (com.google.api.codegen.config.MethodModel)5 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)5 FieldModel (com.google.api.codegen.config.FieldModel)4 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)4 MethodConfig (com.google.api.codegen.config.MethodConfig)2 BatchingConfig (com.google.api.codegen.config.BatchingConfig)1 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)1 GrpcStreamingConfig (com.google.api.codegen.config.GrpcStreamingConfig)1 InitCodeLineType (com.google.api.codegen.metacode.InitCodeLineType)1 InitCodeNode (com.google.api.codegen.metacode.InitCodeNode)1 ApiCallableView (com.google.api.codegen.viewmodel.ApiCallableView)1 PageStreamingDescriptorClassView (com.google.api.codegen.viewmodel.PageStreamingDescriptorClassView)1 PageStreamingDescriptorView (com.google.api.codegen.viewmodel.PageStreamingDescriptorView)1 PagedListResponseFactoryClassView (com.google.api.codegen.viewmodel.PagedListResponseFactoryClassView)1 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)1 UnpagedListCallableMethodDetailView (com.google.api.codegen.viewmodel.UnpagedListCallableMethodDetailView)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1