Search in sources :

Example 51 with MethodModel

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

the class ApiCallableTransformer method generateMainApiCallable.

private ApiCallableView generateMainApiCallable(MethodContext context) {
    MethodConfig methodConfig = context.getMethodConfig();
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    ApiCallableView.Builder apiCallableBuilder = ApiCallableView.newBuilder();
    apiCallableBuilder.requestTypeName(method.getAndSaveRequestTypeName(context.getTypeTable(), context.getNamer()));
    apiCallableBuilder.responseTypeName(method.getAndSaveResponseTypeName(context.getTypeTable(), context.getNamer()));
    apiCallableBuilder.name(namer.getCallableName(method));
    apiCallableBuilder.methodName(namer.getApiMethodName(method, context.getMethodConfig().getVisibility()));
    apiCallableBuilder.asyncMethodName(namer.getAsyncApiMethodName(method, VisibilityConfig.PUBLIC));
    apiCallableBuilder.memberName(namer.getSettingsMemberName(method));
    apiCallableBuilder.settingsFunctionName(namer.getSettingsFunctionName(method));
    apiCallableBuilder.grpcClientVarName(namer.getReroutedGrpcClientVarName(methodConfig));
    apiCallableBuilder.headerRequestParams(headerRequestParamTransformer.generateHeaderRequestParams(context));
    setCommonApiCallableFields(context, apiCallableBuilder);
    ApiCallableImplType callableImplType = ApiCallableImplType.SimpleApiCallable;
    if (methodConfig.isGrpcStreaming()) {
        callableImplType = ApiCallableImplType.of(methodConfig.getGrpcStreamingType());
        apiCallableBuilder.grpcStreamingType(methodConfig.getGrpcStreamingType());
    } else if (methodConfig.isBatching()) {
        callableImplType = ApiCallableImplType.BatchingApiCallable;
    }
    apiCallableBuilder.type(callableImplType);
    apiCallableBuilder.interfaceTypeName(namer.getApiCallableTypeName(callableImplType.serviceMethodType()));
    return apiCallableBuilder.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) ApiCallableImplType(com.google.api.codegen.viewmodel.ApiCallableImplType)

Example 52 with MethodModel

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

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

the class ApiCallableTransformer method generateOperationApiCallable.

private ApiCallableView generateOperationApiCallable(GapicMethodContext context) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    ApiCallableView.Builder operationApiCallableBuilder = ApiCallableView.newBuilder();
    operationApiCallableBuilder.type(ApiCallableImplType.OperationApiCallable);
    operationApiCallableBuilder.interfaceTypeName(namer.getApiCallableTypeName(ServiceMethodType.LongRunningMethod));
    LongRunningOperationDetailView lroView = lroTransformer.generateDetailView(context);
    operationApiCallableBuilder.requestTypeName(method.getAndSaveRequestTypeName(context.getTypeTable(), context.getNamer()));
    operationApiCallableBuilder.responseTypeName(lroView.operationPayloadTypeName());
    operationApiCallableBuilder.metadataTypeName(lroView.metadataTypeName());
    operationApiCallableBuilder.name(namer.getOperationCallableName(method));
    setCommonApiCallableFields(context, operationApiCallableBuilder);
    operationApiCallableBuilder.settingsFunctionName(namer.getOperationSettingsFunctionName(method));
    return operationApiCallableBuilder.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) LongRunningOperationDetailView(com.google.api.codegen.viewmodel.LongRunningOperationDetailView) ApiCallableView(com.google.api.codegen.viewmodel.ApiCallableView)

Example 54 with MethodModel

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

the class ApiCallableTransformer method setCommonApiCallableFields.

private void setCommonApiCallableFields(MethodContext context, ApiCallableView.Builder apiCallableBuilder) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    MethodConfig methodConfig = context.getMethodConfig();
    apiCallableBuilder.methodName(namer.getApiMethodName(method, context.getMethodConfig().getVisibility()));
    apiCallableBuilder.asyncMethodName(namer.getAsyncApiMethodName(method, VisibilityConfig.PUBLIC));
    apiCallableBuilder.memberName(namer.getSettingsMemberName(method));
    apiCallableBuilder.settingsFunctionName(namer.getSettingsFunctionName(method));
    apiCallableBuilder.grpcClientVarName(namer.getReroutedGrpcClientVarName(methodConfig));
    apiCallableBuilder.methodDescriptorName(namer.getMethodDescriptorName(method));
    apiCallableBuilder.transportSettingsVar(namer.getTransportSettingsVar(method));
    apiCallableBuilder.httpMethod(generateHttpFields(context));
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel)

Example 55 with MethodModel

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

the class BatchingTransformer method generateDescriptors.

public List<BatchingDescriptorView> generateDescriptors(InterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    ImmutableList.Builder<BatchingDescriptorView> descriptors = ImmutableList.builder();
    for (MethodModel method : context.getBatchingMethods()) {
        BatchingConfig batching = context.getMethodConfig(method).getBatching();
        BatchingDescriptorView.Builder descriptor = BatchingDescriptorView.newBuilder();
        descriptor.methodName(context.getNamer().getMethodKey(method));
        descriptor.batchedFieldName(namer.getFieldName(batching.getBatchedField()));
        descriptor.discriminatorFieldNames(generateDiscriminatorFieldNames(batching));
        if (batching.hasSubresponseField()) {
            descriptor.subresponseFieldName(namer.getFieldName(batching.getSubresponseField()));
        }
        descriptor.byteLengthFunctionName(namer.getByteLengthFunctionName(batching.getBatchedField()));
        descriptors.add(descriptor.build());
    }
    return descriptors.build();
}
Also used : BatchingDescriptorView(com.google.api.codegen.viewmodel.BatchingDescriptorView) MethodModel(com.google.api.codegen.config.MethodModel) ImmutableList(com.google.common.collect.ImmutableList) BatchingConfig(com.google.api.codegen.config.BatchingConfig)

Aggregations

MethodModel (com.google.api.codegen.config.MethodModel)95 ArrayList (java.util.ArrayList)30 MethodConfig (com.google.api.codegen.config.MethodConfig)29 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)23 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)20 ImmutableList (com.google.common.collect.ImmutableList)16 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)14 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)14 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)12 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)11 FieldConfig (com.google.api.codegen.config.FieldConfig)11 ProtoMethodModel (com.google.api.codegen.config.ProtoMethodModel)9 Test (org.junit.Test)9 FieldModel (com.google.api.codegen.config.FieldModel)8 MethodContext (com.google.api.codegen.transformer.MethodContext)8 SymbolTable (com.google.api.codegen.util.SymbolTable)8 TypeModel (com.google.api.codegen.config.TypeModel)7 TestCaseView (com.google.api.codegen.viewmodel.testing.TestCaseView)7 InterfaceModel (com.google.api.codegen.config.InterfaceModel)6 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)6