Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationExporter.java @ 9195:a4121ec450d6
'ca.'-issue
ExportContextCSV+PDF separated
uinfo.inundationduration url export
author | gernotbelger |
---|---|
date | Fri, 29 Jun 2018 14:52:54 +0200 |
parents | 1614cb14308f |
children | b4402594213b |
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.flood_duration; | 9 package org.dive4elements.river.artifacts.sinfo.flood_duration; |
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 FloodDurationExporter extends AbstractCommonExporter<FloodDurationCalculationResults> { | 24 |
25 public class FloodDurationExporter extends AbstractCommonExporter<FloodDurationCalculationResult, FloodDurationCalculationResults> { | |
32 | 26 |
33 @Override | 27 @Override |
34 protected void doWriteCSVData(final CSVWriter writer, final FloodDurationCalculationResults results) { | 28 protected void writeCSVGlobalMetadata(final ExportContextCSV exportContext, final FloodDurationCalculationResults results) { |
35 // TODO: Diesen Ablauf in super? | 29 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<FloodDurationCalculationResults> 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 | |
64 } | 30 } |
65 | 31 |
66 @Override | 32 @Override |
67 protected void doWritePdf(final OutputStream out, final FloodDurationCalculationResults results) { | 33 protected void writePDFGlobalMetadata(final ExportContextPDF exportContext, final MetaAndTableJRDataSource source) { |
34 exportContext.addJRMetaDataUSINFO(source); | |
35 } | |
68 | 36 |
69 // TODO: Move to super (hier ist aber spezieller code drin...) | 37 @Override |
70 try { | 38 protected void configureDesign(final FloodDurationCalculationResult result, final JasperDesigner design) { |
71 final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, null); | 39 if (result instanceof FloodDurationCalculationResult) { // redundant, but type might change |
72 | 40 design.removeColumn("wOpt"); |
73 final JasperReporter reporter = new JasperReporter(); | 41 design.removeColumn("qOpt"); |
74 | 42 design.removeColumn("bezOpt"); |
75 for (final AbstractCalculationExportableResult<FloodDurationCalculationResults> result : results.getResults()) { | 43 design.removeColumn("durOpt"); |
76 final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource(); | |
77 getHelper().addJRMetaDataUSINFO(source, results); | |
78 | |
79 final JasperDesigner design = result.addReport(exportContextCSV, results, reporter, source); | |
80 if (result instanceof FloodDurationCalculationResult) { | |
81 // final int wlCount = ((FloodDurationCalculationResult) result).getWaterlevelCount(); | |
82 // if (wlCount == 0 || wlCount == 2) { | |
83 design.removeColumn("wOpt"); | |
84 design.removeColumn("qOpt"); | |
85 design.removeColumn("bezOpt"); | |
86 design.removeColumn("durOpt"); | |
87 // } | |
88 } | |
89 } | |
90 | |
91 reporter.exportPDF(out); | |
92 } | 44 } |
93 catch (final JRException je) { | |
94 getLog().warn("Error generating PDF Report!", je); | |
95 } | |
96 | |
97 } | 45 } |
98 } | 46 } |