use of org.eclipse.vorto.codegen.spi.model.Generator in project vorto by eclipse.
the class VortoService method generate.
public IGenerationResult generate(String key, String namespace, String name, String version, Map<String, String> parameters, Optional<String> headerAuth) {
LOGGER.info(String.format("Generating for Platform [%s] and Model [%s.%s:%s]", key, namespace, name, version));
Generator generator = repo.get(key).orElseThrow(GatewayUtils.notFound(String.format("[Generator %s]", key)));
InformationModel model = getModel(namespace, name, version, headerAuth).orElseThrow(GatewayUtils.notFound(String.format("[Model %s.%s:%s]", namespace, name, version)));
List<MappingModel> mappings = getMappings(key, namespace, name, version, headerAuth);
InvocationContext invocationContext = new InvocationContext(mappings, repo.newGeneratorLookup(), parameters);
try {
final ModelId modelId = new ModelId(name, namespace, version);
List<Attachment> attachments = modelRepository.getAttachments(modelId);
Optional<Attachment> importedFile = attachments.stream().filter(attachment -> attachment.getTagById(Attachment.TAG_IMPORTED.getLabel()) != null).findAny();
if (importedFile.isPresent()) {
byte[] importedFileContent = modelRepository.downloadAttachment(modelId, importedFile.get().getFilename());
invocationContext.setImportedFile(new FileContent(importedFile.get().getFilename(), importedFileContent));
}
} catch (Exception ex) {
// do logging
}
return generate(generator.getInstance(), model, invocationContext);
}
use of org.eclipse.vorto.codegen.spi.model.Generator in project vorto by eclipse.
the class VortoService method generate.
public IGenerationResult generate(ModelContent model, String pluginkey, Map<String, String> params) {
LOGGER.info(String.format("Generating for [%s]", model.getRoot().getPrettyFormat()));
Model converted = converter.convert(model, Optional.empty());
Generator generator = repo.get(pluginkey).orElseThrow(GatewayUtils.notFound(String.format("[Generator %s]", pluginkey)));
InvocationContext invocationContext = InvocationContext.simpleInvocationContext(params);
InformationModel infomodel = Utils.toInformationModel(converted);
return generate(generator.getInstance(), infomodel, invocationContext);
}
Aggregations