Search in sources :

Example 1 with Client

use of com.spectralogic.ds3autogen.go.models.client.Client in project ds3_autogen by SpectraLogic.

the class GoCodeGenerator method generateClient.

/**
     * Generates the client files. Each file contains the client commands separated by {@link HttpVerb}
     */
private void generateClient(final ImmutableList<Ds3Request> ds3Requests) throws IOException, TemplateException {
    for (final HttpVerb httpVerb : HttpVerb.values()) {
        final ImmutableList<Ds3Request> filteredRequests = ds3Requests.stream().filter(ds3Request -> ds3Request.getHttpVerb() == httpVerb).collect(GuavaCollectors.immutableList());
        generateClientFile(filteredRequests, httpVerb);
    }
}
Also used : Client(com.spectralogic.ds3autogen.go.models.client.Client) ConverterUtil.isEnum(com.spectralogic.ds3autogen.utils.ConverterUtil.isEnum) GetObjectResponseGenerator(com.spectralogic.ds3autogen.go.generators.response.GetObjectResponseGenerator) ResponseModelGenerator(com.spectralogic.ds3autogen.go.generators.response.ResponseModelGenerator) Ds3RequestClassificationUtil(com.spectralogic.ds3autogen.utils.Ds3RequestClassificationUtil) TypeModelGenerator(com.spectralogic.ds3autogen.go.generators.type.TypeModelGenerator) LoggerFactory(org.slf4j.LoggerFactory) NoResponseGenerator(com.spectralogic.ds3autogen.go.generators.response.NoResponseGenerator) BaseTypeGenerator(com.spectralogic.ds3autogen.go.generators.type.BaseTypeGenerator) Type(com.spectralogic.ds3autogen.go.models.type.Type) Response(com.spectralogic.ds3autogen.go.models.response.Response) StringUtils.uncapitalize(org.apache.commons.lang3.StringUtils.uncapitalize) ResponsePayloadUtil.hasResponsePayload(com.spectralogic.ds3autogen.utils.ResponsePayloadUtil.hasResponsePayload) ConverterUtil.removeUnusedTypes(com.spectralogic.ds3autogen.utils.ConverterUtil.removeUnusedTypes) CodeGenerator(com.spectralogic.ds3autogen.api.CodeGenerator) Ds3Request(com.spectralogic.ds3autogen.api.models.apispec.Ds3Request) BaseClientGenerator(com.spectralogic.ds3autogen.go.generators.client.BaseClientGenerator) ImmutableList(com.google.common.collect.ImmutableList) Request(com.spectralogic.ds3autogen.go.models.request.Request) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3DocSpec(com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec) OutputStreamWriter(java.io.OutputStreamWriter) com.spectralogic.ds3autogen.go.generators.request(com.spectralogic.ds3autogen.go.generators.request) Path(java.nio.file.Path) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) BaseResponseGenerator(com.spectralogic.ds3autogen.go.generators.response.BaseResponseGenerator) IOException(java.io.IOException) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) freemarker.template(freemarker.template) ClientModelGenerator(com.spectralogic.ds3autogen.go.generators.client.ClientModelGenerator) ConverterUtil.isEmpty(com.spectralogic.ds3autogen.utils.ConverterUtil.isEmpty) GuavaCollectors(com.spectralogic.ds3autogen.utils.collections.GuavaCollectors) Paths(java.nio.file.Paths) Writer(java.io.Writer) Ds3TypeClassificationUtil.isJobsApiBean(com.spectralogic.ds3autogen.utils.Ds3TypeClassificationUtil.isJobsApiBean) HttpVerb(com.spectralogic.ds3autogen.api.models.enums.HttpVerb) JobListGenerator(com.spectralogic.ds3autogen.go.generators.type.JobListGenerator) Ds3Request(com.spectralogic.ds3autogen.api.models.apispec.Ds3Request) HttpVerb(com.spectralogic.ds3autogen.api.models.enums.HttpVerb)

Example 2 with Client

use of com.spectralogic.ds3autogen.go.models.client.Client in project ds3_autogen by SpectraLogic.

the class GoCodeGenerator method generateClientFile.

/**
     * Generates a client file for commands that have the specified {@link HttpVerb}
     */
private void generateClientFile(final ImmutableList<Ds3Request> ds3Requests, final HttpVerb httpVerb) throws IOException, TemplateException {
    if (isEmpty(ds3Requests)) {
        LOG.info("There were no commands with verb {} to generate the {} client file", getClientFileName(httpVerb), httpVerb.toString());
    }
    final Template tmpl = config.getTemplate("client/client_template.ftl");
    final ClientModelGenerator<?> generator = new BaseClientGenerator();
    final Client client = generator.generate(ds3Requests);
    final Path path = destDir.resolve(BASE_PROJECT_PATH.resolve(Paths.get(getClientFileName(httpVerb) + ".go")));
    LOG.info("Getting OutputStream for file: {}", path.toString());
    try (final OutputStream outputStream = fileUtils.getOutputFile(path);
        final Writer writer = new OutputStreamWriter(outputStream)) {
        tmpl.process(client, writer);
    }
}
Also used : Path(java.nio.file.Path) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Client(com.spectralogic.ds3autogen.go.models.client.Client) BaseClientGenerator(com.spectralogic.ds3autogen.go.generators.client.BaseClientGenerator) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Aggregations

BaseClientGenerator (com.spectralogic.ds3autogen.go.generators.client.BaseClientGenerator)2 Client (com.spectralogic.ds3autogen.go.models.client.Client)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 Path (java.nio.file.Path)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 CodeGenerator (com.spectralogic.ds3autogen.api.CodeGenerator)1 FileUtils (com.spectralogic.ds3autogen.api.FileUtils)1 Ds3ApiSpec (com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec)1 Ds3Request (com.spectralogic.ds3autogen.api.models.apispec.Ds3Request)1 Ds3Type (com.spectralogic.ds3autogen.api.models.apispec.Ds3Type)1 Ds3DocSpec (com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec)1 HttpVerb (com.spectralogic.ds3autogen.api.models.enums.HttpVerb)1 ClientModelGenerator (com.spectralogic.ds3autogen.go.generators.client.ClientModelGenerator)1 com.spectralogic.ds3autogen.go.generators.request (com.spectralogic.ds3autogen.go.generators.request)1 BaseResponseGenerator (com.spectralogic.ds3autogen.go.generators.response.BaseResponseGenerator)1 GetObjectResponseGenerator (com.spectralogic.ds3autogen.go.generators.response.GetObjectResponseGenerator)1 NoResponseGenerator (com.spectralogic.ds3autogen.go.generators.response.NoResponseGenerator)1