Search in sources :

Example 81 with MethodModel

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

the class GoGapicSurfaceTransformer method generateRetryConfigDefinitions.

@VisibleForTesting
List<RetryConfigDefinitionView> generateRetryConfigDefinitions(InterfaceContext context, List<MethodModel> methods) {
    Set<RetryConfigDefinitionView.Name> retryNames = new HashSet<>();
    for (MethodModel method : methods) {
        MethodConfig conf = context.getMethodConfig(method);
        retryNames.add(RetryConfigDefinitionView.Name.create(conf.getRetrySettingsConfigName(), conf.getRetryCodesConfigName()));
    }
    TreeMap<RetryConfigDefinitionView.Name, RetryConfigDefinitionView> retryDef = new TreeMap<>();
    Map<String, ImmutableSet<String>> retryCodesDef = context.getInterfaceConfig().getRetryCodesDefinition();
    Map<String, RetrySettings> retryParamsDef = context.getInterfaceConfig().getRetrySettingsDefinition();
    for (RetryConfigDefinitionView.Name name : retryNames) {
        ImmutableSet<String> codes = retryCodesDef.get(name.retryCodesConfigName());
        if (codes.isEmpty()) {
            continue;
        }
        List<String> retryCodeNames = new ArrayList<>();
        for (String code : codes) {
            retryCodeNames.add(context.getNamer().getStatusCodeName(code));
        }
        retryDef.put(name, RetryConfigDefinitionView.newBuilder().name(name).retryCodes(retryCodeNames).params(retryParamsDef.get(name.retrySettingsConfigName())).build());
    }
    if (!retryDef.isEmpty()) {
        context.getImportTypeTable().saveNicknameFor("time;;;");
        context.getImportTypeTable().saveNicknameFor("google.golang.org/grpc/codes;;;");
    }
    return new ArrayList<>(retryDef.values());
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) RetryConfigDefinitionView(com.google.api.codegen.viewmodel.RetryConfigDefinitionView) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) MethodConfig(com.google.api.codegen.config.MethodConfig) RetrySettings(com.google.api.gax.retrying.RetrySettings) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 82 with MethodModel

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

the class JavaSurfaceTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(InterfaceContext context) {
    ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
    SymbolTable testNameTable = new SymbolTable();
    for (MethodModel method : context.getSupportedMethods()) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        if (methodConfig.isGrpcStreaming()) {
            if (methodConfig.getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
                // Issue: https://github.com/googleapis/toolkit/issues/946
                continue;
            }
            addGrpcStreamingTestImports(context, methodConfig.getGrpcStreamingType());
            MethodContext methodContext = context.asRequestMethodContext(method);
            InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), methodConfig.getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
            testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, ClientMethodType.CallableMethod));
        } else if (methodConfig.isFlattening()) {
            ClientMethodType clientMethodType;
            if (methodConfig.isPageStreaming()) {
                clientMethodType = ClientMethodType.PagedFlattenedMethod;
            } else if (methodConfig.isLongRunningOperation()) {
                clientMethodType = ClientMethodType.AsyncOperationFlattenedMethod;
            } else {
                clientMethodType = ClientMethodType.FlattenedMethod;
            }
            for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                MethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), flatteningGroup.getFlattenedFieldConfigs().values(), InitCodeOutputType.FieldList, valueGenerator);
                testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
            }
        } else {
            // TODO: Add support of non-flattening method
            // Github issue: https://github.com/googleapis/toolkit/issues/393
            System.err.println("Non-flattening method test is not supported yet for " + method.getSimpleName());
        }
    }
    return testCaseViews;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) ArrayList(java.util.ArrayList) SymbolTable(com.google.api.codegen.util.SymbolTable) MethodContext(com.google.api.codegen.transformer.MethodContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext)

Example 83 with MethodModel

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

the class JavaSurfaceTransformer method generatePagedResponseWrappers.

private List<StaticLangPagedResponseView> generatePagedResponseWrappers(InterfaceContext context, GapicProductConfig productConfig, ReleaseLevel releaseLevel) {
    addPagedResponseWrapperImports(context.getImportTypeTable());
    ImmutableList.Builder<StaticLangPagedResponseView> pagedResponseWrappersList = ImmutableList.builder();
    for (MethodModel method : context.getSupportedMethods()) {
        if (context.getMethodConfig(method).isPageStreaming()) {
            pagedResponseWrappersList.add(generatePagedResponseWrapper(context.asRequestMethodContext(method), context.getImportTypeTable()));
        }
    }
    return pagedResponseWrappersList.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) StaticLangPagedResponseView(com.google.api.codegen.viewmodel.StaticLangPagedResponseView) ImmutableList(com.google.common.collect.ImmutableList)

Example 84 with MethodModel

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

the class NodeJSGapicSurfaceTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
    ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
    SymbolTable testNameTable = new SymbolTable();
    for (MethodModel method : context.getSupportedMethods()) {
        GapicMethodContext methodContext = context.asRequestMethodContext(method);
        if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
            // Issue: https://github.com/googleapis/toolkit/issues/946
            continue;
        }
        Iterable<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
        InitCodeContext initCodeContext = InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(InitCodeOutputType.SingleObject).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
        testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, getMethodType(methodContext.getMethodConfig())));
    }
    return testCaseViews;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) SymbolTable(com.google.api.codegen.util.SymbolTable) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext)

Example 85 with MethodModel

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

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