use of org.eclipse.vorto.plugin.generator.ICodeGenerator 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);
}
}
Aggregations