Search in sources :

Example 1 with PageStreamingResponseView

use of com.google.api.codegen.viewmodel.testing.PageStreamingResponseView in project toolkit by googleapis.

the class TestCaseTransformer method createPageStreamingResponseViews.

private List<PageStreamingResponseView> createPageStreamingResponseViews(MethodContext methodContext) {
    MethodConfig methodConfig = methodContext.getMethodConfig();
    SurfaceNamer namer = methodContext.getNamer();
    List<PageStreamingResponseView> pageStreamingResponseViews = new ArrayList<>();
    if (!methodConfig.isPageStreaming()) {
        return pageStreamingResponseViews;
    }
    FieldConfig resourcesFieldConfig = methodConfig.getPageStreaming().getResourcesFieldConfig();
    FieldModel resourcesField = resourcesFieldConfig.getField();
    String resourceTypeName = methodContext.getTypeTable().getAndSaveNicknameForElementType(resourcesField);
    // Construct the list of function calls needed to retrieve paged resource from response object.
    ImmutableList.Builder<String> resourcesFieldGetFunctionList = new ImmutableList.Builder<>();
    for (FieldModel field : resourcesFieldConfig.getFieldPath()) {
        resourcesFieldGetFunctionList.add(namer.getFieldGetFunctionName(field));
    }
    pageStreamingResponseViews.add(PageStreamingResponseView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterNames(resourcesFieldGetFunctionList.build()).resourcesIterateMethod(namer.getPagedResponseIterateMethod()).resourcesVarName(namer.localVarName(Name.from("resources"))).build());
    if (methodContext.getFeatureConfig().useResourceNameFormatOption(resourcesFieldConfig)) {
        resourceTypeName = methodContext.getNamer().getAndSaveElementResourceTypeName(methodContext.getTypeTable(), resourcesFieldConfig);
        resourcesFieldGetFunctionList = new ImmutableList.Builder<>();
        for (FieldModel field : resourcesFieldConfig.getFieldPath()) {
            resourcesFieldGetFunctionList.add(namer.getFieldGetFunctionName(methodContext.getFeatureConfig(), resourcesFieldConfig));
        }
        String expectedTransformFunction = null;
        if (methodContext.getFeatureConfig().useResourceNameConverters(resourcesFieldConfig)) {
            expectedTransformFunction = namer.getResourceTypeParseMethodName(methodContext.getTypeTable(), resourcesFieldConfig);
        }
        pageStreamingResponseViews.add(PageStreamingResponseView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterNames(resourcesFieldGetFunctionList.build()).resourcesIterateMethod(namer.getPagedResponseIterateMethod(methodContext.getFeatureConfig(), resourcesFieldConfig)).expectedValueTransformFunction(expectedTransformFunction).resourcesVarName(namer.localVarName(Name.from("resource_names"))).build());
    }
    return pageStreamingResponseViews;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) InitFieldConfig(com.google.api.codegen.metacode.InitFieldConfig) FieldConfig(com.google.api.codegen.config.FieldConfig) ImmutableList(com.google.common.collect.ImmutableList) PageStreamingResponseView(com.google.api.codegen.viewmodel.testing.PageStreamingResponseView) ArrayList(java.util.ArrayList) FieldModel(com.google.api.codegen.config.FieldModel)

Aggregations

FieldConfig (com.google.api.codegen.config.FieldConfig)1 FieldModel (com.google.api.codegen.config.FieldModel)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 InitFieldConfig (com.google.api.codegen.metacode.InitFieldConfig)1 PageStreamingResponseView (com.google.api.codegen.viewmodel.testing.PageStreamingResponseView)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1