use of org.eclipse.vorto.model.conversion.ModelContentToEcoreConverter 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);
}
}
use of org.eclipse.vorto.model.conversion.ModelContentToEcoreConverter in project vorto by eclipse.
the class ModelContentDeserializationTest method testDeserializeWithDictionaryType.
@Test
public void testDeserializeWithDictionaryType() throws Exception {
ModelContent content = ObjectMapperFactory.getInstance().readValue(new ClassPathResource("json/TestModelContent_dictionary.json").getInputStream(), ModelContent.class);
assertNotNull(content);
ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
FunctionblockModel model = (FunctionblockModel) converter.convert(content, Optional.empty());
assertNotNull(model.getFunctionblock().getStatus().getProperties().get(0).getType() instanceof DictionaryPropertyType);
}
use of org.eclipse.vorto.model.conversion.ModelContentToEcoreConverter in project vorto by eclipse.
the class ModelContentDeserializationTest method testDeserializeWithPrimitiveType.
@Test
public void testDeserializeWithPrimitiveType() throws Exception {
ModelContent content = ObjectMapperFactory.getInstance().readValue(new ClassPathResource("json/TestModelContent_primitive.json").getInputStream(), ModelContent.class);
assertNotNull(content);
ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
FunctionblockModel model = (FunctionblockModel) converter.convert(content, Optional.empty());
assertNotNull(model.getFunctionblock().getStatus().getProperties().get(0).getType() instanceof PrimitivePropertyType);
}
Aggregations