Search in sources :

Example 26 with FieldModel

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

the class DynamicLangApiMethodTransformer method removePageTokenFieldConfig.

private Iterable<FieldConfig> removePageTokenFieldConfig(GapicMethodContext context, Iterable<FieldConfig> fieldConfigs) {
    MethodConfig methodConfig = context.getMethodConfig();
    if (methodConfig == null || !methodConfig.isPageStreaming()) {
        return fieldConfigs;
    }
    final FieldModel requestTokenField = methodConfig.getPageStreaming().getRequestTokenField();
    return Iterables.filter(fieldConfigs, new Predicate<FieldConfig>() {

        @Override
        public boolean apply(FieldConfig fieldConfig) {
            return !fieldConfig.getField().equals(requestTokenField);
        }
    });
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) FieldConfig(com.google.api.codegen.config.FieldConfig) FieldModel(com.google.api.codegen.config.FieldModel)

Example 27 with FieldModel

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

the class DynamicLangApiMethodTransformer method generateRequestObjectParam.

private RequestObjectParamView generateRequestObjectParam(GapicMethodContext context, FieldConfig fieldConfig) {
    SurfaceNamer namer = context.getNamer();
    FeatureConfig featureConfig = context.getFeatureConfig();
    ModelTypeTable typeTable = context.getTypeTable();
    FieldModel field = fieldConfig.getField();
    Iterable<FieldModel> requiredFields = context.getMethodConfig().getRequiredFields();
    boolean isRequired = false;
    for (FieldModel f : requiredFields) {
        if (f.getSimpleName().equals(field.getSimpleName())) {
            isRequired = true;
        }
    }
    RequestObjectParamView.Builder param = RequestObjectParamView.newBuilder();
    param.name(namer.getVariableName(field));
    param.keyName(namer.getFieldKey(field));
    param.nameAsMethodName(namer.getFieldGetFunctionName(featureConfig, fieldConfig));
    param.typeName(typeTable.getAndSaveNicknameFor(field));
    param.elementTypeName(typeTable.getAndSaveNicknameForElementType(field));
    param.setCallName(namer.getFieldSetFunctionName(featureConfig, fieldConfig));
    param.addCallName(namer.getFieldAddFunctionName(field));
    param.getCallName(namer.getFieldGetFunctionName(featureConfig, fieldConfig));
    param.isMap(field.isMap());
    param.isArray(!field.isMap() && field.isRepeated());
    param.isPrimitive(field.isPrimitive());
    param.isOptional(!isRequired);
    if (!isRequired) {
        param.optionalDefault(namer.getOptionalFieldDefaultValue(fieldConfig, context));
    }
    return param.build();
}
Also used : FieldModel(com.google.api.codegen.config.FieldModel) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView)

Example 28 with FieldModel

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

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

the class PathTemplateTransformer method generateResourceProtos.

public List<ResourceProtoView> generateResourceProtos(GapicInterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    ResourceNameMessageConfigs resourceConfigs = context.getProductConfig().getResourceNameMessageConfigs();
    ListMultimap<String, FieldModel> fieldsByMessage = resourceConfigs.getFieldsWithResourceNamesByMessage();
    Map<String, FieldConfig> fieldConfigMap = context.getProductConfig().getDefaultResourceNameFieldConfigMap();
    List<ResourceProtoView> protos = new ArrayList<>();
    for (Entry<String, Collection<FieldModel>> entry : fieldsByMessage.asMap().entrySet()) {
        String msgName = entry.getKey();
        Collection<FieldModel> fields = new ArrayList<>(entry.getValue());
        ResourceProtoView.Builder protoBuilder = ResourceProtoView.newBuilder();
        protoBuilder.protoClassName(namer.getTypeNameConverter().getTypeName(msgName).getNickname());
        List<ResourceProtoFieldView> fieldViews = new ArrayList<>();
        for (FieldModel field : fields) {
            FieldConfig fieldConfig = fieldConfigMap.get(field.getFullName());
            String fieldTypeSimpleName = namer.getResourceTypeName(fieldConfig.getResourceNameConfig());
            String fieldTypeName = context.getImportTypeTable().getAndSaveNicknameForTypedResourceName(fieldConfig, fieldTypeSimpleName);
            if (field.isRepeated()) {
                fieldTypeName = fieldTypeName.replaceFirst("IEnumerable", "ResourceNameList");
            }
            String fieldDocTypeName = fieldTypeName.replace('<', '{').replace('>', '}');
            String fieldElementTypeName = context.getImportTypeTable().getAndSaveNicknameForResourceNameElementType(fieldConfig, fieldTypeSimpleName);
            ResourceProtoFieldView fieldView = ResourceProtoFieldView.newBuilder().typeName(fieldTypeName).parseMethodTypeName(namer.getPackageName() + "." + fieldTypeName).docTypeName(fieldDocTypeName).elementTypeName(fieldElementTypeName).isAny(fieldConfig.getResourceNameType() == ResourceNameType.ANY).isRepeated(field.isRepeated()).isOneof(fieldConfig.getResourceNameType() == ResourceNameType.ONEOF).propertyName(namer.getResourceNameFieldGetFunctionName(fieldConfig)).underlyingPropertyName(namer.publicMethodName(Name.from(field.getSimpleName()))).build();
            fieldViews.add(fieldView);
        }
        protoBuilder.fields(fieldViews);
        protos.add(protoBuilder.build());
    }
    Collections.sort(protos, new Comparator<ResourceProtoView>() {

        @Override
        public int compare(ResourceProtoView a, ResourceProtoView b) {
            return a.protoClassName().compareTo(b.protoClassName());
        }
    });
    return protos;
}
Also used : FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) ResourceNameMessageConfigs(com.google.api.codegen.config.ResourceNameMessageConfigs) ResourceProtoView(com.google.api.codegen.viewmodel.ResourceProtoView) ResourceProtoFieldView(com.google.api.codegen.viewmodel.ResourceProtoFieldView) Collection(java.util.Collection) FieldModel(com.google.api.codegen.config.FieldModel)

Example 30 with FieldModel

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

Aggregations

FieldModel (com.google.api.codegen.config.FieldModel)44 MethodConfig (com.google.api.codegen.config.MethodConfig)13 ArrayList (java.util.ArrayList)13 ImmutableList (com.google.common.collect.ImmutableList)11 FieldConfig (com.google.api.codegen.config.FieldConfig)9 MethodModel (com.google.api.codegen.config.MethodModel)8 SimpleParamDocView (com.google.api.codegen.viewmodel.SimpleParamDocView)7 ParamDocView (com.google.api.codegen.viewmodel.ParamDocView)6 BatchingConfig (com.google.api.codegen.config.BatchingConfig)4 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)4 DynamicLangDefaultableParamView (com.google.api.codegen.viewmodel.DynamicLangDefaultableParamView)4 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)3 Name (com.google.api.codegen.util.Name)3 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)2 GenericFieldSelector (com.google.api.codegen.config.GenericFieldSelector)2 Schema (com.google.api.codegen.discovery.Schema)2 SymbolTable (com.google.api.codegen.util.SymbolTable)2 TypeName (com.google.api.codegen.util.TypeName)2 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)2 StaticLangApiMessageView (com.google.api.codegen.viewmodel.StaticLangApiMessageView)2