Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoExporter.java @ 8948:a4f1ac81f26d
Work on SINFO-FlowDepthMinMax.
Also rework of result row stuff, in order to reduce abstraction, using result type concept
author | gernotbelger |
---|---|
date | Wed, 14 Mar 2018 14:10:32 +0100 |
parents | 5d5d482da3e9 |
children | c40db8e8dcae |
comparison
equal
deleted
inserted
replaced
8947:86650594f051 | 8948:a4f1ac81f26d |
---|---|
40 import net.sf.jasperreports.engine.JasperPrint; | 40 import net.sf.jasperreports.engine.JasperPrint; |
41 | 41 |
42 /** | 42 /** |
43 * @author Gernot Belger | 43 * @author Gernot Belger |
44 */ | 44 */ |
45 public abstract class AbstractSInfoExporter<ROW extends AbstractSInfoResultRow, RESULT extends AbstractSInfoCalculationResult<ROW>, RESULTS extends AbstractSInfoCalculationResults<ROW, RESULT>> extends AbstractExporter { | 45 public abstract class AbstractSInfoExporter<RESULT extends AbstractSInfoCalculationResult, RESULTS extends AbstractSInfoCalculationResults<RESULT>> extends AbstractExporter { |
46 | 46 |
47 private static final String CSV_META_HEADER_SOUNDING = "sinfo.export.flow_depth.csv.meta.header.sounding"; | 47 private static final String CSV_META_HEADER_SOUNDING = "sinfo.export.flow_depth.csv.meta.header.sounding"; |
48 | 48 |
49 private static final String CSV_META_HEADER_SOUNDING_YEAR = "sinfo.export.flow_depth.csv.meta.header.sounding.year"; | 49 private static final String CSV_META_HEADER_SOUNDING_YEAR = "sinfo.export.flow_depth.csv.meta.header.sounding.year"; |
50 | 50 |
118 protected final void writeCSVResult(final CSVWriter writer, final RESULTS results, final RESULT result) { | 118 protected final void writeCSVResult(final CSVWriter writer, final RESULTS results, final RESULT result) { |
119 | 119 |
120 writeCSVResultMetadata(writer, results, result); | 120 writeCSVResultMetadata(writer, results, result); |
121 | 121 |
122 /* nwo the value rows */ | 122 /* nwo the value rows */ |
123 final Collection<ROW> rows = result.getRows(); | 123 final Collection<SInfoResultRow> rows = result.getRows(); |
124 for (final ROW row : rows) { | 124 for (final SInfoResultRow row : rows) { |
125 writeCSVRow(writer, results, row); | 125 writeCSVRow(writer, results, result, row); |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 /** | 129 /** |
130 * Add metadata that is written once per result set. | 130 * Add metadata that is written once per result set. |
131 */ | 131 */ |
132 protected abstract void writeCSVResultMetadata(CSVWriter writer, RESULTS results, RESULT result); | 132 protected abstract void writeCSVResultMetadata(CSVWriter writer, RESULTS results, RESULT result); |
133 | 133 |
134 protected final void writeCSVRow(final CSVWriter writer, final RESULTS results, final ROW row) { | 134 protected final void writeCSVRow(final CSVWriter writer, final RESULTS results, final RESULT result, final SInfoResultRow row) { |
135 getLog().debug("writeCSVFlowDepthRow"); | 135 getLog().debug("writeCSVFlowDepthRow"); |
136 | 136 |
137 final String[] formattedRow = formatCSVRow(results, row); | 137 final String[] formattedRow = formatCSVRow(results, result, row); |
138 writer.writeNext(formattedRow); | 138 writer.writeNext(formattedRow); |
139 } | 139 } |
140 | 140 |
141 protected abstract String[] formatCSVRow(RESULTS results, final ROW row); | 141 protected abstract String[] formatCSVRow(RESULTS results, RESULT result, final SInfoResultRow row); |
142 | 142 |
143 @Override | 143 @Override |
144 protected final void writePDF(final OutputStream outStream) { | 144 protected final void writePDF(final OutputStream outStream) { |
145 getLog().debug("write PDF"); | 145 getLog().debug("write PDF"); |
146 | 146 |
184 | 184 |
185 protected abstract void addJRMetaData(final MetaAndTableJRDataSource source, final RESULTS results); | 185 protected abstract void addJRMetaData(final MetaAndTableJRDataSource source, final RESULTS results); |
186 | 186 |
187 protected final void addJRTableData(final MetaAndTableJRDataSource source, final RESULTS results, final RESULT result) { | 187 protected final void addJRTableData(final MetaAndTableJRDataSource source, final RESULTS results, final RESULT result) { |
188 | 188 |
189 final Collection<ROW> rows = result.getRows(); | 189 final Collection<SInfoResultRow> rows = result.getRows(); |
190 | 190 |
191 for (final ROW row : rows) { | 191 for (final SInfoResultRow row : rows) { |
192 | 192 |
193 final String[] formattedRow = formatPDFRow(results, row); | 193 final String[] formattedRow = formatPDFRow(results, row); |
194 source.addData(formattedRow); | 194 source.addData(formattedRow); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 protected abstract String[] formatPDFRow(RESULTS results, final ROW row); | 198 protected abstract String[] formatPDFRow(RESULTS results, final SInfoResultRow row); |
199 | 199 |
200 protected final void writeCSVGlobalMetadataDefaults(final CSVWriter writer, final AbstractSInfoCalculationResults<?, ?> results) { | 200 protected final void writeCSVGlobalMetadataDefaults(final CSVWriter writer, final AbstractSInfoCalculationResults<?> results) { |
201 | 201 |
202 final String calcModeLabel = results.getCalcModeLabel(); | 202 final String calcModeLabel = results.getCalcModeLabel(); |
203 final RiverInfo river = results.getRiver(); | 203 final RiverInfo river = results.getRiver(); |
204 final DoubleRange calcRange = results.getCalcRange(); | 204 final DoubleRange calcRange = results.getCalcRange(); |
205 | 205 |
259 final int year = wst.getYear(); | 259 final int year = wst.getYear(); |
260 if (year > 0) | 260 if (year > 0) |
261 writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_YEAR, Integer.toString(year)); | 261 writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_YEAR, Integer.toString(year)); |
262 } | 262 } |
263 | 263 |
264 protected final void addJRMetaDataDefaults(final MetaAndTableJRDataSource source, final AbstractSInfoCalculationResults<?, ?> results) { | 264 protected final void addJRMetaDataDefaults(final MetaAndTableJRDataSource source, final AbstractSInfoCalculationResults<?> results) { |
265 | 265 |
266 final RiverInfo river = results.getRiver(); | 266 final RiverInfo river = results.getRiver(); |
267 final String wstUnitName = river.getWstUnit(); | 267 final String wstUnitName = river.getWstUnit(); |
268 | 268 |
269 source.addMetaData("header", msg(SInfoI18NStrings.CSV_META_HEADER_RESULT_LABEL)); | 269 source.addMetaData("header", msg(SInfoI18NStrings.CSV_META_HEADER_RESULT_LABEL)); |