Search in sources :

Example 1 with DiscoGapicInterfaceContext

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

the class JavaDiscoGapicResourceNameToViewTransformer method transform.

@Override
public List<ViewModel> transform(DiscoApiModel apiModel, GapicProductConfig productConfig) {
    List<ViewModel> surfaceRequests = new ArrayList<>();
    String packageName = productConfig.getPackageName();
    SurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
    DiscoGapicInterfaceContext context = DiscoGapicInterfaceContext.createWithoutInterface(apiModel, productConfig, createTypeTable(productConfig.getPackageName(), surfaceNamer), surfaceNamer, JavaFeatureConfig.create(productConfig));
    // Keep track of which name patterns have been generated to avoid duplicate classes.
    Set<String> namePatterns = new HashSet<>();
    for (String interfaceName : productConfig.getInterfaceConfigMap().keySet()) {
        SchemaTransformationContext requestContext = SchemaTransformationContext.create(interfaceName, context.getSchemaTypeTable(), context);
        // Maps a canonical resource name pattern to any method that uses that pattern.
        Map<String, Method> namePatternsToMethod = new HashMap<>();
        for (MethodConfig methodConfig : productConfig.getInterfaceConfigMap().get(interfaceName).getMethodConfigs()) {
            Method method = ((DiscoveryMethodModel) methodConfig.getMethodModel()).getDiscoMethod();
            namePatternsToMethod.put(DiscoGapicParser.getCanonicalPath(method.flatPath()), method);
        }
        for (SingleResourceNameConfig nameConfig : productConfig.getInterfaceConfigMap().get(interfaceName).getSingleResourceNameConfigs()) {
            String namePattern = nameConfig.getNamePattern();
            if (namePatterns.contains(namePattern)) {
                continue;
            }
            Method method = namePatternsToMethod.get(namePattern);
            StaticLangApiResourceNameView resourceNameView = generateResourceNameClass(requestContext, method, nameConfig);
            surfaceRequests.add(generateResourceNameFile(requestContext, resourceNameView));
            namePatterns.add(nameConfig.getNamePattern());
        }
    }
    Collections.sort(surfaceRequests, new Comparator<ViewModel>() {

        @Override
        public int compare(ViewModel o1, ViewModel o2) {
            return String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath());
        }
    });
    return surfaceRequests;
}
Also used : SchemaTransformationContext(com.google.api.codegen.discogapic.SchemaTransformationContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) Method(com.google.api.codegen.discovery.Method) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) StaticLangApiResourceNameView(com.google.api.codegen.viewmodel.StaticLangApiResourceNameView) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig) MethodConfig(com.google.api.codegen.config.MethodConfig) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) DiscoGapicInterfaceContext(com.google.api.codegen.config.DiscoGapicInterfaceContext) HashSet(java.util.HashSet)

Example 2 with DiscoGapicInterfaceContext

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

the class JavaDiscoGapicRequestToViewTransformer method transform.

@Override
public List<ViewModel> transform(DiscoApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceRequests = new ArrayList<>();
    String packageName = productConfig.getPackageName();
    SurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        DiscoGapicInterfaceContext context = JavaDiscoGapicSurfaceTransformer.newInterfaceContext(apiInterface, productConfig, surfaceNamer, createTypeTable(productConfig.getPackageName()));
        for (DiscoveryMethodModel method : context.getSupportedMethods()) {
            RequestObjectParamView params = getRequestObjectParams(context, method);
            SchemaTransformationContext requestContext = SchemaTransformationContext.create(method.getFullName(), context.getSchemaTypeTable(), context);
            StaticLangApiMessageView requestView = generateRequestClass(requestContext, method, params);
            surfaceRequests.add(generateRequestFile(requestContext, requestView));
        }
    }
    surfaceRequests.sort((ViewModel o1, ViewModel o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath()));
    return surfaceRequests;
}
Also used : SchemaTransformationContext(com.google.api.codegen.discogapic.SchemaTransformationContext) InterfaceModel(com.google.api.codegen.config.InterfaceModel) StaticLangApiMessageView(com.google.api.codegen.viewmodel.StaticLangApiMessageView) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) DiscoGapicInterfaceContext(com.google.api.codegen.config.DiscoGapicInterfaceContext)

Example 3 with DiscoGapicInterfaceContext

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

the class JavaDiscoGapicSchemaToViewTransformer method transform.

@Override
public List<ViewModel> transform(DiscoApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceSchemas = new ArrayList<>();
    String packageName = productConfig.getPackageName();
    JavaSurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
    DiscoGapicInterfaceContext context = DiscoGapicInterfaceContext.createWithoutInterface(model, productConfig, createTypeTable(productConfig.getPackageName(), surfaceNamer), surfaceNamer, JavaFeatureConfig.create(productConfig));
    for (Schema schema : context.getDocument().schemas().values()) {
        Map<SchemaTransformationContext, StaticLangApiMessageView> contextViews = new TreeMap<>(SchemaTransformationContext.comparator);
        generateSchemaClasses(contextViews, context, schema);
        for (Map.Entry<SchemaTransformationContext, StaticLangApiMessageView> contextView : contextViews.entrySet()) {
            surfaceSchemas.add(generateSchemaFile(contextView.getKey(), contextView.getValue()));
        }
    }
    Collections.sort(surfaceSchemas, new Comparator<ViewModel>() {

        @Override
        public int compare(ViewModel o1, ViewModel o2) {
            return String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath());
        }
    });
    return surfaceSchemas;
}
Also used : SchemaTransformationContext(com.google.api.codegen.discogapic.SchemaTransformationContext) Schema(com.google.api.codegen.discovery.Schema) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) TreeMap(java.util.TreeMap) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) StaticLangApiMessageView(com.google.api.codegen.viewmodel.StaticLangApiMessageView) Map(java.util.Map) TreeMap(java.util.TreeMap) DiscoGapicInterfaceContext(com.google.api.codegen.config.DiscoGapicInterfaceContext)

Aggregations

DiscoGapicInterfaceContext (com.google.api.codegen.config.DiscoGapicInterfaceContext)3 SchemaTransformationContext (com.google.api.codegen.discogapic.SchemaTransformationContext)3 JavaSurfaceNamer (com.google.api.codegen.transformer.java.JavaSurfaceNamer)3 ViewModel (com.google.api.codegen.viewmodel.ViewModel)3 ArrayList (java.util.ArrayList)3 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)2 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)2 StaticLangApiMessageView (com.google.api.codegen.viewmodel.StaticLangApiMessageView)2 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)1 Method (com.google.api.codegen.discovery.Method)1 Schema (com.google.api.codegen.discovery.Schema)1 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)1 StaticLangApiResourceNameView (com.google.api.codegen.viewmodel.StaticLangApiResourceNameView)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1