Search in sources :

Example 1 with IGenerationResult

use of org.eclipse.vorto.plugin.generator.IGenerationResult in project vorto by eclipse.

the class GeneratorExecutionHandler method handleRequest.

@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
    ObjectMapper mapper = ObjectMapperFactory.getInstance();
    ApiGatewayRequest request = ApiGatewayRequest.createFromJson(input);
    Optional<ICodeGenerator> generator = generators.stream().filter(gen -> gen.getMeta().getKey().equals(request.getPathParam(PLUGINKEY))).findAny();
    if (!generator.isPresent()) {
        objectMapper.writeValue(output, createHttpReponse(404));
    }
    ModelContent modelContent = mapper.readValue(request.getInput(), ModelContent.class);
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    Model converted = converter.convert(modelContent, Optional.empty());
    InvocationContext invocationContext = InvocationContext.simpleInvocationContext(request.getQueryParams());
    InformationModel infomodel = org.eclipse.vorto.plugin.utils.Utils.toInformationModel(converted);
    try {
        IGenerationResult generatorResult = generator.get().generate(infomodel, invocationContext);
        ApiGatewayResponse validResponse = createResponse(generatorResult);
        OutputStreamWriter writer = new OutputStreamWriter(output, "UTF-8");
        writer.write(objectMapper.writeValueAsString(validResponse));
        writer.close();
    } catch (GeneratorException e) {
        ApiGatewayResponse response = createHttpReponse(500);
        objectMapper.writeValue(output, response);
    }
}
Also used : RequestStreamHandler(com.amazonaws.services.lambda.runtime.RequestStreamHandler) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) Context(com.amazonaws.services.lambda.runtime.Context) EclipseHonoGenerator(org.eclipse.vorto.codegen.hono.EclipseHonoGenerator) ApiGatewayRequest(org.eclipse.vorto.plugin.utils.ApiGatewayRequest) ApiGatewayResponse(org.eclipse.vorto.plugin.utils.ApiGatewayResponse) Model(org.eclipse.vorto.core.api.model.model.Model) EclipseDittoGenerator(org.eclipse.vorto.codegen.ditto.EclipseDittoGenerator) HashSet(java.util.HashSet) ObjectMapperFactory(org.eclipse.vorto.plugin.generator.adapter.ObjectMapperFactory) ICodeGenerator(org.eclipse.vorto.plugin.generator.ICodeGenerator) OutputStreamWriter(java.io.OutputStreamWriter) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) OutputStream(java.io.OutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BoschIoTSuiteGenerator(org.eclipse.vorto.codegen.bosch.BoschIoTSuiteGenerator) Set(java.util.Set) IOException(java.io.IOException) GeneratorException(org.eclipse.vorto.plugin.generator.GeneratorException) OpenAPIGenerator(org.eclipse.vorto.codegen.openapi.OpenAPIGenerator) ModelContent(org.eclipse.vorto.model.ModelContent) InvocationContext(org.eclipse.vorto.plugin.generator.InvocationContext) JSONSchemaGenerator(org.eclipse.vorto.codegen.jsonschema.JSONSchemaGenerator) ModelContentToEcoreConverter(org.eclipse.vorto.model.conversion.ModelContentToEcoreConverter) Optional(java.util.Optional) InputStream(java.io.InputStream) ModelContent(org.eclipse.vorto.model.ModelContent) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) ModelContentToEcoreConverter(org.eclipse.vorto.model.conversion.ModelContentToEcoreConverter) ICodeGenerator(org.eclipse.vorto.plugin.generator.ICodeGenerator) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) Model(org.eclipse.vorto.core.api.model.model.Model) OutputStreamWriter(java.io.OutputStreamWriter) InvocationContext(org.eclipse.vorto.plugin.generator.InvocationContext) GeneratorException(org.eclipse.vorto.plugin.generator.GeneratorException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiGatewayResponse(org.eclipse.vorto.plugin.utils.ApiGatewayResponse) ApiGatewayRequest(org.eclipse.vorto.plugin.utils.ApiGatewayRequest)

Example 2 with IGenerationResult

use of org.eclipse.vorto.plugin.generator.IGenerationResult in project vorto by eclipse.

the class EclipseHonoJavaGeneratorTest method testConnectorGeneratedMQTTClient.

/*
   * -----Below test cases are specific to Connector related files-------
   */
/*
   * Test case for checking whether the MQTT client generated contains the models which are listed
   * in the information model
   * 
   */
@Test
public void testConnectorGeneratedMQTTClient() throws GeneratorException, IOException, URISyntaxException {
    IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext());
    File defaultFileHonoDataService = new File(getClass().getClassLoader().getResource("defaultFileFormat/HonoDataService_MQTT.java").toURI());
    File defaultFileHonoMqttClient = new File(getClass().getClassLoader().getResource("defaultFileFormat/HonoMqttClient.java").toURI());
    Generated generatedFileHonoDataService = zipFileReader(generationResult, "HonoDataService", ".java");
    Generated generatedFileHonoMqttClient = zipFileReader(generationResult, "HonoMqttClient", ".java");
    // assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFileHonoDataService)),
    // new String(generatedFileHonoDataService.getContent(), "utf-8"));
    assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFileHonoMqttClient)), new String(generatedFileHonoMqttClient.getContent(), "utf-8"));
}
Also used : Generated(org.eclipse.vorto.plugin.generator.utils.Generated) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) File(java.io.File) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Example 3 with IGenerationResult

use of org.eclipse.vorto.plugin.generator.IGenerationResult in project vorto by eclipse.

the class EclipseHonoJavaGeneratorTest method checkAPIGenerationOfEnumModel.

/*
   * Test case for checking whether the datatype related java file has the enum values specified in
   * the input datatype file.
   * 
   */
@Test
public void checkAPIGenerationOfEnumModel() throws Exception {
    IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext());
    Generated generatedfile = zipFileReader(generationResult, "UnitEnum", ".java");
    File defaultFile = new File(getClass().getClassLoader().getResource("defaultFileFormat/ValidEnum.java").toURI());
    assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFile)), new String(generatedfile.getContent(), "utf-8"));
}
Also used : Generated(org.eclipse.vorto.plugin.generator.utils.Generated) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) File(java.io.File) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Example 4 with IGenerationResult

use of org.eclipse.vorto.plugin.generator.IGenerationResult in project vorto by eclipse.

the class EclipseHonoJavaGeneratorTest method checkAPIGenerationOfEntityModel.

/*
   * Test case for checking whether the datatype related java file has the entity values specified
   * in the input datatype file.
   * 
   */
@Test
public void checkAPIGenerationOfEntityModel() throws Exception {
    IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext());
    Generated generatedfile = zipFileReader(generationResult, "UnitEntity", ".java");
    File defaultFile = new File(getClass().getClassLoader().getResource("defaultFileFormat/ValidEntity.java").toURI());
    assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFile)), new String(generatedfile.getContent(), "utf-8"));
}
Also used : Generated(org.eclipse.vorto.plugin.generator.utils.Generated) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) File(java.io.File) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Example 5 with IGenerationResult

use of org.eclipse.vorto.plugin.generator.IGenerationResult in project vorto by eclipse.

the class EclipseHonoJavaGeneratorTest method testClientAppGeneratedModels.

/*
   * -----Below test cases are specific to Client App related files-------
   */
/*
   * Test case for checking whether the client App generated contains the models which are listed in
   * the information model
   * 
   */
@Test
public void testClientAppGeneratedModels() throws GeneratorException, IOException, URISyntaxException {
    IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext());
    Generated generatedfile = zipFileReader(generationResult, "MySensorApp", ".java");
    File defaultFile = new File(getClass().getClassLoader().getResource("defaultFileFormat/MainApp.java").toURI());
    assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFile)), new String(generatedfile.getContent(), "utf-8"));
}
Also used : Generated(org.eclipse.vorto.plugin.generator.utils.Generated) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) File(java.io.File) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Aggregations

IGenerationResult (org.eclipse.vorto.plugin.generator.IGenerationResult)34 Test (org.junit.Test)33 AbstractGeneratorTest (org.eclipse.vorto.plugin.AbstractGeneratorTest)32 Generated (org.eclipse.vorto.plugin.generator.utils.Generated)27 File (java.io.File)17 HashMap (java.util.HashMap)7 InvocationContext (org.eclipse.vorto.plugin.generator.InvocationContext)4 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)3 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)3 HashSet (java.util.HashSet)2 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)2 Context (com.amazonaws.services.lambda.runtime.Context)1 RequestStreamHandler (com.amazonaws.services.lambda.runtime.RequestStreamHandler)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Optional (java.util.Optional)1