Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxExporter.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.flowdepthminmax; | 9 package org.dive4elements.river.artifacts.sinfo.flowdepthminmax; |
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 flow depths computation. | 17 * Generates different output formats (csv, pdf) of data that resulted from a flow depths computation. |
25 * | 18 * |
26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
27 * @author Gernot Belger | 20 * @author Gernot Belger |
28 */ | 21 */ |
29 // REMARK: must be public because its registered in generators.xml | 22 // REMARK: must be public because its registered in generators.xml |
30 public class FlowDepthMinMaxExporter extends AbstractCommonExporter<FlowDepthMinMaxCalculationResults> { | 23 public class FlowDepthMinMaxExporter extends AbstractCommonExporter<FlowDepthMinMaxCalculationResult, FlowDepthMinMaxCalculationResults> { |
31 | 24 |
32 @Override | 25 @Override |
33 protected void doWritePdf(final OutputStream out, final FlowDepthMinMaxCalculationResults results) { | 26 protected void writeCSVGlobalMetadata(final ExportContextCSV exportContext, final FlowDepthMinMaxCalculationResults results) { |
34 // TODO: Move to super | 27 exportContext.writeCSVGlobalMetadataDefaults(); |
35 try { | |
36 final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, null); | |
37 | 28 |
38 final JasperReporter reporter = new JasperReporter(); | |
39 | |
40 for (final AbstractCalculationExportableResult<FlowDepthMinMaxCalculationResults> result : results.getResults()) { | |
41 final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource(); | |
42 getHelper().addJRMetaDataUSINFO(source, results); | |
43 | |
44 result.addReport(exportContextCSV, results, reporter, source); | |
45 } | |
46 | |
47 reporter.exportPDF(out); | |
48 } | |
49 catch (final JRException je) { | |
50 getLog().warn("Error generating PDF Report!", je); | |
51 } | |
52 } | 29 } |
53 | 30 |
54 @Override | 31 @Override |
55 protected void doWriteCSVData(final CSVWriter writer, final FlowDepthMinMaxCalculationResults results) { | 32 protected void writePDFGlobalMetadata(final ExportContextPDF exportContext, final MetaAndTableJRDataSource source) { |
56 // TODO: Diesen Ablauf in super? | 33 exportContext.addJRMetaDataUSINFO(source); |
57 | |
58 // TODO: move results into context? | |
59 final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, writer); | |
60 | |
61 getLog().info("writeCSVData"); | |
62 | |
63 /* write as csv */ | |
64 exportContextCSV.writeCSVGlobalMetadataDefaults(results); // ggf auslagern innerhalb dieser Klasse | |
65 | |
66 // writer.writeNext(new String[] { "" }); // break line HERE to avoid redundance | |
67 | |
68 final RiverInfo river = results.getRiver(); | |
69 | |
70 final Class<?> lastResultType = null; | |
71 | |
72 for (final AbstractCalculationExportableResult<FlowDepthMinMaxCalculationResults> result : results.getResults()) { | |
73 | |
74 final Class<?> resultType = result.getClass(); | |
75 if (lastResultType == null || lastResultType != resultType) { | |
76 exportContextCSV.writeBlankLine(); | |
77 result.writeCSVHeader(exportContextCSV, results, river); | |
78 exportContextCSV.writeBlankLine(); | |
79 } else | |
80 exportContextCSV.writeCSVLine(new String[] { "#" }); | |
81 | |
82 result.writeCsv(exportContextCSV, results); | |
83 } | |
84 | |
85 } | 34 } |
86 } | 35 } |