Search in sources :

Example 1 with SingleGenerationResult

use of org.eclipse.vorto.plugin.generator.utils.SingleGenerationResult in project vorto by eclipse.

the class OpenAPIGenerator method generate.

@Override
public IGenerationResult generate(final InformationModel infomodel, final InvocationContext context) throws GeneratorException {
    SingleGenerationResult output = new SingleGenerationResult("application/vnd.oai.openapi;version=3.0");
    OpenAPITemplate openAPITemplate = new OpenAPITemplate();
    new GeneratorTaskFromFileTemplate<>(openAPITemplate).generate(infomodel, context, output);
    return output;
}
Also used : OpenAPITemplate(org.eclipse.vorto.codegen.openapi.templates.OpenAPITemplate) SingleGenerationResult(org.eclipse.vorto.plugin.generator.utils.SingleGenerationResult)

Example 2 with SingleGenerationResult

use of org.eclipse.vorto.plugin.generator.utils.SingleGenerationResult in project vorto by eclipse.

the class BoschIoTSuiteGeneratorTest method generateProvisionTrue.

/*
   * Check if provisioning script file is returned when config property is passed as provision to
   * BoschIOTSuiteGenerator
   */
@Test
public void generateProvisionTrue() throws Exception {
    configProperties.put("provision", "true");
    InvocationContext context = new InvocationContext(mappingModels, configProperties);
    SingleGenerationResult singleGenerationResult = (SingleGenerationResult) boschIOTSuiteGenerator.generate(modelProvider(), context);
    assertEquals("Provisioning_MySensor.postman.json", singleGenerationResult.getFileName());
}
Also used : InvocationContext(org.eclipse.vorto.plugin.generator.InvocationContext) SingleGenerationResult(org.eclipse.vorto.plugin.generator.utils.SingleGenerationResult) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Example 3 with SingleGenerationResult

use of org.eclipse.vorto.plugin.generator.utils.SingleGenerationResult in project vorto by eclipse.

the class BoschIoTSuiteGenerator method generate.

@Override
public IGenerationResult generate(InformationModel infomodel, InvocationContext invocationContext) throws GeneratorException {
    GenerationResultZip output = new GenerationResultZip(infomodel, KEY);
    GenerationResultBuilder result = GenerationResultBuilder.from(output);
    String platform = invocationContext.getConfigurationProperties().getOrDefault(KEY_LANGUAGE, "");
    if (platform.equalsIgnoreCase("arduino")) {
        result.append(generateArduino(infomodel, invocationContext));
    } else if (platform.equalsIgnoreCase("python")) {
        result.append(generatePython(infomodel, invocationContext));
    } else if (platform.equalsIgnoreCase("java")) {
        result.append(generateJava(infomodel, invocationContext));
    } else if (invocationContext.getConfigurationProperties().getOrDefault(KEY_PROVISION, "false").equals("true")) {
        SingleGenerationResult singleOutput = new SingleGenerationResult("application/json");
        if (invocationContext.getConfigurationProperties().getOrDefault(KEY_BODY_TEMPLATE, "false").equals("true")) {
            new GeneratorTaskFromFileTemplate<>(REQUEST_TEMPLATE).generate(infomodel, invocationContext, singleOutput);
        } else {
            new GeneratorTaskFromFileTemplate<>(new ProvisionDeviceScriptTemplate(REQUEST_TEMPLATE)).generate(infomodel, invocationContext, singleOutput);
        }
        return singleOutput;
    }
    return output;
}
Also used : GenerationResultZip(org.eclipse.vorto.plugin.generator.utils.GenerationResultZip) GeneratorTaskFromFileTemplate(org.eclipse.vorto.plugin.generator.utils.GeneratorTaskFromFileTemplate) GenerationResultBuilder(org.eclipse.vorto.plugin.generator.utils.GenerationResultBuilder) ProvisionDeviceScriptTemplate(org.eclipse.vorto.codegen.bosch.templates.ProvisionDeviceScriptTemplate) SingleGenerationResult(org.eclipse.vorto.plugin.generator.utils.SingleGenerationResult)

Example 4 with SingleGenerationResult

use of org.eclipse.vorto.plugin.generator.utils.SingleGenerationResult in project vorto by eclipse.

the class EclipseDittoGenerator method generate.

@Override
public IGenerationResult generate(InformationModel infomodel, InvocationContext invocationContext) {
    String target = invocationContext.getConfigurationProperties().getOrDefault("target", "");
    if (THING_JSON.equalsIgnoreCase(target)) {
        SingleGenerationResult output = new SingleGenerationResult("application/json");
        new GeneratorTaskFromFileTemplate<>(DITTO_THING_JSON_TEMPLATE).generate(infomodel, invocationContext, output);
        return output;
    }
    if (JSON_SCHEMA.equalsIgnoreCase(target)) {
        GenerationResultZip zipOutput = new GenerationResultZip(infomodel, GENERATOR_KEY);
        ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<>();
        generator.addTask(new SchemaValidatorTask());
        generator.generate(infomodel, invocationContext, zipOutput);
        GenerationResultBuilder result = GenerationResultBuilder.from(zipOutput);
        return result.build();
    }
    throw new IllegalArgumentException("The request parameter 'target' is required. It must have one of the values ('jsonSchema', " + "'thingJson')");
}
Also used : GenerationResultZip(org.eclipse.vorto.plugin.generator.utils.GenerationResultZip) SchemaValidatorTask(org.eclipse.vorto.codegen.ditto.schema.SchemaValidatorTask) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ChainedCodeGeneratorTask(org.eclipse.vorto.plugin.generator.utils.ChainedCodeGeneratorTask) GenerationResultBuilder(org.eclipse.vorto.plugin.generator.utils.GenerationResultBuilder) SingleGenerationResult(org.eclipse.vorto.plugin.generator.utils.SingleGenerationResult)

Aggregations

SingleGenerationResult (org.eclipse.vorto.plugin.generator.utils.SingleGenerationResult)4 GenerationResultBuilder (org.eclipse.vorto.plugin.generator.utils.GenerationResultBuilder)2 GenerationResultZip (org.eclipse.vorto.plugin.generator.utils.GenerationResultZip)2 ProvisionDeviceScriptTemplate (org.eclipse.vorto.codegen.bosch.templates.ProvisionDeviceScriptTemplate)1 SchemaValidatorTask (org.eclipse.vorto.codegen.ditto.schema.SchemaValidatorTask)1 OpenAPITemplate (org.eclipse.vorto.codegen.openapi.templates.OpenAPITemplate)1 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)1 AbstractGeneratorTest (org.eclipse.vorto.plugin.AbstractGeneratorTest)1 InvocationContext (org.eclipse.vorto.plugin.generator.InvocationContext)1 ChainedCodeGeneratorTask (org.eclipse.vorto.plugin.generator.utils.ChainedCodeGeneratorTask)1 GeneratorTaskFromFileTemplate (org.eclipse.vorto.plugin.generator.utils.GeneratorTaskFromFileTemplate)1 Test (org.junit.Test)1