Search in sources :

Example 1 with GrpcStreamingConfig

use of com.google.api.codegen.config.GrpcStreamingConfig 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 2 with GrpcStreamingConfig

use of com.google.api.codegen.config.GrpcStreamingConfig in project toolkit by googleapis.

the class NodeJSGapicSurfaceTransformer method createGrpcStreamingDescriptors.

private List<GrpcStreamingDetailView> createGrpcStreamingDescriptors(GapicInterfaceContext context) {
    List<GrpcStreamingDetailView> result = new ArrayList<>();
    for (MethodModel method : context.getGrpcStreamingMethods()) {
        GrpcStreamingConfig grpcStreamingConfig = context.asDynamicMethodContext(method).getMethodConfig().getGrpcStreaming();
        String resourcesFieldGetFunction = null;
        if (grpcStreamingConfig.hasResourceField()) {
            resourcesFieldGetFunction = context.getNamer().getFieldGetFunctionName(grpcStreamingConfig.getResourcesField());
        }
        result.add(GrpcStreamingDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).grpcStreamingType(grpcStreamingConfig.getType()).grpcResourcesField(resourcesFieldGetFunction).streamTypeName(context.getNamer().getStreamTypeName(grpcStreamingConfig.getType())).build());
    }
    return result;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ArrayList(java.util.ArrayList) GrpcStreamingDetailView(com.google.api.codegen.viewmodel.GrpcStreamingDetailView) GrpcStreamingConfig(com.google.api.codegen.config.GrpcStreamingConfig)

Example 3 with GrpcStreamingConfig

use of com.google.api.codegen.config.GrpcStreamingConfig in project toolkit by googleapis.

the class PhpGapicSurfaceTransformer method createGrpcStreamingDescriptors.

private List<GrpcStreamingDetailView> createGrpcStreamingDescriptors(GapicInterfaceContext context) {
    List<GrpcStreamingDetailView> result = new ArrayList<>();
    for (MethodModel method : context.getGrpcStreamingMethods()) {
        GrpcStreamingConfig grpcStreamingConfig = context.asDynamicMethodContext(method).getMethodConfig().getGrpcStreaming();
        String resourcesFieldGetFunction = null;
        if (grpcStreamingConfig.hasResourceField()) {
            resourcesFieldGetFunction = context.getNamer().getFieldGetFunctionName(grpcStreamingConfig.getResourcesField());
        }
        result.add(GrpcStreamingDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).transportMethodName(context.getNamer().getGrpcMethodName(method)).grpcStreamingType(grpcStreamingConfig.getType()).grpcResourcesField(resourcesFieldGetFunction).build());
    }
    return result;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ArrayList(java.util.ArrayList) GrpcStreamingDetailView(com.google.api.codegen.viewmodel.GrpcStreamingDetailView) GrpcStreamingConfig(com.google.api.codegen.config.GrpcStreamingConfig)

Aggregations

GrpcStreamingConfig (com.google.api.codegen.config.GrpcStreamingConfig)3 ArrayList (java.util.ArrayList)3 MethodModel (com.google.api.codegen.config.MethodModel)2 GrpcStreamingDetailView (com.google.api.codegen.viewmodel.GrpcStreamingDetailView)2 BatchingConfig (com.google.api.codegen.config.BatchingConfig)1 FieldModel (com.google.api.codegen.config.FieldModel)1 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)1 InitCodeLineType (com.google.api.codegen.metacode.InitCodeLineType)1 InitCodeNode (com.google.api.codegen.metacode.InitCodeNode)1