comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculationResult.java @ 9195:a4121ec450d6

'ca.'-issue ExportContextCSV+PDF separated uinfo.inundationduration url export
author gernotbelger
date Fri, 29 Jun 2018 14:52:54 +0200
parents 9b2e46090099
children 740d65e4aa14
comparison
equal deleted inserted replaced
9191:f692f5a0536a 9195:a4121ec450d6
11 11
12 import java.util.ArrayList; 12 import java.util.ArrayList;
13 import java.util.Collection; 13 import java.util.Collection;
14 14
15 import org.dive4elements.river.artifacts.common.ExportContextCSV; 15 import org.dive4elements.river.artifacts.common.ExportContextCSV;
16 import org.dive4elements.river.artifacts.common.ExportContextPDF;
16 import org.dive4elements.river.artifacts.common.GeneralResultType; 17 import org.dive4elements.river.artifacts.common.GeneralResultType;
18 import org.dive4elements.river.artifacts.common.IExportContext;
17 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; 19 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
18 import org.dive4elements.river.artifacts.common.ResultRow; 20 import org.dive4elements.river.artifacts.common.ResultRow;
19 import org.dive4elements.river.artifacts.sinfo.common.AbstractTkhCalculationResult; 21 import org.dive4elements.river.artifacts.sinfo.common.AbstractTkhCalculationResult;
20 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; 22 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
21 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; 23 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
24 /** 26 /**
25 * Contains the results of a {@link FloodDurationCalculation}. 27 * Contains the results of a {@link FloodDurationCalculation}.
26 * 28 *
27 * @author Gernot Belger 29 * @author Gernot Belger
28 */ 30 */
29 final class TkhCalculationResult extends AbstractTkhCalculationResult<TkhCalculationResults> { 31 final class TkhCalculationResult extends AbstractTkhCalculationResult {
30 32
31 private static final long serialVersionUID = 1L; 33 private static final long serialVersionUID = 1L;
32 private static final String JASPER_FILE = "/jasper/templates/sinfo.tkh.jrxml"; 34 private static final String JASPER_FILE = "/jasper/templates/sinfo.tkh.jrxml";
33 35
34 private enum ExportMode { 36 private enum ExportMode {
39 super(label, wst, hasTkh, rows); 41 super(label, wst, hasTkh, rows);
40 42
41 } 43 }
42 44
43 @Override 45 @Override
44 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final TkhCalculationResults results, final RiverInfo river) { 46 public void writeCSVHeader(final ExportContextCSV exportContext, final RiverInfo river) {
45 47
46 final Collection<String> header = new ArrayList<>(11); 48 final Collection<String> header = new ArrayList<>(11);
47 49
48 header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station)); 50 header.add(exportContext.formatCsvHeader(GeneralResultType.station));
49 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.tkh)); 51 header.add(exportContext.msgUnitCSV(SInfoResultType.tkh));
50 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.soilkind)); 52 header.add(exportContext.formatCsvHeader(SInfoResultType.soilkind));
51 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.meanBedHeight, river.getWstUnit())); 53 header.add(exportContext.msgUnitCSV(SInfoResultType.meanBedHeight, river.getWstUnit()));
52 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel, river.getWstUnit())); 54 header.add(exportContext.msgUnitCSV(SInfoResultType.waterlevel, river.getWstUnit()));
53 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge)); 55 header.add(exportContext.msgUnitCSV(SInfoResultType.discharge));
54 56
57 final TkhCalculationResults results = exportContext.getResults();
55 final String descriptionHeader = results.getDescriptionHeader(); 58 final String descriptionHeader = results.getDescriptionHeader();
56 if (descriptionHeader != null) 59 if (descriptionHeader != null)
57 header.add(descriptionHeader); 60 header.add(descriptionHeader);
58 61
59 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel)); 62 header.add(exportContext.formatCsvHeader(SInfoResultType.gaugeLabel));
60 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location)); 63 header.add(exportContext.formatCsvHeader(SInfoResultType.location));
61 64
62 exportContextCSV.writeCSVLine(header.toArray(new String[header.size()])); 65 exportContext.writeCSVLine(header.toArray(new String[header.size()]));
63 66
64 } 67 }
65 68
66 @Override 69 @Override
67 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV, final TkhCalculationResults results) { 70 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) {
68 exportContextCSV.writeCSVWaterlevelMetadata(super.getWst());// TODO: move to super 71 exportContextCSV.writeCSVWaterlevelMetadata(super.getWst());// TODO: move to super
69 exportContextCSV.writeBlankLine(); 72 exportContextCSV.writeBlankLine();
70 } 73 }
71 74
72 @Override 75 @Override
73 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final TkhCalculationResults results, final ResultRow row) { 76 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) {
74 77
75 return this.formatRow(exportContextCSV, results, row, ExportMode.csv); 78 return this.formatRow(exportContextCSV, row, ExportMode.csv);
76 } 79 }
77 80
78 @Override 81 @Override
79 protected String[] formatPDFRow(final ExportContextCSV exportContextPDF, final TkhCalculationResults results, final ResultRow row) { 82 protected String[] formatPDFRow(final ExportContextPDF exportContext, final ResultRow row) {
80 83
81 return this.formatRow(exportContextPDF, results, row, ExportMode.pdf); 84 return this.formatRow(exportContext, row, ExportMode.pdf);
82 } 85 }
83 86
84 @Override 87 @Override
85 protected String getJasperFile() { 88 protected String getJasperFile() {
86 return JASPER_FILE; 89 return JASPER_FILE;
87 } 90 }
88 91
89 @Override 92 @Override
90 protected void addJRTableHeader(final ExportContextCSV exportContextPDF, final MetaAndTableJRDataSource source, final TkhCalculationResults results) { 93 protected void addJRTableHeader(final ExportContextPDF exportContext, final MetaAndTableJRDataSource source) {
91 /* column headings */ 94 /* column headings */
92 exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station); 95 exportContext.addJRMetadata(source, "station_header", GeneralResultType.station);
93 exportContextPDF.addJRMetadata(source, "tkh_header", SInfoResultType.tkh); 96 exportContext.addJRMetadata(source, "tkh_header", SInfoResultType.tkh);
94 exportContextPDF.addJRMetadata(source, "tkhkind_header", SInfoResultType.soilkind); 97 exportContext.addJRMetadata(source, "tkhkind_header", SInfoResultType.soilkind);
95 exportContextPDF.addJRMetadata(source, "bedheight_header", SInfoResultType.meanBedHeight); 98 exportContext.addJRMetadata(source, "bedheight_header", SInfoResultType.meanBedHeight);
96 exportContextPDF.addJRMetadata(source, "waterlevel_header", SInfoResultType.waterlevel); 99 exportContext.addJRMetadata(source, "waterlevel_header", SInfoResultType.waterlevel);
97 exportContextPDF.addJRMetadata(source, "discharge_header", SInfoResultType.discharge); 100 exportContext.addJRMetadata(source, "discharge_header", SInfoResultType.discharge);
98 101
99 // REMARK: actually the column makes no sense if description header is null. But (software symmetry...) WINFO also 102 // REMARK: actually the column makes no sense if description header is null. But (software symmetry...) WINFO also
100 // writes an empty column into the pdf in that case (most probably to avoid the need for two jasper templates). 103 // writes an empty column into the pdf in that case (most probably to avoid the need for two jasper templates).
104
105 final TkhCalculationResults results = exportContext.getResults();
101 final String descriptionHeader = results.getDescriptionHeader(); 106 final String descriptionHeader = results.getDescriptionHeader();
102 final String waterlevelNameHeader = descriptionHeader == null ? exportContextPDF.msgPdf(SInfoResultType.waterlevelLabel) : descriptionHeader;
103 exportContextPDF.addJRMetadata(source, "waterlevel_name_header", waterlevelNameHeader);
104 107
105 exportContextPDF.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel); 108 final String waterlevelNameHeader = descriptionHeader == null ? exportContext.msgPdf(SInfoResultType.waterlevelLabel) : descriptionHeader;
106 exportContextPDF.addJRMetadata(source, "location_header", SInfoResultType.location); 109 exportContext.addJRMetadata(source, "waterlevel_name_header", waterlevelNameHeader);
110
111 exportContext.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel);
112 exportContext.addJRMetadata(source, "location_header", SInfoResultType.location);
107 113
108 } 114 }
109 115
110 private String[] formatRow(final ExportContextCSV exportContext, final TkhCalculationResults results, final ResultRow row, final ExportMode mode) { 116 private String[] formatRow(final IExportContext exportContext, final ResultRow row, final ExportMode mode) {
111 117
112 final Collection<String> lines = new ArrayList<>(11); 118 final Collection<String> lines = new ArrayList<>(11);
113 119
114 lines.add(exportContext.formatRowValue(row, GeneralResultType.station)); 120 lines.add(exportContext.formatRowValue(row, GeneralResultType.station));
115 lines.add(exportContext.formatRowValue(row, SInfoResultType.tkh)); 121 lines.add(exportContext.formatRowValue(row, SInfoResultType.tkh));
117 lines.add(exportContext.formatRowValue(row, SInfoResultType.meanBedHeight)); 123 lines.add(exportContext.formatRowValue(row, SInfoResultType.meanBedHeight));
118 lines.add(exportContext.formatRowValue(row, SInfoResultType.waterlevel)); 124 lines.add(exportContext.formatRowValue(row, SInfoResultType.waterlevel));
119 lines.add(exportContext.formatRowValue(row, SInfoResultType.discharge)); 125 lines.add(exportContext.formatRowValue(row, SInfoResultType.discharge));
120 126
121 // REMARK: always export this column in pdf-mode, because WInfo also does it (no need for two jasper-templates). 127 // REMARK: always export this column in pdf-mode, because WInfo also does it (no need for two jasper-templates).
122 if (results.getDescriptionHeader() != null || mode == ExportMode.pdf) 128 final TkhCalculationResults results = exportContext.getResults();
129 final String descriptionHeader = results.getDescriptionHeader();
130 if (descriptionHeader != null || mode == ExportMode.pdf)
123 lines.add(exportContext.formatRowValue(row, SInfoResultType.waterlevelLabel)); 131 lines.add(exportContext.formatRowValue(row, SInfoResultType.waterlevelLabel));
124 132
125 lines.add(exportContext.formatRowValue(row, SInfoResultType.gaugeLabel)); 133 lines.add(exportContext.formatRowValue(row, SInfoResultType.gaugeLabel));
126 lines.add(exportContext.formatRowValue(row, SInfoResultType.location)); 134 lines.add(exportContext.formatRowValue(row, SInfoResultType.location));
127 135
128 return lines.toArray(new String[lines.size()]); 136 return lines.toArray(new String[lines.size()]);
129 } 137 }
130
131 } 138 }

http://dive4elements.wald.intevation.org