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