Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesExporter.java @ 9006:7134a4c7d1b6
U-Info S-Info general work
author | gernotbelger |
---|---|
date | Tue, 17 Apr 2018 13:20:25 +0200 |
parents | fb9430250899 |
children | ea3908c3cbb6 |
comparison
equal
deleted
inserted
replaced
9005:460fcc128794 | 9006:7134a4c7d1b6 |
---|---|
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; | |
12 import java.util.ArrayList; | 13 import java.util.ArrayList; |
13 import java.util.Collection; | 14 import java.util.Collection; |
14 | 15 |
16 import org.apache.commons.lang.math.DoubleRange; | |
15 import org.apache.log4j.Logger; | 17 import org.apache.log4j.Logger; |
16 import org.dive4elements.river.artifacts.common.GeneralResultType; | 18 import org.dive4elements.river.artifacts.common.I18NStrings; |
19 import org.dive4elements.river.artifacts.common.JasperReporter; | |
20 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; | |
17 import org.dive4elements.river.artifacts.common.ResultRow; | 21 import org.dive4elements.river.artifacts.common.ResultRow; |
18 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; | |
19 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | 22 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
20 import org.dive4elements.river.artifacts.uinfo.commons.AbstractUInfoExporter; | 23 import org.dive4elements.river.artifacts.uinfo.commons.AbstractUInfoExporter; |
24 import org.dive4elements.river.artifacts.uinfo.commons.UInfoResultType; | |
21 | 25 |
22 import au.com.bytecode.opencsv.CSVWriter; | 26 import au.com.bytecode.opencsv.CSVWriter; |
27 import net.sf.jasperreports.engine.JRException; | |
23 | 28 |
24 /** | 29 /** |
25 * @author Domenico Nardi Tironi | 30 * @author Domenico Nardi Tironi |
26 * | 31 * |
27 */ | 32 */ |
28 public class VegetationZonesExporter extends AbstractUInfoExporter<VegetationZonesCalculationResult, VegetationZonesCalculationResults> { | 33 public class VegetationZonesExporter extends AbstractUInfoExporter<VegetationZonesCalculationResult, VegetationZonesCalculationResults> { |
29 | 34 |
30 /** The log used in this exporter. */ | 35 /** The log used in this exporter. */ |
31 private static Logger log = Logger.getLogger(VegetationZonesExporter.class); | 36 private static Logger log = Logger.getLogger(VegetationZonesExporter.class); |
32 | 37 |
33 private static final String JASPER_FILE = "/jasper/uinfo.vegetationzones.jasper"; | 38 private static final String JASPER_FILE = "/jasper/templates/uinfo.vegetationzones.jrxml"; |
34 | 39 |
35 @Override | 40 @Override |
36 protected Logger getLog() { | 41 protected Logger getLog() { |
37 return log; | 42 return log; |
38 } | 43 } |
39 | 44 |
40 @Override | 45 @Override |
41 protected void writeCSVGlobalMetadata(final CSVWriter writer, final VegetationZonesCalculationResults results) { | 46 protected void writeCSVGlobalMetadata(final CSVWriter writer, final VegetationZonesCalculationResults results) { |
42 log.info("SalixLineExporter.writeCSVMeta"); | 47 log.info("SalixLineExporter.writeCSVMeta"); |
43 super.writeCSVGlobalMetadataDefaults(writer, results); | 48 super.writeCSVGlobalMetadataDefaults(writer, results); |
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 } | |
44 } | 56 } |
45 | 57 |
46 /** | 58 /** |
47 * Write the header, with different headings depending on whether at a | 59 * Write the header, with different headings depending on whether at a |
48 * gauge or at a location. | 60 * gauge or at a location. |
54 protected void writeCSVHeader(final CSVWriter writer, final VegetationZonesCalculationResults results, final RiverInfo river) { | 66 protected void writeCSVHeader(final CSVWriter writer, final VegetationZonesCalculationResults results, final RiverInfo river) { |
55 log.info("FlowDepthExporter.writeCSVHeader"); | 67 log.info("FlowDepthExporter.writeCSVHeader"); |
56 | 68 |
57 final Collection<String> header = new ArrayList<>(11); | 69 final Collection<String> header = new ArrayList<>(11); |
58 | 70 |
59 header.add(msg(GeneralResultType.station.getCsvHeader())); | 71 header.add(msg(UInfoResultType.vegname.getCsvHeader())); |
60 header.add(msgUnit(SInfoResultType.flowdepth.getCsvHeader(), SInfoResultType.flowdepth.getUnit())); | 72 header.add(msg(UInfoResultType.vegdauervon.getCsvHeader())); |
61 | 73 header.add(msg(UInfoResultType.vegdauerbis.getCsvHeader())); |
62 header.add(msgUnit(SInfoResultType.waterlevel.getCsvHeader(), river.getWstUnit())); | |
63 header.add(msgUnit(SInfoResultType.discharge.getCsvHeader(), SInfoResultType.discharge.getUnit())); | |
64 header.add(msg(SInfoResultType.waterlevelLabel.getCsvHeader())); | |
65 header.add(msg(SInfoResultType.gaugeLabel.getCsvHeader())); | |
66 header.add(msgUnit(SInfoResultType.meanBedHeight.getCsvHeader(), river.getWstUnit())); | |
67 header.add(msg(SInfoResultType.soundingLabel.getCsvHeader())); | |
68 header.add(msg(SInfoResultType.location.getCsvHeader())); | |
69 | 74 |
70 writer.writeNext(header.toArray(new String[header.size()])); | 75 writer.writeNext(header.toArray(new String[header.size()])); |
71 } | 76 } |
72 | 77 |
73 /** | 78 /** |
80 @Override | 85 @Override |
81 protected String[] formatRow(final VegetationZonesCalculationResults results, final ResultRow row, final ExportMode mode) { | 86 protected String[] formatRow(final VegetationZonesCalculationResults results, final ResultRow row, final ExportMode mode) { |
82 | 87 |
83 final Collection<String> lines = new ArrayList<>(11); | 88 final Collection<String> lines = new ArrayList<>(11); |
84 | 89 |
85 lines.add(row.exportValue(this.context, GeneralResultType.station)); | 90 lines.add(row.exportValue(this.context, UInfoResultType.vegname)); |
86 lines.add(row.exportValue(this.context, SInfoResultType.flowdepth)); | 91 lines.add(row.exportValue(this.context, UInfoResultType.vegdauervon)); |
87 | 92 lines.add(row.exportValue(this.context, UInfoResultType.vegdauerbis)); |
88 lines.add(row.exportValue(this.context, SInfoResultType.waterlevel)); | |
89 lines.add(row.exportValue(this.context, SInfoResultType.discharge)); | |
90 lines.add(row.exportValue(this.context, SInfoResultType.waterlevelLabel)); | |
91 lines.add(row.exportValue(this.context, SInfoResultType.gaugeLabel)); | |
92 lines.add(row.exportValue(this.context, SInfoResultType.meanBedHeight)); | |
93 lines.add(row.exportValue(this.context, SInfoResultType.soundingLabel)); | |
94 lines.add(row.exportValue(this.context, SInfoResultType.location)); | |
95 | 93 |
96 return lines.toArray(new String[lines.size()]); | 94 return lines.toArray(new String[lines.size()]); |
97 } | 95 } |
98 | 96 |
99 @Override | 97 @Override |
100 protected String getJasperFile() { | 98 protected void writeCSVResultMetadata(final CSVWriter writer, final VegetationZonesCalculationResults results, |
101 // TODO Auto-generated method stub | 99 final VegetationZonesCalculationResult result) { |
102 return JASPER_FILE; | 100 |
103 } | 101 } |
104 | 102 |
105 @Override | 103 @Override |
106 protected void writeCSVResultMetadata(final CSVWriter writer, final VegetationZonesCalculationResults results, | 104 protected final void addJRMetaData(final MetaAndTableJRDataSource source, final VegetationZonesCalculationResults results) { |
107 final VegetationZonesCalculationResult result) { | |
108 // TODO Auto-generated method stub | |
109 | 105 |
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 } | |
110 } | 126 } |
111 | 127 |
112 } | 128 } |