comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationCalculationResult.java @ 9150:23945061daec

gigantic refactoring: exporter, result, results to support multiple jaspers -> collisions
author gernotbelger
date Thu, 14 Jun 2018 16:56:31 +0200
parents fb9430250899
children 0633f963c5be
comparison
equal deleted inserted replaced
9149:5be112fba832 9150:23945061daec
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by 2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH 3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt 4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5 * 5 *
6 * This file is Free Software under the GNU AGPL (>=v3) 6 * This file is Free Software under the GNU AGPL (>=v3)
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.inundationduration; 10 package org.dive4elements.river.artifacts.uinfo.inundationduration;
11 11
12 import java.util.ArrayList;
12 import java.util.Collection; 13 import java.util.Collection;
13 14
14 import org.dive4elements.river.artifacts.common.AbstractCalculationResult; 15 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
16 import org.dive4elements.river.artifacts.common.ExportContextCSV;
17 import org.dive4elements.river.artifacts.common.GeneralResultType;
18 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
15 import org.dive4elements.river.artifacts.common.ResultRow; 19 import org.dive4elements.river.artifacts.common.ResultRow;
20 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
21 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
16 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; 22 import org.dive4elements.river.artifacts.sinfo.util.WstInfo;
17 23
18 /** 24 /**
19 * @author Domenico Nardi Tironi 25 * @author Domenico Nardi Tironi
20 */ 26 */
21 final class InundationDurationCalculationResult extends AbstractCalculationResult { 27 final class InundationDurationCalculationResult extends AbstractCalculationExportableResult<InundationDurationCalculationResults> {
22 28
23 private static final long serialVersionUID = 1L; 29 private static final long serialVersionUID = 1L;
30 private static final String JASPER_FILE = "/jasper/templates/uinfo.inundationduration.jrxml";
24 31
25 public InundationDurationCalculationResult(final String label, final WstInfo wst, final Collection< ResultRow> rows) { 32 public InundationDurationCalculationResult(final String label, final WstInfo wst, final Collection<ResultRow> rows) {
26 super(label, rows); 33 super(label, rows);
27 } 34 }
28 35
36 @Override
37 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final InundationDurationCalculationResults results, final RiverInfo river) {
38
39 final Collection<String> header = new ArrayList<>(11);
40
41 header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station));
42 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.flowdepth));
43
44 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel, river.getWstUnit()));
45 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge));
46 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.waterlevelLabel));
47 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel));
48 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.meanBedHeight, river.getWstUnit()));
49 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.soundingLabel));
50 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location));
51
52 exportContextCSV.writeCSVLine(header.toArray(new String[header.size()]));
53
54 }
55
56 @Override
57 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV, final InundationDurationCalculationResults results) {
58 // no Result metadata so far
59 }
60
61 @Override
62 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final InundationDurationCalculationResults results, final ResultRow row) {
63 return formatRow(exportContextCSV, results, row);
64 }
65
66 @Override
67 protected String[] formatPDFRow(final ExportContextCSV exportContextPDF, final InundationDurationCalculationResults results, final ResultRow row) {
68
69 return formatRow(exportContextPDF, results, row);
70 }
71
72 @Override
73 protected String getJasperFile() {
74
75 return JASPER_FILE;
76 }
77
78 @Override
79 protected void addJRTableHeader(final ExportContextCSV exportContextPDF, final MetaAndTableJRDataSource source,
80 final InundationDurationCalculationResults results) {
81
82 exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station);
83 }
84
85 protected String[] formatRow(final ExportContextCSV context, final InundationDurationCalculationResults results, final ResultRow row) {
86
87 final Collection<String> lines = new ArrayList<>(11);
88
89 lines.add(context.formatRowValue(row, GeneralResultType.station));
90 lines.add(context.formatRowValue(row, SInfoResultType.flowdepth));
91
92 lines.add(context.formatRowValue(row, SInfoResultType.waterlevel));
93 lines.add(context.formatRowValue(row, SInfoResultType.discharge));
94 lines.add(context.formatRowValue(row, SInfoResultType.waterlevelLabel));
95 lines.add(context.formatRowValue(row, SInfoResultType.gaugeLabel));
96 lines.add(context.formatRowValue(row, SInfoResultType.meanBedHeight));
97 lines.add(context.formatRowValue(row, SInfoResultType.soundingLabel));
98 lines.add(context.formatRowValue(row, SInfoResultType.location));
99
100 return lines.toArray(new String[lines.size()]);
101 }
102
29 } 103 }

http://dive4elements.wald.intevation.org