Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionExporter.java @ 9157:f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
author | mschaefer |
---|---|
date | Tue, 19 Jun 2018 14:19:32 +0200 |
parents | 23945061daec |
children | a4121ec450d6 |
rev | line source |
---|---|
9150 | 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.sinfo.collision; | |
11 | |
12 import java.io.OutputStream; | |
13 | |
14 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; | |
15 import org.dive4elements.river.artifacts.common.AbstractCommonExporter; | |
16 import org.dive4elements.river.artifacts.common.ExportContextCSV; | |
17 import org.dive4elements.river.artifacts.common.JasperReporter; | |
18 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
19 import org.dive4elements.river.artifacts.sinfo.common.SInfoI18NStrings; |
9150 | 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 | |
25 /** | |
26 * @author Gernot Belger | |
27 */ | |
28 public final class CollisionExporter extends AbstractCommonExporter<CollisionCalculationResults> { | |
29 | |
30 @Override | |
31 protected void doWriteCSVData(final CSVWriter writer, final CollisionCalculationResults results) { | |
32 // TODO: Diesen Ablauf in super? | |
33 | |
34 // TODO: move results into context? | |
35 final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, writer); | |
36 | |
37 getLog().info("writeCSVData"); | |
38 | |
39 /* write as csv */ | |
40 exportContextCSV.writeCSVGlobalMetadataDefaults(results); // ggf auslagern innerhalb dieser Klasse | |
41 | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
42 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_YEARS, results.getYearsHeader()); |
9150 | 43 // writer.writeNext(new String[] { "" }); // break line HERE to avoid redundance |
44 | |
45 final RiverInfo river = results.getRiver(); | |
46 | |
47 final Class<?> lastResultType = null; | |
48 | |
49 for (final AbstractCalculationExportableResult<CollisionCalculationResults> result : results.getResults()) { | |
50 | |
51 final Class<?> resultType = result.getClass(); | |
52 if (lastResultType == null || lastResultType != resultType) { | |
53 exportContextCSV.writeBlankLine(); | |
54 result.writeCSVHeader(exportContextCSV, results, river); | |
55 exportContextCSV.writeBlankLine(); | |
56 } else | |
57 exportContextCSV.writeCSVLine(new String[] { "#" }); | |
58 | |
59 result.writeCsv(exportContextCSV, results); | |
60 } | |
61 } | |
62 | |
63 @Override | |
64 protected void doWritePdf(final OutputStream out, final CollisionCalculationResults results) { | |
65 // TODO: Move to super | |
66 try { | |
67 final ExportContextCSV exportContextCSV = new ExportContextCSV(this.context, null); | |
68 | |
69 final JasperReporter reporter = new JasperReporter(); | |
70 | |
71 for (final AbstractCalculationExportableResult<CollisionCalculationResults> result : results.getResults()) { | |
72 final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource(); | |
73 getHelper().addJRMetaDataUSINFO(source, results); | |
74 | |
75 result.addReport(exportContextCSV, results, reporter, source); | |
76 } | |
77 | |
78 reporter.exportPDF(out); | |
79 } | |
80 catch (final JRException je) { | |
81 getLog().warn("Error generating PDF Report!", je); | |
82 } | |
83 } | |
84 } |