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.vegetationzones; |
|
11 |
9006
|
12 import java.io.OutputStream; |
8996
|
13 import java.util.ArrayList; |
|
14 import java.util.Collection; |
|
15 |
9006
|
16 import org.apache.commons.lang.math.DoubleRange; |
8996
|
17 import org.apache.log4j.Logger; |
9006
|
18 import org.dive4elements.river.artifacts.common.I18NStrings; |
|
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.util.RiverInfo; |
|
23 import org.dive4elements.river.artifacts.uinfo.commons.AbstractUInfoExporter; |
9006
|
24 import org.dive4elements.river.artifacts.uinfo.commons.UInfoResultType; |
8996
|
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 VegetationZonesExporter extends AbstractUInfoExporter<VegetationZonesCalculationResult, VegetationZonesCalculationResults> { |
|
34 |
|
35 /** The log used in this exporter. */ |
|
36 private static Logger log = Logger.getLogger(VegetationZonesExporter.class); |
|
37 |
9006
|
38 private static final String JASPER_FILE = "/jasper/templates/uinfo.vegetationzones.jrxml"; |
8996
|
39 |
|
40 @Override |
|
41 protected Logger getLog() { |
|
42 return log; |
|
43 } |
|
44 |
|
45 @Override |
|
46 protected void writeCSVGlobalMetadata(final CSVWriter writer, final VegetationZonesCalculationResults results) { |
|
47 log.info("SalixLineExporter.writeCSVMeta"); |
|
48 super.writeCSVGlobalMetadataDefaults(writer, results); |
9006
|
49 |
|
50 final DoubleRange calcRange = results.getCalcRange(); |
|
51 if (calcRange != null) { |
|
52 // "# Ort/Bereich (km): " |
|
53 writeCSVMetaEntry(writer, I18NStrings.CSV_META_RANGE, msg(I18NStrings.CSV_META_RANGE_LABEL), getKmFormatter().format(calcRange.getMinimumDouble()), |
|
54 getKmFormatter().format(calcRange.getMaximumDouble())); |
|
55 } |
8996
|
56 } |
|
57 |
|
58 /** |
|
59 * Write the header, with different headings depending on whether at a |
|
60 * gauge or at a location. |
|
61 * |
|
62 * @param river |
|
63 * @param useTkh |
|
64 */ |
|
65 @Override |
|
66 protected void writeCSVHeader(final CSVWriter writer, final VegetationZonesCalculationResults results, final RiverInfo river) { |
|
67 log.info("FlowDepthExporter.writeCSVHeader"); |
|
68 |
|
69 final Collection<String> header = new ArrayList<>(11); |
|
70 |
9006
|
71 header.add(msg(UInfoResultType.vegname.getCsvHeader())); |
|
72 header.add(msg(UInfoResultType.vegdauervon.getCsvHeader())); |
|
73 header.add(msg(UInfoResultType.vegdauerbis.getCsvHeader())); |
8996
|
74 |
|
75 writer.writeNext(header.toArray(new String[header.size()])); |
|
76 } |
|
77 |
|
78 /** |
|
79 * Format a row of a flow depth result into an array of string, both used by csv and pdf |
|
80 * |
|
81 * @param pdf |
|
82 * |
|
83 * @param useTkh |
|
84 */ |
|
85 @Override |
|
86 protected String[] formatRow(final VegetationZonesCalculationResults results, final ResultRow row, final ExportMode mode) { |
|
87 |
|
88 final Collection<String> lines = new ArrayList<>(11); |
|
89 |
9006
|
90 lines.add(row.exportValue(this.context, UInfoResultType.vegname)); |
|
91 lines.add(row.exportValue(this.context, UInfoResultType.vegdauervon)); |
|
92 lines.add(row.exportValue(this.context, UInfoResultType.vegdauerbis)); |
8996
|
93 |
9023
|
94 return lines.toArray(new String[lines.size()]); |
8996
|
95 } |
|
96 |
|
97 @Override |
9006
|
98 protected void writeCSVResultMetadata(final CSVWriter writer, final VegetationZonesCalculationResults results, |
|
99 final VegetationZonesCalculationResult result) { |
|
100 |
8996
|
101 } |
|
102 |
|
103 @Override |
9006
|
104 protected final void addJRMetaData(final MetaAndTableJRDataSource source, final VegetationZonesCalculationResults results) { |
8996
|
105 |
9006
|
106 super.addJRMetaData(source, results); |
|
107 |
|
108 /* additional column headings */ |
|
109 source.addMetaData("veg_name", UInfoResultType.vegname.getPdfHeader(this.context.getMeta())); |
|
110 source.addMetaData("veg_dauervon", UInfoResultType.vegdauervon.getPdfHeader(this.context.getMeta())); |
|
111 source.addMetaData("veg_dauerbis", UInfoResultType.vegdauerbis.getPdfHeader(this.context.getMeta())); |
|
112 } |
|
113 |
|
114 @Override |
|
115 protected void writePDF(final OutputStream out) { |
|
116 try { |
|
117 final MetaAndTableJRDataSource source = createJRData(this.data); |
|
118 |
|
119 final JasperReporter reporter = new JasperReporter(); |
|
120 reporter.addReport(JASPER_FILE, source); |
|
121 reporter.exportPDF(out); |
|
122 } |
|
123 catch (final JRException je) { |
|
124 getLog().warn("Error generating PDF Report!", je); |
|
125 } |
8996
|
126 } |
|
127 |
|
128 } |