8996
|
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.uinfo.inundationduration; |
|
11 |
9006
|
12 import java.io.OutputStream; |
8996
|
13 import java.util.ArrayList; |
|
14 import java.util.Collection; |
|
15 |
|
16 import org.apache.log4j.Logger; |
|
17 import org.dive4elements.river.artifacts.common.GeneralResultType; |
9107
|
18 import org.dive4elements.river.artifacts.common.I18NStrings; |
9006
|
19 import org.dive4elements.river.artifacts.common.JasperReporter; |
|
20 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; |
8996
|
21 import org.dive4elements.river.artifacts.common.ResultRow; |
|
22 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
|
23 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
|
24 import org.dive4elements.river.artifacts.uinfo.commons.AbstractUInfoExporter; |
|
25 |
|
26 import au.com.bytecode.opencsv.CSVWriter; |
9006
|
27 import net.sf.jasperreports.engine.JRException; |
8996
|
28 |
|
29 /** |
|
30 * @author Domenico Nardi Tironi |
|
31 * |
|
32 */ |
|
33 public class InundationDurationExporter extends AbstractUInfoExporter<InundationDurationCalculationResult, InundationDurationCalculationResults> { |
|
34 |
|
35 /** The log used in this exporter. */ |
|
36 private static Logger log = Logger.getLogger(InundationDurationExporter.class); |
|
37 |
9006
|
38 private static final String JASPER_FILE = "/jasper/templates/uinfo.inundationduration.jrxml"; |
8996
|
39 |
|
40 @Override |
|
41 protected Logger getLog() { |
|
42 return log; |
|
43 } |
|
44 |
|
45 @Override |
|
46 protected void writeCSVGlobalMetadata(final CSVWriter writer, final InundationDurationCalculationResults results) { |
|
47 log.info("SalixLineExporter.writeCSVMeta"); |
|
48 |
|
49 super.writeCSVGlobalMetadataDefaults(writer, results); |
9107
|
50 |
|
51 // "# Höhensystem des Flusses: " |
|
52 writeCSVMetaEntry(writer, I18NStrings.CSV_META_HEIGHT_UNIT_RIVER, results.getRiver().getWstUnit()); |
|
53 |
9006
|
54 writer.writeNext(new String[] { "" }); // break line |
8996
|
55 } |
|
56 |
|
57 @Override |
|
58 protected void writeCSVResultMetadata(final CSVWriter writer, final InundationDurationCalculationResults results, |
|
59 final InundationDurationCalculationResult result) { |
|
60 |
|
61 /* |
|
62 * final BedHeightInfo sounding = result.getSounding(); |
|
63 * super.writeCSVSoundingMetadata(writer, sounding); |
|
64 * final WstInfo wst = result.getWst(); |
|
65 * super.writeCSVWaterlevelMetadata(writer, wst); |
|
66 */ |
|
67 } |
|
68 |
|
69 /** |
|
70 * Write the header, with different headings depending on whether at a |
|
71 * gauge or at a location. |
|
72 * |
|
73 * @param river |
|
74 * @param useTkh |
|
75 */ |
|
76 @Override |
|
77 protected void writeCSVHeader(final CSVWriter writer, final InundationDurationCalculationResults results, final RiverInfo river) { |
|
78 log.info("FlowDepthExporter.writeCSVHeader"); |
|
79 |
|
80 final Collection<String> header = new ArrayList<>(11); |
|
81 |
|
82 header.add(msg(GeneralResultType.station.getCsvHeader())); |
|
83 header.add(msgUnit(SInfoResultType.flowdepth.getCsvHeader(), SInfoResultType.flowdepth.getUnit())); |
|
84 |
|
85 header.add(msgUnit(SInfoResultType.waterlevel.getCsvHeader(), river.getWstUnit())); |
|
86 header.add(msgUnit(SInfoResultType.discharge.getCsvHeader(), SInfoResultType.discharge.getUnit())); |
|
87 header.add(msg(SInfoResultType.waterlevelLabel.getCsvHeader())); |
|
88 header.add(msg(SInfoResultType.gaugeLabel.getCsvHeader())); |
|
89 header.add(msgUnit(SInfoResultType.meanBedHeight.getCsvHeader(), river.getWstUnit())); |
|
90 header.add(msg(SInfoResultType.soundingLabel.getCsvHeader())); |
|
91 header.add(msg(SInfoResultType.location.getCsvHeader())); |
|
92 |
|
93 writer.writeNext(header.toArray(new String[header.size()])); |
|
94 } |
|
95 |
|
96 /** |
|
97 * Format a row of a flow depth result into an array of string, both used by csv and pdf |
|
98 * |
|
99 * @param pdf |
|
100 * |
|
101 * @param useTkh |
|
102 */ |
|
103 @Override |
|
104 protected String[] formatRow(final InundationDurationCalculationResults results, final ResultRow row, final ExportMode mode) { |
|
105 |
|
106 final Collection<String> lines = new ArrayList<>(11); |
|
107 |
|
108 lines.add(row.exportValue(this.context, GeneralResultType.station)); |
|
109 lines.add(row.exportValue(this.context, SInfoResultType.flowdepth)); |
|
110 |
|
111 lines.add(row.exportValue(this.context, SInfoResultType.waterlevel)); |
|
112 lines.add(row.exportValue(this.context, SInfoResultType.discharge)); |
|
113 lines.add(row.exportValue(this.context, SInfoResultType.waterlevelLabel)); |
|
114 lines.add(row.exportValue(this.context, SInfoResultType.gaugeLabel)); |
|
115 lines.add(row.exportValue(this.context, SInfoResultType.meanBedHeight)); |
|
116 lines.add(row.exportValue(this.context, SInfoResultType.soundingLabel)); |
|
117 lines.add(row.exportValue(this.context, SInfoResultType.location)); |
|
118 |
|
119 return lines.toArray(new String[lines.size()]); |
|
120 } |
|
121 |
|
122 @Override |
|
123 protected final void addJRMetaData(final MetaAndTableJRDataSource source, final InundationDurationCalculationResults results) { |
|
124 |
|
125 /* general metadata */ |
|
126 super.addJRMetaData(source, results); |
9006
|
127 |
8996
|
128 /* column headings */ |
|
129 source.addMetaData("station_header", GeneralResultType.station.getPdfHeader(this.context.getMeta())); |
9006
|
130 |
|
131 } |
|
132 |
|
133 @Override |
|
134 protected void writePDF(final OutputStream out) { |
|
135 try { |
|
136 final MetaAndTableJRDataSource source = createJRData(this.data); |
|
137 |
|
138 final JasperReporter reporter = new JasperReporter(); |
|
139 reporter.addReport(JASPER_FILE, source); |
|
140 reporter.exportPDF(out); |
|
141 } |
|
142 catch (final JRException je) { |
|
143 getLog().warn("Error generating PDF Report!", je); |
|
144 } |
8996
|
145 } |
|
146 |
|
147 } |