Search in sources :

Example 31 with FieldConfig

use of com.google.api.codegen.config.FieldConfig 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 = namer.getPagedResponseIterateMethod(context.getFeatureConfig(), resourceFieldConfig);
    String resourceFieldName = namer.getFieldName(resourceField);
    String resourceFieldGetterName = namer.getFieldGetFunctionName(context.getFeatureConfig(), resourceFieldConfig);
    methodViewBuilder.listMethod(ListMethodDetailView.newBuilder().requestTypeName(requestTypeName).responseTypeName(responseTypeName).resourceTypeName(resourceTypeName).iterateMethodName(iterateMethodName).resourceFieldName(resourceFieldName).resourcesFieldGetFunction(resourceFieldGetterName).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 32 with FieldConfig

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

the class StaticLangApiMethodTransformer method generatePathTemplateChecks.

private List<PathTemplateCheckView> generatePathTemplateChecks(MethodContext context, Iterable<FieldConfig> fieldConfigs) {
    List<PathTemplateCheckView> pathTemplateChecks = new ArrayList<>();
    if (!context.getFeatureConfig().enableStringFormatFunctions()) {
        return pathTemplateChecks;
    }
    for (FieldConfig fieldConfig : fieldConfigs) {
        if (!fieldConfig.useValidation()) {
            // Don't generate a path template check if fieldConfig is not configured to use validation.
            continue;
        }
        FieldModel field = fieldConfig.getField();
        ImmutableMap<String, String> fieldNamePatterns = context.getFieldResourceEntityMap();
        String entityName = fieldNamePatterns.get(field.getSimpleName());
        if (entityName != null) {
            SingleResourceNameConfig resourceNameConfig = context.getSingleResourceNameConfig(entityName);
            if (resourceNameConfig == null) {
                String methodName = context.getMethodModel().getSimpleName();
                throw new IllegalStateException("No collection config with id '" + entityName + "' required by configuration for method '" + methodName + "'");
            }
            PathTemplateCheckView.Builder check = PathTemplateCheckView.newBuilder();
            check.pathTemplateName(context.getNamer().getPathTemplateName(context.getInterfaceConfig(), resourceNameConfig));
            check.paramName(context.getNamer().getVariableName(field));
            check.allowEmptyString(shouldAllowEmpty(context, field));
            check.validationMessageContext(context.getNamer().getApiMethodName(context.getMethodModel(), context.getMethodConfig().getVisibility()));
            pathTemplateChecks.add(check.build());
        }
    }
    return pathTemplateChecks;
}
Also used : PathTemplateCheckView(com.google.api.codegen.viewmodel.PathTemplateCheckView) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) FieldModel(com.google.api.codegen.config.FieldModel) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig)

Example 33 with FieldConfig

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

the class StaticLangApiMethodTransformer method generateUnpagedListCallableMethod.

// Used by: Java
public StaticLangApiMethodView generateUnpagedListCallableMethod(MethodContext context, SampleContext sampleContext) {
    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, context.getCallingForms(), sampleContext);
    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 34 with FieldConfig

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

the class PageStreamingTransformer method generateFactoryClass.

private PagedListResponseFactoryClassView generateFactoryClass(MethodContext context) {
    SurfaceNamer namer = context.getNamer();
    MethodModel method = context.getMethodModel();
    ImportTypeTable typeTable = context.getTypeTable();
    PageStreamingConfig pageStreaming = context.getMethodConfig().getPageStreaming();
    FieldModel resourceField = pageStreaming.getResourcesField();
    FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
    PagedListResponseFactoryClassView.Builder factory = PagedListResponseFactoryClassView.newBuilder();
    factory.name(namer.getPagedListResponseFactoryConstName(method));
    factory.requestTypeName(method.getAndSaveRequestTypeName(typeTable, namer));
    factory.responseTypeName(method.getAndSaveResponseTypeName(typeTable, namer));
    factory.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceField));
    factory.pagedListResponseTypeName(namer.getAndSavePagedResponseTypeName(context, resourceFieldConfig));
    factory.pageStreamingDescriptorName(namer.getPageStreamingDescriptorConstName(method));
    return factory.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) FieldConfig(com.google.api.codegen.config.FieldConfig) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) PagedListResponseFactoryClassView(com.google.api.codegen.viewmodel.PagedListResponseFactoryClassView) FieldModel(com.google.api.codegen.config.FieldModel)

Example 35 with FieldConfig

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

the class InitCodeTransformer method createResourceNameOneofInitValueView.

private ResourceNameOneofInitValueView createResourceNameOneofInitValueView(MethodContext context, FieldConfig fieldConfig, InitCodeNode item, boolean convertToString) {
    ResourceNameOneofConfig oneofConfig = (ResourceNameOneofConfig) fieldConfig.getResourceNameConfig();
    SurfaceNamer namer = context.getNamer();
    ImportTypeTable typeTable = context.getTypeTable();
    if (context.getFeatureConfig().useStaticCreateMethodForOneofs()) {
        ResourceNamePatternConfig pattern = getMatchingResourceNamePattern(item, oneofConfig);
        String createMethod = convertToString ? pattern.getFormatMethodName() : pattern.getCreateMethodName();
        ImmutableList<String> formatArgs = getFormatFunctionArgs(context, ImmutableList.copyOf(pattern.getBindingVariables()), item.getInitValueConfig());
        return ResourceNameOneofInitValueView.newBuilder().resourceOneofTypeName(namer.getAndSaveElementResourceTypeName(typeTable, fieldConfig)).createMethodName(createMethod).formatArgs(formatArgs).build();
    } else {
        SingleResourceNameConfig singleResourceNameConfig = getMatchingSingleResourceNameConfig(context, item, oneofConfig);
        FieldConfig singleResourceNameFieldConfig = fieldConfig.withResourceNameConfig(singleResourceNameConfig);
        ResourceNameInitValueView initView = createResourceNameInitValueView(context, singleResourceNameFieldConfig, item).convertToString(convertToString).build();
        return ResourceNameOneofInitValueView.newBuilder().resourceOneofTypeName(namer.getAndSaveElementResourceTypeName(typeTable, fieldConfig)).specificResourceNameView(initView).build();
    }
}
Also used : ResourceNamePatternConfig(com.google.api.codegen.config.ResourceNamePatternConfig) RepeatedResourceNameInitValueView(com.google.api.codegen.viewmodel.RepeatedResourceNameInitValueView) ResourceNameInitValueView(com.google.api.codegen.viewmodel.ResourceNameInitValueView) ResourceNameOneofConfig(com.google.api.codegen.config.ResourceNameOneofConfig) FieldConfig(com.google.api.codegen.config.FieldConfig) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig)

Aggregations

FieldConfig (com.google.api.codegen.config.FieldConfig)40 MethodModel (com.google.api.codegen.config.MethodModel)16 ArrayList (java.util.ArrayList)15 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)14 FieldModel (com.google.api.codegen.config.FieldModel)11 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)11 MethodConfig (com.google.api.codegen.config.MethodConfig)7 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)7 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)6 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)5 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)5 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)5 InitCodeContext (com.google.api.codegen.metacode.InitCodeContext)4 SymbolTable (com.google.api.codegen.util.SymbolTable)4 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)4 MethodContext (com.google.api.codegen.config.MethodContext)3 InitCodeNode (com.google.api.codegen.metacode.InitCodeNode)3 GrpcStreamingType (com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType)2 ResourceNameConfig (com.google.api.codegen.config.ResourceNameConfig)2 ResourceNameMessageConfigs (com.google.api.codegen.config.ResourceNameMessageConfigs)2