use of org.eclipse.vorto.codegen.api.FileContent 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);
}
Aggregations