Search in sources :

Example 1 with RetryCodesDefinitionView

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

the class CSharpGapicClientTransformer method generateSettingsClass.

private StaticLangSettingsView generateSettingsClass(GapicInterfaceContext context) {
    StaticLangSettingsView.Builder settingsClass = StaticLangSettingsView.newBuilder();
    settingsClass.doc(generateSettingsDoc(context));
    String name = context.getNamer().getApiSettingsClassName(context.getInterfaceConfig());
    settingsClass.name(name);
    ApiModel model = context.getApiModel();
    settingsClass.serviceHostname(productServiceConfig.getServiceHostname(context.getServiceAddress()));
    settingsClass.servicePort(productServiceConfig.getServicePort(context.getServiceAddress()));
    settingsClass.authScopes(model.getAuthScopes(context.getProductConfig()));
    settingsClass.callSettings(generateCallSettings(context));
    settingsClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptorClasses(context));
    settingsClass.batchingDescriptors(batchingTransformer.generateDescriptorClasses(context));
    // Remove additional retry codes, added due to the change in retry when using proto annotations.
    List<RetryCodesDefinitionView> retryCodes = retryDefinitionsTransformer.generateRetryCodesDefinitions(context);
    settingsClass.retryCodesDefinitions(retryCodes);
    settingsClass.retryParamsDefinitions(retryDefinitionsTransformer.generateRetryParamsDefinitions(context));
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    settingsClass.hasDefaultServiceAddress(interfaceConfig.hasDefaultServiceAddress());
    settingsClass.hasDefaultServiceScopes(interfaceConfig.hasDefaultServiceScopes());
    settingsClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
    return settingsClass.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) StaticLangSettingsView(com.google.api.codegen.viewmodel.StaticLangSettingsView) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) ApiModel(com.google.api.codegen.config.ApiModel) RetryCodesDefinitionView(com.google.api.codegen.viewmodel.RetryCodesDefinitionView)

Example 2 with RetryCodesDefinitionView

use of com.google.api.codegen.viewmodel.RetryCodesDefinitionView 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()));
    typeTable.getAndSaveNicknameFor(context.getGrpcContainerTypeName());
    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.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.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 : ProtoMethodModel(com.google.api.codegen.config.ProtoMethodModel) 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)

Aggregations

RetryCodesDefinitionView (com.google.api.codegen.viewmodel.RetryCodesDefinitionView)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 MethodConfig (com.google.api.codegen.config.MethodConfig)1 MethodModel (com.google.api.codegen.config.MethodModel)1 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)1 ProtoMethodModel (com.google.api.codegen.config.ProtoMethodModel)1 ApiCallSettingsView (com.google.api.codegen.viewmodel.ApiCallSettingsView)1 RetryParamsDefinitionView (com.google.api.codegen.viewmodel.RetryParamsDefinitionView)1 StaticLangSettingsView (com.google.api.codegen.viewmodel.StaticLangSettingsView)1 HashMap (java.util.HashMap)1