Search in sources :

Example 1 with ApiCallSettingsView

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

the class ApiCallableTransformer method generateApiCallableSettings.

public List<ApiCallSettingsView> generateApiCallableSettings(MethodContext context) {
    List<ApiCallSettingsView> settings = new ArrayList<>();
    MethodConfig methodConfig = context.getMethodConfig();
    if (methodConfig.isGrpcStreaming()) {
        settings.add(generateApiCallableSettings(context, ApiCallableImplType.of(methodConfig.getGrpcStreamingType())));
    } else if (methodConfig.isPageStreaming()) {
        settings.add(generateApiCallableSettings(context, ApiCallableImplType.PagedApiCallable));
    } else if (methodConfig.isBatching()) {
        settings.add(generateApiCallableSettings(context, ApiCallableImplType.BatchingApiCallable));
    } else if (methodConfig.isLongRunningOperation()) {
        if (context.getFeatureConfig().enableRawOperationCallSettings()) {
            settings.add(generateApiCallableSettings(context, ApiCallableImplType.SimpleApiCallable));
        }
        settings.add(generateApiCallableSettings(context, ApiCallableImplType.OperationApiCallable));
    } else {
        settings.add(generateApiCallableSettings(context, ApiCallableImplType.SimpleApiCallable));
    }
    return settings;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) ArrayList(java.util.ArrayList) ApiCallSettingsView(com.google.api.codegen.viewmodel.ApiCallSettingsView)

Example 2 with ApiCallSettingsView

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

the class JavaSurfaceTransformer method generateStubSettingsClass.

private StaticLangStubSettingsView generateStubSettingsClass(InterfaceContext context, GapicProductConfig productConfig, StaticLangApiMethodView exampleApiMethod) {
    addSettingsImports(context);
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    ApiModel model = context.getApiModel();
    StaticLangStubSettingsView.Builder xsettingsClass = StaticLangStubSettingsView.newBuilder();
    xsettingsClass.releaseLevelAnnotation(context.getNamer().getReleaseAnnotation(packageMetadataConfig.releaseLevel(TargetLanguage.JAVA)));
    xsettingsClass.doc(generateSettingsDoc(context, exampleApiMethod, productConfig, context.getNamer().getApiStubSettingsClassName(interfaceConfig), namer.getApiStubInterfaceName(context.getInterfaceConfig())));
    String name = namer.getApiStubSettingsClassName(context.getInterfaceConfig());
    xsettingsClass.name(name);
    xsettingsClass.serviceAddress(model.getServiceAddress());
    xsettingsClass.servicePort(model.getServicePort());
    xsettingsClass.authScopes(model.getAuthScopes());
    if (productConfig.getTransportProtocol().equals(TransportProtocol.HTTP)) {
        xsettingsClass.useDefaultServicePortInEndpoint(false);
    }
    xsettingsClass.transportProtocol(productConfig.getTransportProtocol());
    xsettingsClass.rpcTransportName(namer.getTransportClassName(productConfig.getTransportProtocol()));
    xsettingsClass.transportNameGetter(namer.getTransporNameGetMethod(productConfig.getTransportProtocol()));
    xsettingsClass.defaultTransportProviderBuilder(namer.getDefaultTransportProviderBuilder(productConfig.getTransportProtocol()));
    xsettingsClass.transportProvider(namer.getTransportProvider(productConfig.getTransportProtocol()));
    xsettingsClass.instantiatingChannelProvider(namer.getInstantiatingChannelProvider(productConfig.getTransportProtocol()));
    List<ApiCallSettingsView> apiCallSettings = apiCallableTransformer.generateCallSettings(context);
    xsettingsClass.callSettings(apiCallSettings);
    xsettingsClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptorClasses(context));
    xsettingsClass.pagedListResponseFactories(pageStreamingTransformer.generateFactoryClasses(context));
    xsettingsClass.batchingDescriptors(batchingTransformer.generateDescriptorClasses(context));
    xsettingsClass.retryCodesDefinitions(retryDefinitionsTransformer.generateRetryCodesDefinitions(context));
    xsettingsClass.retryParamsDefinitions(retryDefinitionsTransformer.generateRetryParamsDefinitions(context));
    xsettingsClass.transportProtocol(productConfig.getTransportProtocol());
    xsettingsClass.hasDefaultServiceAddress(interfaceConfig.hasDefaultServiceAddress());
    xsettingsClass.hasDefaultServiceScopes(interfaceConfig.hasDefaultServiceScopes());
    xsettingsClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
    xsettingsClass.stubInterfaceName(getAndSaveNicknameForStubType(context, namer.getApiStubInterfaceName(interfaceConfig)));
    xsettingsClass.rpcStubClassName(getAndSaveNicknameForStubType(context, namer.getApiRpcStubClassName(interfaceConfig.getInterfaceModel(), productConfig.getTransportProtocol())));
    return xsettingsClass.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ApiModel(com.google.api.codegen.config.ApiModel) StaticLangStubSettingsView(com.google.api.codegen.viewmodel.StaticLangStubSettingsView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ApiCallSettingsView(com.google.api.codegen.viewmodel.ApiCallSettingsView)

Example 3 with ApiCallSettingsView

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

the class ApiCallableTransformer method generateApiCallableSettings.

public ApiCallSettingsView generateApiCallableSettings(MethodContext context, ApiCallableImplType callableImplType) {
    SurfaceNamer namer = context.getNamer();
    ImportTypeTable typeTable = context.getTypeTable();
    MethodModel method = context.getMethodModel();
    MethodConfig methodConfig = context.getMethodConfig();
    Map<String, RetryCodesDefinitionView> retryCodesByKey = new HashMap<>();
    for (RetryCodesDefinitionView retryCodes : retryDefinitionsTransformer.generateRetryCodesDefinitions(context.getSurfaceInterfaceContext())) {
        retryCodesByKey.put(retryCodes.key(), retryCodes);
    }
    Map<String, RetryParamsDefinitionView> retryParamsByKey = new HashMap<>();
    for (RetryParamsDefinitionView retryParams : retryDefinitionsTransformer.generateRetryParamsDefinitions(context.getSurfaceInterfaceContext())) {
        retryParamsByKey.put(retryParams.key(), retryParams);
    }
    ApiCallSettingsView.Builder settings = ApiCallSettingsView.newBuilder();
    settings.methodName(namer.getApiMethodName(method, VisibilityConfig.PUBLIC));
    settings.asyncMethodName(namer.getAsyncApiMethodName(method, VisibilityConfig.PUBLIC));
    settings.requestTypeName(method.getAndSaveRequestTypeName(context.getTypeTable(), context.getNamer()));
    settings.responseTypeName(method.getAndSaveResponseTypeName(context.getTypeTable(), context.getNamer()));
    settings.grpcTypeName(typeTable.getAndSaveNicknameFor(context.getGrpcContainerTypeName()));
    settings.grpcMethodConstant(namer.getGrpcMethodConstant(method));
    settings.retryCodesName(methodConfig.getRetryCodesConfigName());
    settings.retryCodesView(retryCodesByKey.get(methodConfig.getRetryCodesConfigName()));
    settings.retryParamsName(methodConfig.getRetrySettingsConfigName());
    settings.retryParamsView(retryParamsByKey.get(methodConfig.getRetrySettingsConfigName()));
    settings.visibility(namer.getVisiblityKeyword(methodConfig.getVisibility()));
    String notImplementedPrefix = "ApiCallableTransformer.generateApiCallableSettings - ";
    settings.resourceTypeName(namer.getNotImplementedString(notImplementedPrefix + "resourceTypeName"));
    settings.pagedListResponseTypeName(namer.getNotImplementedString(notImplementedPrefix + "pagedListResponseTypeName"));
    settings.pageStreamingDescriptorName(namer.getNotImplementedString(notImplementedPrefix + "pageStreamingDescriptorName"));
    settings.pagedListResponseFactoryName(namer.getNotImplementedString(notImplementedPrefix + "pagedListResponseFactoryName"));
    settings.batchingDescriptorName(namer.getNotImplementedString(notImplementedPrefix + "batchingDescriptorName"));
    settings.memberName(namer.getSettingsMemberName(method));
    settings.settingsGetFunction(namer.getSettingsFunctionName(method));
    settings.type(callableImplType);
    switch(callableImplType) {
        case BidiStreamingApiCallable:
        case ClientStreamingApiCallable:
        case ServerStreamingApiCallable:
            settings.type(ApiCallableImplType.of(methodConfig.getGrpcStreamingType()));
            if (methodConfig.getGrpcStreaming().hasResourceField()) {
                FieldModel resourceType = methodConfig.getGrpcStreaming().getResourcesField();
                settings.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceType));
            }
            settings.grpcStreamingType(methodConfig.getGrpcStreaming().getType());
            break;
        case PagedApiCallable:
            settings.type(ApiCallableImplType.PagedApiCallable);
            FieldModel resourceField = methodConfig.getPageStreaming().getResourcesField();
            settings.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceField));
            settings.pagedListResponseTypeName(namer.getAndSavePagedResponseTypeName(context, methodConfig.getPageStreaming().getResourcesFieldConfig()));
            settings.pageStreamingDescriptorName(namer.getPageStreamingDescriptorConstName(method));
            settings.pagedListResponseFactoryName(namer.getPagedListResponseFactoryConstName(method));
            break;
        case BatchingApiCallable:
            settings.type(ApiCallableImplType.BatchingApiCallable);
            settings.batchingDescriptorName(namer.getBatchingDescriptorConstName(method));
            settings.batchingConfig(batchingTransformer.generateBatchingConfig(context));
            break;
        case OperationApiCallable:
            settings.type(ApiCallableImplType.OperationApiCallable);
            settings.operationMethod(lroTransformer.generateDetailView(context));
            settings.memberName(namer.getOperationSettingsMemberName(method));
            settings.settingsGetFunction(namer.getOperationSettingsFunctionName(method));
            break;
        case SimpleApiCallable:
            break;
        default:
            throw new IllegalStateException("Unhandled ApiCallableImplType enum value: " + callableImplType);
    }
    return settings.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) HashMap(java.util.HashMap) RetryCodesDefinitionView(com.google.api.codegen.viewmodel.RetryCodesDefinitionView) ApiCallSettingsView(com.google.api.codegen.viewmodel.ApiCallSettingsView) MethodConfig(com.google.api.codegen.config.MethodConfig) RetryParamsDefinitionView(com.google.api.codegen.viewmodel.RetryParamsDefinitionView) FieldModel(com.google.api.codegen.config.FieldModel)

Example 4 with ApiCallSettingsView

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

the class CSharpGapicClientTransformer method generateCallSettings.

public List<ApiCallSettingsView> generateCallSettings(GapicInterfaceContext context) {
    // This method can be removed once mixins are supported in C#
    List<ApiCallSettingsView> settingsMembers = new ArrayList<>();
    for (MethodModel method : csharpCommonTransformer.getSupportedMethods(context)) {
        List<ApiCallSettingsView> calls = apiCallableTransformer.generateApiCallableSettings(context.asRequestMethodContext(method));
        settingsMembers.addAll(calls);
    }
    return settingsMembers;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ArrayList(java.util.ArrayList) ApiCallSettingsView(com.google.api.codegen.viewmodel.ApiCallSettingsView)

Aggregations

ApiCallSettingsView (com.google.api.codegen.viewmodel.ApiCallSettingsView)4 MethodConfig (com.google.api.codegen.config.MethodConfig)2 MethodModel (com.google.api.codegen.config.MethodModel)2 ArrayList (java.util.ArrayList)2 ApiModel (com.google.api.codegen.config.ApiModel)1 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)1 FieldModel (com.google.api.codegen.config.FieldModel)1 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1 RetryCodesDefinitionView (com.google.api.codegen.viewmodel.RetryCodesDefinitionView)1 RetryParamsDefinitionView (com.google.api.codegen.viewmodel.RetryParamsDefinitionView)1 StaticLangStubSettingsView (com.google.api.codegen.viewmodel.StaticLangStubSettingsView)1 HashMap (java.util.HashMap)1