Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineExporter.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 | da0bdbcd6f09 |
comparison
equal
deleted
inserted
replaced
9191:f692f5a0536a | 9195:a4121ec450d6 |
---|---|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
8 * documentation coming with Dive4Elements River for details. | 8 * documentation coming with Dive4Elements River for details. |
9 */ | 9 */ |
10 package org.dive4elements.river.artifacts.uinfo.salix; | 10 package org.dive4elements.river.artifacts.uinfo.salix; |
11 | 11 |
12 import java.io.OutputStream; | |
13 | |
14 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; | |
15 import org.dive4elements.river.artifacts.common.AbstractCommonExporter; | 12 import org.dive4elements.river.artifacts.common.AbstractCommonExporter; |
16 import org.dive4elements.river.artifacts.common.ExportContextCSV; | 13 import org.dive4elements.river.artifacts.common.ExportContextCSV; |
14 import org.dive4elements.river.artifacts.common.ExportContextPDF; | |
17 import org.dive4elements.river.artifacts.common.I18NStrings; | 15 import org.dive4elements.river.artifacts.common.I18NStrings; |
18 import org.dive4elements.river.artifacts.common.JasperReporter; | |
19 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; | 16 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; |
20 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | |
21 | |
22 import au.com.bytecode.opencsv.CSVWriter; | |
23 import net.sf.jasperreports.engine.JRException; | |
24 | 17 |
25 /** | 18 /** |
26 * @author Domenico Nardi Tironi | 19 * @author Domenico Nardi Tironi |
27 * | 20 * |
28 */ | 21 */ |
29 public class SalixLineExporter extends AbstractCommonExporter<SalixLineCalculationResults> { | 22 public class SalixLineExporter extends AbstractCommonExporter<SalixLineCalculationResult, SalixLineCalculationResults> { |
30 | 23 |
31 @Override | 24 @Override |
32 protected void doWritePdf(final OutputStream out, final SalixLineCalculationResults results) { | 25 protected void writeCSVGlobalMetadata(final ExportContextCSV exportContextCSV, final SalixLineCalculationResults results) { |
33 // TODO: Move to super | 26 /* write as csv */ |
34 try { | 27 exportContextCSV.writeCSVGlobalMetadataDefaults(); // ggf auslagern innerhalb dieser Klasse |
35 final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, null); | |
36 | 28 |
37 final JasperReporter reporter = new JasperReporter(); | 29 // break line ? |
38 | |
39 for (final AbstractCalculationExportableResult<SalixLineCalculationResults> result : results.getResults()) { | |
40 final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource(); | |
41 getHelper().addJRMetaDataUSINFO(source, results); | |
42 | |
43 result.addReport(exportContextCSV, results, reporter, source); | |
44 } | |
45 | |
46 reporter.exportPDF(out); | |
47 } | |
48 catch (final JRException je) { | |
49 getLog().warn("Error generating PDF Report!", je); | |
50 } | |
51 } | |
52 | |
53 @Override | |
54 protected void doWriteCSVData(final CSVWriter writer, final SalixLineCalculationResults results) { | |
55 // TODO: Diesen Ablauf in super? - ist etwas anders bei den globalen metadaten | |
56 | |
57 // TODO: move results into context? | |
58 final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, writer); | |
59 | |
60 getLog().info("writeCSVData"); | |
61 | |
62 /* write as csv */ | |
63 exportContextCSV.writeCSVGlobalMetadataDefaults(results); // ggf auslagern innerhalb dieser Klasse | |
64 | |
65 // writer.writeNext(new String[] { "" }); // break line HERE to avoid redundance | |
66 | 30 |
67 // "# Höhensystem des Flusses: " | 31 // "# Höhensystem des Flusses: " |
68 exportContextCSV.writeCSVMetaEntry(I18NStrings.CSV_META_HEIGHT_UNIT_RIVER, results.getRiver().getWstUnit()); | 32 exportContextCSV.writeCSVMetaEntry(I18NStrings.CSV_META_HEIGHT_UNIT_RIVER, results.getRiver().getWstUnit()); |
69 | 33 |
70 // Add Auswerter, Bezugspegel, Jahr/Zeitraum der Wasserspiegellage | 34 // Add Auswerter, Bezugspegel, Jahr/Zeitraum der Wasserspiegellage |
77 // "# Jahr/Zeitraum der Wasserspiegellage: " | 41 // "# Jahr/Zeitraum der Wasserspiegellage: " |
78 // final int year = wst.getYear(); | 42 // final int year = wst.getYear(); |
79 // if (year > 0) | 43 // if (year > 0) |
80 exportContextCSV.writeCSVMetaEntry("uinfo.export.salix_line.csv.meta.header.waterlevel.year", "Integer.toString(year)"); | 44 exportContextCSV.writeCSVMetaEntry("uinfo.export.salix_line.csv.meta.header.waterlevel.year", "Integer.toString(year)"); |
81 | 45 |
82 final RiverInfo river = results.getRiver(); | 46 } |
83 | 47 |
84 final Class<?> lastResultType = null; | 48 @Override |
85 | 49 protected void writePDFGlobalMetadata(final ExportContextPDF exportContext, final MetaAndTableJRDataSource source) { |
86 for (final AbstractCalculationExportableResult<SalixLineCalculationResults> result : results.getResults()) { | 50 exportContext.addJRMetaDataUSINFO(source); |
87 | |
88 final Class<?> resultType = result.getClass(); | |
89 if (lastResultType == null || lastResultType != resultType) { | |
90 exportContextCSV.writeBlankLine(); | |
91 result.writeCSVHeader(exportContextCSV, results, river); | |
92 exportContextCSV.writeBlankLine(); | |
93 } else | |
94 exportContextCSV.writeCSVLine(new String[] { "#" }); | |
95 | |
96 result.writeCsv(exportContextCSV, results); | |
97 } | |
98 } | 51 } |
99 | 52 |
100 } | 53 } |