Search in sources :

Example 61 with MethodModel

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

the class StaticLangApiMethodTransformer method generateOperationCallableMethod.

public StaticLangApiMethodView generateOperationCallableMethod(MethodContext context) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
    setCommonFields(context, methodViewBuilder);
    methodViewBuilder.name(namer.getOperationCallableMethodName(method));
    methodViewBuilder.exampleName(context.getNamer().getOperationCallableMethodExampleName(method));
    setCallableMethodFields(context, namer.getOperationCallableName(method), methodViewBuilder);
    TypeModel returnType = context.getMethodConfig().getLongRunningConfig().getReturnType();
    methodViewBuilder.responseTypeName(context.getTypeTable().getAndSaveNicknameFor(returnType));
    methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context));
    return methodViewBuilder.type(ClientMethodType.OperationCallableMethod).build();
}
Also used : Builder(com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) TypeModel(com.google.api.codegen.config.TypeModel)

Example 62 with MethodModel

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

the class StaticLangApiMethodTransformer method generateUnpagedListCallableMethod.

public StaticLangApiMethodView generateUnpagedListCallableMethod(MethodContext context) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
    setCommonFields(context, methodViewBuilder);
    methodViewBuilder.name(namer.getCallableMethodName(method));
    methodViewBuilder.exampleName(namer.getCallableMethodExampleName(method));
    setListMethodFields(context, Synchronicity.Sync, methodViewBuilder);
    setCallableMethodFields(context, namer.getCallableName(method), methodViewBuilder);
    String getResourceListCallName = namer.getFieldGetFunctionName(context.getFeatureConfig(), context.getMethodConfig().getPageStreaming().getResourcesFieldConfig());
    String resourceListParseFunction = "";
    PageStreamingConfig pageStreaming = context.getMethodConfig().getPageStreaming();
    FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
    if (context.getFeatureConfig().useResourceNameConverters(resourceFieldConfig)) {
        resourceListParseFunction = namer.getResourceTypeParseListMethodName(context.getTypeTable(), resourceFieldConfig);
    }
    UnpagedListCallableMethodDetailView unpagedListCallableDetails = UnpagedListCallableMethodDetailView.newBuilder().resourceListGetFunction(getResourceListCallName).resourceListParseFunction(resourceListParseFunction).build();
    methodViewBuilder.unpagedListCallableMethod(unpagedListCallableDetails);
    methodViewBuilder.responseTypeName(context.getMethodModel().getAndSaveResponseTypeName(context.getTypeTable(), context.getNamer()));
    return methodViewBuilder.type(ClientMethodType.UnpagedListCallableMethod).build();
}
Also used : Builder(com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) UnpagedListCallableMethodDetailView(com.google.api.codegen.viewmodel.UnpagedListCallableMethodDetailView) FieldConfig(com.google.api.codegen.config.FieldConfig) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig)

Example 63 with MethodModel

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

the class StaticLangApiMethodTransformer method generateRequestObjectAsyncMethod.

public StaticLangApiMethodView generateRequestObjectAsyncMethod(MethodContext context, List<ParamWithSimpleDoc> additionalParams, ClientMethodType type) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
    setCommonFields(context, methodViewBuilder);
    methodViewBuilder.name(namer.getAsyncApiMethodName(method, context.getMethodConfig().getVisibility()));
    methodViewBuilder.exampleName(namer.getAsyncApiMethodExampleName(method));
    setRequestObjectMethodFields(context, namer.getCallableAsyncMethodName(method), Synchronicity.Async, additionalParams, methodViewBuilder);
    setStaticLangAsyncReturnTypeName(context, methodViewBuilder);
    return methodViewBuilder.type(type).build();
}
Also used : Builder(com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView)

Example 64 with MethodModel

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

the class StaticLangApiMethodTransformer method setListMethodFields.

private void setListMethodFields(MethodContext context, Synchronicity synchronicity, StaticLangApiMethodView.Builder methodViewBuilder) {
    MethodModel method = context.getMethodModel();
    ImportTypeTable typeTable = context.getTypeTable();
    SurfaceNamer namer = context.getNamer();
    PageStreamingConfig pageStreaming = context.getMethodConfig().getPageStreaming();
    String requestTypeName = method.getAndSaveRequestTypeName(context.getTypeTable(), context.getNamer());
    String responseTypeName = method.getAndSaveResponseTypeName(context.getTypeTable(), context.getNamer());
    FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
    FieldModel resourceField = resourceFieldConfig.getField();
    String resourceTypeName;
    if (context.getFeatureConfig().useResourceNameFormatOption(resourceFieldConfig)) {
        resourceTypeName = namer.getAndSaveElementResourceTypeName(typeTable, resourceFieldConfig);
    } else {
        resourceTypeName = typeTable.getAndSaveNicknameForElementType(resourceField);
    }
    String iterateMethodName = context.getNamer().getPagedResponseIterateMethod(context.getFeatureConfig(), resourceFieldConfig);
    String resourceFieldName = context.getNamer().getFieldName(resourceField);
    List<String> resourceFieldGetFunctionNames = resourceField.getPagedResponseResourceMethods(context.getFeatureConfig(), resourceFieldConfig, context.getNamer());
    methodViewBuilder.listMethod(ListMethodDetailView.newBuilder().requestTypeName(requestTypeName).responseTypeName(responseTypeName).resourceTypeName(resourceTypeName).iterateMethodName(iterateMethodName).resourceFieldName(resourceFieldName).resourcesFieldGetFunctions(resourceFieldGetFunctionNames).build());
    switch(synchronicity) {
        case Sync:
            methodViewBuilder.responseTypeName(namer.getAndSavePagedResponseTypeName(context, resourceFieldConfig));
            break;
        case Async:
            methodViewBuilder.responseTypeName(namer.getAndSaveAsyncPagedResponseTypeName(context, resourceFieldConfig));
            break;
    }
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) FieldConfig(com.google.api.codegen.config.FieldConfig) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) FieldModel(com.google.api.codegen.config.FieldModel)

Example 65 with MethodModel

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

the class StaticLangApiMethodTransformer method generatePagedRequestObjectMethod.

public StaticLangApiMethodView generatePagedRequestObjectMethod(MethodContext context, List<ParamWithSimpleDoc> additionalParams) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
    setCommonFields(context, methodViewBuilder);
    methodViewBuilder.name(namer.getApiMethodName(method, context.getMethodConfig().getVisibility()));
    methodViewBuilder.exampleName(namer.getApiMethodExampleName(context.getInterfaceConfig(), method));
    setListMethodFields(context, Synchronicity.Sync, methodViewBuilder);
    setRequestObjectMethodFields(context, namer.getPagedCallableMethodName(method), Synchronicity.Sync, additionalParams, methodViewBuilder);
    return methodViewBuilder.type(ClientMethodType.PagedRequestObjectMethod).build();
}
Also used : Builder(com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView)

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