Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java @ 9195:a4121ec450d6
'ca.'-issue
ExportContextCSV+PDF separated
uinfo.inundationduration url export
author | gernotbelger |
---|---|
date | Fri, 29 Jun 2018 14:52:54 +0200 |
parents | 23945061daec |
children | a49fe0ebb297 |
comparison
equal
deleted
inserted
replaced
9191:f692f5a0536a | 9195:a4121ec450d6 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.sinfo.tkhstate; | 9 package org.dive4elements.river.artifacts.sinfo.tkhstate; |
10 | 10 |
11 import java.io.OutputStream; | |
12 | |
13 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; | |
14 import org.dive4elements.river.artifacts.common.AbstractCommonExporter; | 11 import org.dive4elements.river.artifacts.common.AbstractCommonExporter; |
15 import org.dive4elements.river.artifacts.common.ExportContextCSV; | 12 import org.dive4elements.river.artifacts.common.ExportContextCSV; |
16 import org.dive4elements.river.artifacts.common.JasperReporter; | 13 import org.dive4elements.river.artifacts.common.ExportContextPDF; |
17 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; | 14 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; |
18 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | |
19 | |
20 import au.com.bytecode.opencsv.CSVWriter; | |
21 import net.sf.jasperreports.engine.JRException; | |
22 | 15 |
23 /** | 16 /** |
24 * Generates different output formats (csv, pdf) of data that resulted from a tkh computation. | 17 * Generates different output formats (csv, pdf) of data that resulted from a tkh computation. |
25 * | 18 * |
26 * @author Gernot Belger | 19 * @author Gernot Belger |
27 */ | 20 */ |
28 // REMARK: must be public because its registered in generators.xml | 21 // REMARK: must be public because its registered in generators.xml |
29 public class TkhExporter extends AbstractCommonExporter<TkhCalculationResults> { | 22 public class TkhExporter extends AbstractCommonExporter<TkhCalculationResult, TkhCalculationResults> { |
30 | 23 |
31 private static final String CSV_META_CALCULATION_FORMULA = "sinfo.export.tkh.calculation.formula"; | 24 private static final String CSV_META_CALCULATION_FORMULA = "sinfo.export.tkh.calculation.formula"; |
32 | 25 |
33 @Override | 26 @Override |
34 protected void doWritePdf(final OutputStream out, final TkhCalculationResults results) { | 27 protected void writeCSVGlobalMetadata(final ExportContextCSV exportContext, final TkhCalculationResults results) { |
35 // TODO: Move to super | |
36 try { | |
37 final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, null); | |
38 | 28 |
39 final JasperReporter reporter = new JasperReporter(); | 29 /* write as csv */ |
30 exportContext.writeCSVGlobalMetadataDefaults(); // ggf auslagern innerhalb dieser Klasse | |
40 | 31 |
41 for (final AbstractCalculationExportableResult<TkhCalculationResults> result : results.getResults()) { | 32 // "# Berechnungsgrundlage: Gleichung nach GILL (1971)" |
42 final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource(); | 33 exportContext.writeCSVMetaEntry(CSV_META_CALCULATION_FORMULA); |
43 getHelper().addJRMetaDataUSINFO(source, results); | |
44 | |
45 source.addMetaData("calculation_label", msg("sinfo.export.flow_depth.pdf.meta.calculation.label")); | |
46 source.addMetaData("calculation_name", msg("sinfo.export.flow_depth.pdf.meta.calculation.name")); | |
47 | |
48 result.addReport(exportContextCSV, results, reporter, source); | |
49 } | |
50 | |
51 reporter.exportPDF(out); | |
52 } | |
53 catch (final JRException je) { | |
54 getLog().warn("Error generating PDF Report!", je); | |
55 } | |
56 } | 34 } |
57 | 35 |
58 @Override | 36 @Override |
59 protected void doWriteCSVData(final CSVWriter writer, final TkhCalculationResults results) { | 37 protected final void writePDFGlobalMetadata(final ExportContextPDF exportContext, final MetaAndTableJRDataSource source) { |
60 // TODO: Diesen Ablauf in super? _WINZIGE ABWEICHUNG vom Standard... | 38 exportContext.addJRMetaDataUSINFO(source); |
61 | 39 |
62 // TODO: move results into context? | 40 source.addMetaData("calculation_label", msg("sinfo.export.flow_depth.pdf.meta.calculation.label")); |
63 final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, writer); | 41 source.addMetaData("calculation_name", msg("sinfo.export.flow_depth.pdf.meta.calculation.name")); |
64 | |
65 getLog().info("writeCSVData"); | |
66 | |
67 /* write as csv */ | |
68 exportContextCSV.writeCSVGlobalMetadataDefaults(results); // ggf auslagern innerhalb dieser Klasse | |
69 | |
70 // "# Berechnungsgrundlage: Gleichung nach GILL (1971)" | |
71 exportContextCSV.writeCSVMetaEntry(CSV_META_CALCULATION_FORMULA); | |
72 | |
73 // writer.writeNext(new String[] { "" }); // break line HERE to avoid redundance | |
74 | |
75 final RiverInfo river = results.getRiver(); | |
76 | |
77 final Class<?> lastResultType = null; | |
78 | |
79 for (final AbstractCalculationExportableResult<TkhCalculationResults> result : results.getResults()) { | |
80 | |
81 final Class<?> resultType = result.getClass(); | |
82 if (lastResultType == null || lastResultType != resultType) { | |
83 exportContextCSV.writeBlankLine(); | |
84 result.writeCSVHeader(exportContextCSV, results, river); | |
85 exportContextCSV.writeBlankLine(); | |
86 } else | |
87 exportContextCSV.writeCSVLine(new String[] { "#" }); | |
88 | |
89 result.writeCsv(exportContextCSV, results); | |
90 } | |
91 } | 42 } |
92 } | 43 } |