Search in sources :

Example 1 with LongRunningOperationDetailView

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

the class GoGapicSurfaceTransformer method generate.

private StaticLangClientFileView generate(GapicInterfaceContext context) {
    StaticLangClientFileView.Builder view = StaticLangClientFileView.newBuilder();
    SurfaceNamer namer = context.getNamer();
    ApiModel model = context.getApiModel();
    ProtoInterfaceModel apiInterface = context.getInterfaceModel();
    GapicProductConfig productConfig = context.getProductConfig();
    GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
    view.templateFileName(API_TEMPLATE_FILENAME);
    view.serviceDoc(serviceTransformer.generateServiceDoc(context, null, productConfig));
    view.domainLayerLocation(productConfig.getDomainLayerLocation());
    view.clientTypeName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    view.clientConstructorName(namer.getApiWrapperClassConstructorName(interfaceConfig));
    view.defaultClientOptionFunctionName(namer.getDefaultApiSettingsFunctionName(interfaceConfig));
    view.defaultCallOptionFunctionName(namer.getDefaultCallSettingsFunctionName(interfaceConfig));
    view.callOptionsTypeName(namer.getCallSettingsTypeName(interfaceConfig));
    view.serviceOriginalName(model.getTitle());
    view.servicePhraseName(namer.getServicePhraseName(interfaceConfig));
    String outputPath = pathMapper.getOutputPath(apiInterface.getFullName(), productConfig);
    String fileName = namer.getServiceFileName(context.getInterfaceConfig());
    view.outputPath(outputPath + File.separator + fileName);
    List<RetryConfigDefinitionView> retryDef = generateRetryConfigDefinitions(context, context.getSupportedMethods());
    view.retryPairDefinitions(retryDef);
    view.callSettings(apiCallableTransformer.generateCallSettings(context));
    List<StaticLangApiMethodView> apiMethods = generateApiMethods(context, context.getSupportedMethods());
    view.apiMethods(apiMethods);
    // If any methods have header request params, "fmt" is needed for `fmt.Sprintf` calls.
    if (apiMethods.stream().anyMatch(m -> !m.headerRequestParams().isEmpty())) {
        context.getImportTypeTable().saveNicknameFor("fmt;;;");
    }
    view.iamResources(iamResourceTransformer.generateIamResources(context));
    if (!((GapicInterfaceConfig) productConfig.getInterfaceConfig(apiInterface.getFullName())).getIamResources().isEmpty()) {
        context.getImportTypeTable().saveNicknameFor("cloud.google.com/go/iam;;;");
    }
    // In Go, multiple methods share the same iterator type, one iterator type per resource type.
    // We have to dedupe the iterators.
    Map<String, PageStreamingDescriptorClassView> iterators = new TreeMap<>();
    for (PageStreamingDescriptorClassView desc : pageStreamingTransformer.generateDescriptorClasses(context)) {
        iterators.put(desc.typeName(), desc);
    }
    view.pageStreamingDescriptorClasses(new ArrayList<>(iterators.values()));
    // Same with long running operations.
    Map<String, LongRunningOperationDetailView> lros = new TreeMap<>();
    for (StaticLangApiMethodView apiMethod : apiMethods) {
        LongRunningOperationDetailView lro = apiMethod.operationMethod();
        if (lro != null) {
            lros.put(lro.clientReturnTypeName(), lro);
        }
    }
    view.lroDetailViews(new ArrayList<>(lros.values()));
    view.serviceAddress(context.getApiModel().getServiceAddress());
    view.servicePort(model.getServicePort());
    view.stubs(grpcStubTransformer.generateGrpcStubs(context));
    addXApiImports(context, context.getSupportedMethods());
    view.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    return view.build();
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) RetryConfigDefinitionView(com.google.api.codegen.viewmodel.RetryConfigDefinitionView) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) ApiModel(com.google.api.codegen.config.ApiModel) TreeMap(java.util.TreeMap) LongRunningOperationDetailView(com.google.api.codegen.viewmodel.LongRunningOperationDetailView) StaticLangClientFileView(com.google.api.codegen.viewmodel.StaticLangClientFileView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) PageStreamingDescriptorClassView(com.google.api.codegen.viewmodel.PageStreamingDescriptorClassView)

Example 2 with LongRunningOperationDetailView

use of com.google.api.codegen.viewmodel.LongRunningOperationDetailView 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 3 with LongRunningOperationDetailView

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

the class NodeJSGapicSurfaceTransformer method createLongRunningDescriptors.

private List<LongRunningOperationDetailView> createLongRunningDescriptors(GapicInterfaceContext context) {
    List<LongRunningOperationDetailView> result = new ArrayList<>();
    for (MethodModel method : context.getLongRunningMethods()) {
        GapicMethodContext methodContext = context.asDynamicMethodContext(method);
        LongRunningConfig lroConfig = methodContext.getMethodConfig().getLongRunningConfig();
        TypeModel returnType = lroConfig.getReturnType();
        TypeModel metadataType = lroConfig.getMetadataType();
        result.add(LongRunningOperationDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).constructorName("").clientReturnTypeName("").operationPayloadTypeName(context.getImportTypeTable().getFullNameFor(returnType)).isEmptyOperation(lroConfig.getReturnType().isEmptyType()).metadataTypeName(context.getImportTypeTable().getFullNameFor(metadataType)).implementsCancel(true).implementsDelete(true).initialPollDelay(lroConfig.getInitialPollDelay().toMillis()).pollDelayMultiplier(lroConfig.getPollDelayMultiplier()).maxPollDelay(lroConfig.getMaxPollDelay().toMillis()).totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()).build());
    }
    return result;
}
Also used : LongRunningOperationDetailView(com.google.api.codegen.viewmodel.LongRunningOperationDetailView) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) LongRunningConfig(com.google.api.codegen.config.LongRunningConfig) ArrayList(java.util.ArrayList) TypeModel(com.google.api.codegen.config.TypeModel)

Example 4 with LongRunningOperationDetailView

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

the class PhpGapicSurfaceTransformer method createLongRunningDescriptors.

private List<LongRunningOperationDetailView> createLongRunningDescriptors(GapicInterfaceContext context) {
    List<LongRunningOperationDetailView> result = new ArrayList<>();
    for (MethodModel method : context.getLongRunningMethods()) {
        GapicMethodContext methodContext = context.asDynamicMethodContext(method);
        LongRunningConfig lroConfig = methodContext.getMethodConfig().getLongRunningConfig();
        TypeModel returnType = lroConfig.getReturnType();
        TypeModel metadataType = lroConfig.getMetadataType();
        result.add(LongRunningOperationDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).transportMethodName(context.getNamer().getGrpcMethodName(method)).constructorName("").clientReturnTypeName("").operationPayloadTypeName(context.getImportTypeTable().getFullNameFor(returnType)).isEmptyOperation(lroConfig.getReturnType().isEmptyType()).metadataTypeName(context.getImportTypeTable().getFullNameFor(metadataType)).implementsCancel(true).implementsDelete(true).initialPollDelay(lroConfig.getInitialPollDelay().toMillis()).pollDelayMultiplier(lroConfig.getPollDelayMultiplier()).maxPollDelay(lroConfig.getMaxPollDelay().toMillis()).totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()).build());
    }
    return result;
}
Also used : LongRunningOperationDetailView(com.google.api.codegen.viewmodel.LongRunningOperationDetailView) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) LongRunningConfig(com.google.api.codegen.config.LongRunningConfig) ArrayList(java.util.ArrayList) TypeModel(com.google.api.codegen.config.TypeModel)

Aggregations

LongRunningOperationDetailView (com.google.api.codegen.viewmodel.LongRunningOperationDetailView)4 MethodModel (com.google.api.codegen.config.MethodModel)3 LongRunningConfig (com.google.api.codegen.config.LongRunningConfig)2 TypeModel (com.google.api.codegen.config.TypeModel)2 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)2 ArrayList (java.util.ArrayList)2 ApiModel (com.google.api.codegen.config.ApiModel)1 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)1 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)1 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)1 ProtoInterfaceModel (com.google.api.codegen.config.ProtoInterfaceModel)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1 ApiCallableView (com.google.api.codegen.viewmodel.ApiCallableView)1 PageStreamingDescriptorClassView (com.google.api.codegen.viewmodel.PageStreamingDescriptorClassView)1 RetryConfigDefinitionView (com.google.api.codegen.viewmodel.RetryConfigDefinitionView)1 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)1 StaticLangClientFileView (com.google.api.codegen.viewmodel.StaticLangClientFileView)1 TreeMap (java.util.TreeMap)1