Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesExporter.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 |
---|---|
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.vegetationzones; | 10 package org.dive4elements.river.artifacts.uinfo.vegetationzones; |
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; |
17 import org.dive4elements.river.artifacts.common.JasperReporter; | 14 import org.dive4elements.river.artifacts.common.ExportContextPDF; |
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 * @author Domenico Nardi Tironi | 18 * @author Domenico Nardi Tironi |
26 * | 19 * |
27 */ | 20 */ |
28 public class VegetationZonesExporter extends AbstractCommonExporter<VegetationZonesCalculationResults> { | 21 public class VegetationZonesExporter extends AbstractCommonExporter<VegetationZonesCalculationResult, VegetationZonesCalculationResults> { |
29 | 22 |
30 @Override | 23 @Override |
31 protected void doWritePdf(final OutputStream out, final VegetationZonesCalculationResults results) { | 24 protected void writeCSVGlobalMetadata(final ExportContextCSV exportContext, final VegetationZonesCalculationResults results) { |
32 // TODO: Move to super | 25 exportContext.writeCSVGlobalMetadataDefaults(); |
33 try { | |
34 final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, null); | |
35 | 26 |
36 final JasperReporter reporter = new JasperReporter(); | |
37 | |
38 for (final AbstractCalculationExportableResult<VegetationZonesCalculationResults> result : results.getResults()) { | |
39 final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource(); | |
40 getHelper().addJRMetaDataUSINFO(source, results); | |
41 | |
42 result.addReport(exportContextCSV, results, reporter, source); | |
43 } | |
44 | |
45 reporter.exportPDF(out); | |
46 } | |
47 catch (final JRException je) { | |
48 getLog().warn("Error generating PDF Report!", je); | |
49 } | |
50 } | 27 } |
51 | 28 |
52 @Override | 29 @Override |
53 protected void doWriteCSVData(final CSVWriter writer, final VegetationZonesCalculationResults results) { | 30 protected void writePDFGlobalMetadata(final ExportContextPDF exportContext, final MetaAndTableJRDataSource source) { |
54 // TODO: Diesen Ablauf in super? | 31 exportContext.addJRMetaDataUSINFO(source); |
55 | |
56 // TODO: move results into context? | |
57 final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, writer); | |
58 | |
59 getLog().info("writeCSVData"); | |
60 | |
61 /* write as csv */ | |
62 exportContextCSV.writeCSVGlobalMetadataDefaults(results); // ggf auslagern innerhalb dieser Klasse | |
63 | |
64 // writer.writeNext(new String[] { "" }); // break line HERE to avoid redundance | |
65 | |
66 final RiverInfo river = results.getRiver(); | |
67 | |
68 final Class<?> lastResultType = null; | |
69 | |
70 for (final AbstractCalculationExportableResult<VegetationZonesCalculationResults> result : results.getResults()) { | |
71 | |
72 final Class<?> resultType = result.getClass(); | |
73 if (lastResultType == null || lastResultType != resultType) { | |
74 exportContextCSV.writeBlankLine(); | |
75 result.writeCSVHeader(exportContextCSV, results, river); | |
76 exportContextCSV.writeBlankLine(); | |
77 } else | |
78 exportContextCSV.writeCSVLine(new String[] { "#" }); | |
79 | |
80 result.writeCsv(exportContextCSV, results); | |
81 } | |
82 } | 32 } |
83 } | 33 } |