Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java @ 9150:23945061daec
gigantic refactoring: exporter, result, results
to support multiple jaspers -> collisions
author | gernotbelger |
---|---|
date | Thu, 14 Jun 2018 16:56:31 +0200 |
parents | ae3565385e6a |
children | a4121ec450d6 |
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde * Software engineering by Intevation GmbH * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.artifacts.sinfo.tkhstate; import java.io.OutputStream; import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; import org.dive4elements.river.artifacts.common.AbstractCommonExporter; import org.dive4elements.river.artifacts.common.ExportContextCSV; import org.dive4elements.river.artifacts.common.JasperReporter; import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; import au.com.bytecode.opencsv.CSVWriter; import net.sf.jasperreports.engine.JRException; /** * Generates different output formats (csv, pdf) of data that resulted from a tkh computation. * * @author Gernot Belger */ // REMARK: must be public because its registered in generators.xml public class TkhExporter extends AbstractCommonExporter<TkhCalculationResults> { private static final String CSV_META_CALCULATION_FORMULA = "sinfo.export.tkh.calculation.formula"; @Override protected void doWritePdf(final OutputStream out, final TkhCalculationResults results) { // TODO: Move to super try { final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, null); final JasperReporter reporter = new JasperReporter(); for (final AbstractCalculationExportableResult<TkhCalculationResults> result : results.getResults()) { final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource(); getHelper().addJRMetaDataUSINFO(source, results); source.addMetaData("calculation_label", msg("sinfo.export.flow_depth.pdf.meta.calculation.label")); source.addMetaData("calculation_name", msg("sinfo.export.flow_depth.pdf.meta.calculation.name")); result.addReport(exportContextCSV, results, reporter, source); } reporter.exportPDF(out); } catch (final JRException je) { getLog().warn("Error generating PDF Report!", je); } } @Override protected void doWriteCSVData(final CSVWriter writer, final TkhCalculationResults results) { // TODO: Diesen Ablauf in super? _WINZIGE ABWEICHUNG vom Standard... // TODO: move results into context? final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, writer); getLog().info("writeCSVData"); /* write as csv */ exportContextCSV.writeCSVGlobalMetadataDefaults(results); // ggf auslagern innerhalb dieser Klasse // "# Berechnungsgrundlage: Gleichung nach GILL (1971)" exportContextCSV.writeCSVMetaEntry(CSV_META_CALCULATION_FORMULA); // writer.writeNext(new String[] { "" }); // break line HERE to avoid redundance final RiverInfo river = results.getRiver(); final Class<?> lastResultType = null; for (final AbstractCalculationExportableResult<TkhCalculationResults> result : results.getResults()) { final Class<?> resultType = result.getClass(); if (lastResultType == null || lastResultType != resultType) { exportContextCSV.writeBlankLine(); result.writeCSVHeader(exportContextCSV, results, river); exportContextCSV.writeBlankLine(); } else exportContextCSV.writeCSVLine(new String[] { "#" }); result.writeCsv(exportContextCSV, results); } } }