Search in sources :

Example 1 with JsonValueRepresentation

use of eu.esdihumboldt.hale.io.html.svg.mapping.json.JsonValueRepresentation in project hale by halestudio.

the class MappingExporter method execute.

@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Generate mapping documentation", ProgressIndicator.UNKNOWN);
    // retrieve template URL
    URL templateUrl = getClass().getResource("mapping.html");
    // generate Json representation
    CellJsonExtension ext = new ExtendedCellRepresentation(getAlignment(), getServiceProvider());
    ValueRepresentation rep = new JsonValueRepresentation();
    StringWriter jsonWriter = new StringWriter();
    JsonStreamBuilder json = new JsonStreamBuilder(jsonWriter, true);
    Set<Locale> locales = AlignmentJson.alignmentInfoJSON(getAlignment(), json, getServiceProvider(), getProjectInfo(), ext, rep, Locale.getDefault(), getSourceSchema(), getTargetSchema());
    // create language binding
    String languageJson = getLanguageJson(locales);
    // create template binding
    Map<String, Object> binding = new HashMap<>();
    binding.put("json", jsonWriter.toString());
    String title = (getProjectInfo() != null && getProjectInfo().getName() != null) ? getProjectInfo().getName() : "Mapping documentation";
    binding.put("title", title);
    binding.put("languages", languageJson);
    binding.put("halejsVersion", HALEJS_VERSION);
    // initialize template engine
    GStringTemplateEngine engine = new GStringTemplateEngine();
    // bind and write template
    try (Writer out = new OutputStreamWriter(getTarget().getOutput(), StandardCharsets.UTF_8)) {
        Writable template = engine.createTemplate(templateUrl).make(binding);
        template.writeTo(out);
        reporter.setSuccess(true);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl("Error creating mapping documentation", e));
        reporter.setSuccess(false);
    } finally {
        progress.end();
    }
    return reporter;
}
Also used : Locale(java.util.Locale) JsonValueRepresentation(eu.esdihumboldt.hale.io.html.svg.mapping.json.JsonValueRepresentation) HashMap(java.util.HashMap) ExtendedCellRepresentation(eu.esdihumboldt.hale.io.html.svg.mapping.json.ExtendedCellRepresentation) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) Writable(groovy.lang.Writable) GStringTemplateEngine(groovy.text.GStringTemplateEngine) CellJsonExtension(eu.esdihumboldt.hale.io.html.svg.mapping.json.CellJsonExtension) URL(java.net.URL) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) ValueRepresentation(eu.esdihumboldt.hale.io.html.svg.mapping.json.ValueRepresentation) JsonValueRepresentation(eu.esdihumboldt.hale.io.html.svg.mapping.json.JsonValueRepresentation) StringWriter(java.io.StringWriter) JsonStreamBuilder(eu.esdihumboldt.util.groovy.json.JsonStreamBuilder) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) AbstractAlignmentWriter(eu.esdihumboldt.hale.common.align.io.impl.AbstractAlignmentWriter)

Aggregations

AbstractAlignmentWriter (eu.esdihumboldt.hale.common.align.io.impl.AbstractAlignmentWriter)1 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 CellJsonExtension (eu.esdihumboldt.hale.io.html.svg.mapping.json.CellJsonExtension)1 ExtendedCellRepresentation (eu.esdihumboldt.hale.io.html.svg.mapping.json.ExtendedCellRepresentation)1 JsonValueRepresentation (eu.esdihumboldt.hale.io.html.svg.mapping.json.JsonValueRepresentation)1 ValueRepresentation (eu.esdihumboldt.hale.io.html.svg.mapping.json.ValueRepresentation)1 JsonStreamBuilder (eu.esdihumboldt.util.groovy.json.JsonStreamBuilder)1 Writable (groovy.lang.Writable)1 GStringTemplateEngine (groovy.text.GStringTemplateEngine)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1