9331
|
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.bundu.bezugswst; |
|
11 |
|
12 import java.util.ArrayList; |
|
13 import java.util.Collection; |
|
14 import java.util.List; |
|
15 |
|
16 import org.dive4elements.river.artifacts.bundu.BunduResultType; |
|
17 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; |
|
18 import org.dive4elements.river.artifacts.common.AbstractExportContext; |
|
19 import org.dive4elements.river.artifacts.common.ExportContextCSV; |
|
20 import org.dive4elements.river.artifacts.common.ExportContextPDF; |
|
21 import org.dive4elements.river.artifacts.common.GeneralResultType; |
|
22 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; |
|
23 import org.dive4elements.river.artifacts.common.ResultRow; |
|
24 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
|
25 |
|
26 /** |
|
27 * Contains the results of a //TODO LINK{@link BezugswstCalculation}. |
|
28 * |
|
29 * @author Gernot Belger |
|
30 */ |
9332
|
31 final class BezugswstMissVolCalculationResult2 extends AbstractCalculationExportableResult implements BunduWstExporter.MissResultType { |
9331
|
32 |
|
33 private static final long serialVersionUID = 1L; |
|
34 |
|
35 private static final String JASPER_FILE = "/jasper/templates/bundu.bezugswst.result2.jrxml"; |
|
36 private static final String fieldMsgStr = "bundu.export.bezugswst.csv.meta.miss.field"; |
|
37 private static final int fieldSize = 10; |
|
38 |
|
39 public BezugswstMissVolCalculationResult2(final String label, final Collection<ResultRow> rows) { |
|
40 super(label, rows); |
|
41 |
|
42 } |
|
43 |
|
44 @Override |
|
45 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) { |
|
46 // no metadata |
|
47 } |
|
48 |
|
49 @Override |
|
50 protected String getJasperFile() { |
|
51 return JASPER_FILE; |
|
52 } |
|
53 |
|
54 protected String[] formatRow(final AbstractExportContext exportContext, final ResultRow row) { |
|
55 |
|
56 final Collection<String> lines = new ArrayList<>(20); |
|
57 |
|
58 lines.add(exportContext.formatRowValue(row, GeneralResultType.station)); |
|
59 final List<String> fields = (List<String>) row.getValue(BunduResultType.fields); |
|
60 assert (fields.size() == fieldSize); // immer abgleichen mit der Calculation! |
|
61 for (final String field : fields) { |
|
62 lines.add(field); |
|
63 } |
|
64 lines.add(exportContext.formatRowValue(row, BunduResultType.meanBedheight)); |
|
65 |
|
66 return lines.toArray(new String[lines.size()]); |
|
67 } |
|
68 |
|
69 @Override |
|
70 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final RiverInfo river) { |
|
71 |
9332
|
72 final int colSize = fieldSize + 2; |
9331
|
73 exportContextCSV.writeTitleForTabs("bundu.export.csv.title.bezugswst.result2", colSize); // Voraussetzung für Tabs ist, dass der Titel vor den Headern |
|
74 final Collection<String> header = new ArrayList<>(colSize); |
|
75 |
|
76 header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station)); |
|
77 |
|
78 for (int i = 1; i <= fieldSize; i++) { |
|
79 header.add(exportContextCSV.msg(fieldMsgStr, i)); |
|
80 } |
|
81 header.add(exportContextCSV.formatCsvHeader(BunduResultType.meanBedheight)); |
|
82 |
|
83 exportContextCSV.writeCSVLine(header.toArray(new String[header.size()])); |
|
84 |
|
85 } |
|
86 |
|
87 @Override |
|
88 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) { |
|
89 |
|
90 return this.formatRow(exportContextCSV, row); |
|
91 } |
|
92 |
|
93 @Override |
|
94 protected String[] formatPDFRow(final ExportContextPDF exportContextPDF, final ResultRow row) { |
|
95 |
|
96 return this.formatRow(exportContextPDF, row); |
|
97 } |
|
98 |
|
99 @Override |
|
100 protected void addJRTableHeader(final ExportContextPDF exportContextPDF, final MetaAndTableJRDataSource source) { |
|
101 /* column headings */ |
|
102 |
|
103 exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station); |
|
104 for (int i = 1; i <= fieldSize; i++) { |
|
105 exportContextPDF.addJRMetadata(source, "field_header" + String.valueOf(i), exportContextPDF.msg(fieldMsgStr, i)); |
|
106 } |
|
107 exportContextPDF.addJRMetadata(source, "mean_bedheight_header", BunduResultType.meanBedheight); |
|
108 |
|
109 } |
|
110 } |