Search in sources :

Example 16 with ClassTemplateSpec

use of com.linkedin.pegasus.generator.spec.ClassTemplateSpec in project rest.li by linkedin.

the class RequestBuilderSpecGenerator method generateFinders.

private List<RootBuilderMethodSpec> generateFinders(RootBuilderSpec rootBuilderSpec, FinderSchemaArray finderSchemas, String keyClass, String valueClass, String resourceName, List<String> pathKeys, Map<String, String> pathKeyTypes) {
    List<RootBuilderMethodSpec> finderSpecList = new ArrayList<RootBuilderMethodSpec>();
    if (finderSchemas != null) {
        String baseBuilderClass = getBuilderBase(ResourceMethod.FINDER);
        for (FinderSchema finder : finderSchemas) {
            String finderName = finder.getName();
            String builderName = CodeUtil.capitalize(resourceName) + "FindBy" + CodeUtil.capitalize(finderName) + getMethodBuilderSuffix();
            FinderBuilderSpec finderBuilderClass = generateFinderRequestBuilder(rootBuilderSpec.getResource(), baseBuilderClass, keyClass, valueClass, builderName, rootBuilderSpec.getNamespace(), finderName, finder);
            generatePathKeyBindingMethods(pathKeys, finderBuilderClass, pathKeyTypes);
            if (finder.getParameters() != null) {
                generateQueryParamBindingMethods(finder.getParameters(), finderBuilderClass);
            }
            // process custom metadata
            if (finder.getMetadata() != null) {
                String metadataClass = finder.getMetadata().getType();
                ClassTemplateSpec metadataClassSpec = classToTemplateSpec(metadataClass);
                finderBuilderClass.setMetadataType(metadataClassSpec);
            }
            String finderMethod = "findBy" + CodeUtil.capitalize(finderName);
            RootBuilderMethodSpec methodSpec = new RootBuilderMethodSpec(finderMethod, finder.getDoc(), finderBuilderClass, rootBuilderSpec);
            finderBuilderClass.setRootBuilderMethod(methodSpec);
            finderSpecList.add(methodSpec);
        }
    }
    return finderSpecList;
}
Also used : ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec) RootBuilderMethodSpec(com.linkedin.restli.tools.clientgen.builderspec.RootBuilderMethodSpec) ArrayList(java.util.ArrayList) FinderSchema(com.linkedin.restli.restspec.FinderSchema) FinderBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.FinderBuilderSpec)

Example 17 with ClassTemplateSpec

use of com.linkedin.pegasus.generator.spec.ClassTemplateSpec in project rest.li by linkedin.

the class RequestBuilderSpecGenerator method generateRestMethodRequestBuilder.

private RestMethodBuilderSpec generateRestMethodRequestBuilder(ResourceSchema resource, String baseBuilderClass, String keyClass, String valueClass, String requestBuilderName, String clientPackage, RestMethodSchema schema) {
    // this method applies to REST methods
    RestMethodBuilderSpec restMethodBuilderClass = new RestMethodBuilderSpec(clientPackage, requestBuilderName, baseBuilderClass, resource, schema.getMethod());
    restMethodBuilderClass.setAnnotations(schema.getAnnotations() == null ? null : schema.getAnnotations().data());
    final ClassTemplateSpec keyClassSpec = classToTemplateSpec(keyClass);
    restMethodBuilderClass.setKeyClass(keyClassSpec);
    final ClassTemplateSpec valueClassSpec = classToTemplateSpec(valueClass);
    restMethodBuilderClass.setValueClass(valueClassSpec);
    registerBuilderSpec(restMethodBuilderClass);
    return restMethodBuilderClass;
}
Also used : ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec) RestMethodBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.RestMethodBuilderSpec)

Aggregations

ClassTemplateSpec (com.linkedin.pegasus.generator.spec.ClassTemplateSpec)17 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)5 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)4 DataSchema (com.linkedin.data.schema.DataSchema)4 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)4 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)4 ComplexDataSchema (com.linkedin.data.schema.ComplexDataSchema)3 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)3 FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)3 PrimitiveDataSchema (com.linkedin.data.schema.PrimitiveDataSchema)3 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)3 MapDataSchema (com.linkedin.data.schema.MapDataSchema)2 CustomInfoSpec (com.linkedin.pegasus.generator.spec.CustomInfoSpec)2 ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)2 FinderBuilderSpec (com.linkedin.restli.tools.clientgen.builderspec.FinderBuilderSpec)2 DataMap (com.linkedin.data.DataMap)1 DataSchemaLocation (com.linkedin.data.schema.DataSchemaLocation)1 RecordTemplateSpec (com.linkedin.pegasus.generator.spec.RecordTemplateSpec)1 FinderSchema (com.linkedin.restli.restspec.FinderSchema)1 ActionBuilderSpec (com.linkedin.restli.tools.clientgen.builderspec.ActionBuilderSpec)1