diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxExporter.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 09e4a4909814
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxExporter.java	Wed Mar 14 14:09:33 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxExporter.java	Wed Mar 14 14:10:32 2018 +0100
@@ -11,15 +11,14 @@
 import java.util.ArrayList;
 import java.util.Collection;
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
-import org.dive4elements.river.artifacts.sinfo.SInfoI18NStrings;
 import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoExporter;
+import org.dive4elements.river.artifacts.sinfo.common.SInfoResultRow;
+import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo;
 import org.dive4elements.river.artifacts.sinfo.util.MetaAndTableJRDataSource;
 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
 import org.dive4elements.river.artifacts.sinfo.util.WstInfo;
-import org.dive4elements.river.utils.RiverUtils;
 
 import au.com.bytecode.opencsv.CSVWriter;
 
@@ -30,16 +29,12 @@
  * @author Gernot Belger
  */
 // REMARK: must be public because its registered in generators.xml
-public class FlowDepthMinMaxExporter extends AbstractSInfoExporter<FlowDepthMinMaxRow, FlowDepthMinMaxCalculationResult, FlowDepthMinMaxCalculationResults> {
+public class FlowDepthMinMaxExporter extends AbstractSInfoExporter<FlowDepthMinMaxCalculationResult, FlowDepthMinMaxCalculationResults> {
 
     /** The log used in this exporter. */
     private static Logger log = Logger.getLogger(FlowDepthMinMaxExporter.class);
 
-    private static final String CSV_FLOWDEPTH_MIN_HEADER = "sinfo.export.flow_depth_minmax.csv.header.min";
-
-    private static final String CSV_FLOWDEPTH_MAX_HEADER = "sinfo.export.flow_depth_minmax.csv.header.max";
-
-    private static final String JASPER_FILE = "/jasper/sinfo.flowdepth.jasper";
+    private static final String JASPER_FILE = "/jasper/sinfo.flowdepthminmax.jasper";
 
     @Override
     protected Logger getLog() {
@@ -78,72 +73,53 @@
 
         final Collection<String> header = new ArrayList<>(11);
 
-        header.add(msg(SInfoI18NStrings.CSV_KM_HEADER));
-
-        header.add(msgUnit(CSV_FLOWDEPTH_MIN_HEADER, SInfoI18NStrings.UNIT_M));
-        header.add(msgUnit(CSV_FLOWDEPTH_MAX_HEADER, SInfoI18NStrings.UNIT_M));
-
-        header.add(msgUnit(SInfoI18NStrings.CSV_WATERLEVEL_HEADER, river.getWstUnit()));
-        header.add(msgUnit(SInfoI18NStrings.CSV_DISCHARGE_HEADER, SInfoI18NStrings.UNIT_CUBIC_M));
-        header.add(msg(SInfoI18NStrings.CSV_LABEL_HEADER));
-        header.add(msg(SInfoI18NStrings.CSV_GAUGE_HEADER));
-        header.add(msgUnit(SInfoI18NStrings.CSV_MEAN_BED_HEIGHT_HEADER, river.getWstUnit()));
-        header.add(msg(SInfoI18NStrings.CSV_SOUNDING_HEADER));
-        header.add(msg(SInfoI18NStrings.CSV_LOCATION_HEADER));
+        header.add(msg(SInfoResultType.station.getCsvHeader()));
+        header.add(msgUnit(SInfoResultType.flowdepthmin.getCsvHeader(), SInfoResultType.flowdepthmin.getUnit()));
+        header.add(msgUnit(SInfoResultType.flowdepthmax.getCsvHeader(), SInfoResultType.flowdepthmax.getUnit()));
+        header.add(msgUnit(SInfoResultType.waterlevel.getCsvHeader(), river.getWstUnit()));
+        header.add(msgUnit(SInfoResultType.discharge.getCsvHeader(), SInfoResultType.discharge.getUnit()));
+        header.add(msg(SInfoResultType.waterlevelLabel.getCsvHeader()));
+        header.add(msg(SInfoResultType.gaugeLabel.getCsvHeader()));
+        header.add(msgUnit(SInfoResultType.meanBedHeight.getCsvHeader(), river.getWstUnit()));
+        header.add(msg(SInfoResultType.soundingLabel.getCsvHeader()));
+        header.add(msg(SInfoResultType.location.getCsvHeader()));
 
         writer.writeNext(header.toArray(new String[header.size()]));
     }
 
     @Override
-    protected String[] formatCSVRow(final FlowDepthMinMaxCalculationResults results, final FlowDepthMinMaxRow row) {
-        return formatFlowDepthRow(row);
+    protected String[] formatCSVRow(final FlowDepthMinMaxCalculationResults results, final FlowDepthMinMaxCalculationResult result, final SInfoResultRow row) {
+        return formatRow(result, row);
     }
 
     /**
      * Format a row of a flow depth result into an array of string, both used by csv and pdf
      *
+     * @param result
+     *
      * @param useTkh
      */
-    private String[] formatFlowDepthRow(final FlowDepthMinMaxRow row) {
-
-        final Collection<String> lines = new ArrayList<>(11);
-
-        // Fluss-km
-        lines.add(getKmFormatter().format(row.getStation()));
-
-        // FIXME: spalten weglassen, wenn min oder max fehlt
-
-        // Minimale Fließtiefe [m]
-        lines.add(getFlowDepthFormatter().format(row.getMinFlowDepth()));
-        // Maximale Fließtiefe [m]
-        lines.add(getFlowDepthFormatter().format(row.getMaxFlowDepth()));
-
-        // Wasserstand [NN + m]
-        lines.add(getW2Formatter().format(row.getWaterlevel()));
+    private String[] formatRow(final FlowDepthMinMaxCalculationResult result, final SInfoResultRow row) {
 
-        // Q [m³/s]
-        final double discharge = row.getDischarge();
-        if (Double.isNaN(discharge))
-            lines.add(StringUtils.EMPTY);
-        else {
-            final double roundedDischarge = RiverUtils.roundQ(discharge);
-            lines.add(getQFormatter().format(roundedDischarge));
-        }
+        final Collection<String> lines = new ArrayList<>(10);
 
-        // Bezeichnung
-        lines.add(row.getWaterlevelLabel());
-
-        // Bezugspegel
-        lines.add(row.getGauge());
+        lines.add(row.exportValue(this.context, SInfoResultType.station));
 
-        // Mittlere Sohlhöhe [NN + m]
-        lines.add(getMeanBedHeighFormatter().format(row.getMeanBedHeight()));
+        // REMARK: null check as pdf will call this with null and in that case we show all columns (to avoid multiple jasper
+        // FIXME: does not work like this: we may have several pairs of min/max; so we need to look at all of them?
+        // templates)
+        // if (result == null || result.getMinSounding() != null)
+        lines.add(row.exportValue(this.context, SInfoResultType.flowdepthmin));
+        // if (result == null || result.getMaxSounding() != null)
+        lines.add(row.exportValue(this.context, SInfoResultType.flowdepthmax));
 
-        // Peilung/Epoche
-        lines.add(row.getSoundageLabel());
-
-        // Lage
-        lines.add(row.getLocation());
+        lines.add(row.exportValue(this.context, SInfoResultType.waterlevel));
+        lines.add(row.exportValue(this.context, SInfoResultType.discharge));
+        lines.add(row.exportValue(this.context, SInfoResultType.waterlevelLabel));
+        lines.add(row.exportValue(this.context, SInfoResultType.gaugeLabel));
+        lines.add(row.exportValue(this.context, SInfoResultType.meanBedHeight));
+        lines.add(row.exportValue(this.context, SInfoResultType.soundingLabel));
+        lines.add(row.exportValue(this.context, SInfoResultType.location));
 
         return lines.toArray(new String[lines.size()]);
     }
@@ -160,20 +136,20 @@
         super.addJRMetaDataDefaults(source, results);
 
         /* column headings */
-        source.addMetaData("station_header", msg(SInfoI18NStrings.CSV_KM_HEADER));
-        source.addMetaData("flowdepthmin_header", msg(CSV_FLOWDEPTH_MIN_HEADER));
-        source.addMetaData("flowdepthmax_header", msg(CSV_FLOWDEPTH_MAX_HEADER));
-        source.addMetaData("waterlevel_header", msg(SInfoI18NStrings.CSV_WATERLEVEL_HEADER));
-        source.addMetaData("discharge_header", msg(SInfoI18NStrings.CSV_DISCHARGE_HEADER));
-        source.addMetaData("waterlevel_name_header", msg(SInfoI18NStrings.CSV_LABEL_HEADER));
-        source.addMetaData("gauge_header", msg(SInfoI18NStrings.CSV_GAUGE_HEADER));
-        source.addMetaData("bedheight_header", msg(SInfoI18NStrings.CSV_MEAN_BED_HEIGHT_HEADER_SHORT));
-        source.addMetaData("sounding_name_header", msg(SInfoI18NStrings.CSV_SOUNDING_HEADER));
-        source.addMetaData("location_header", msg(SInfoI18NStrings.CSV_LOCATION_HEADER));
+        source.addMetaData("station_header", msg(SInfoResultType.station.getCsvHeader()));
+        source.addMetaData("flowdepthmin_header", msg(SInfoResultType.flowdepthmin.getCsvHeader()));
+        source.addMetaData("flowdepthmax_header", msg(SInfoResultType.flowdepthmax.getCsvHeader()));
+        source.addMetaData("waterlevel_header", msg(SInfoResultType.waterlevel.getCsvHeader()));
+        source.addMetaData("discharge_header", msg(SInfoResultType.discharge.getCsvHeader()));
+        source.addMetaData("waterlevel_name_header", msg(SInfoResultType.waterlevelLabel.getCsvHeader()));
+        source.addMetaData("gauge_header", msg(SInfoResultType.gaugeLabel.getCsvHeader()));
+        source.addMetaData("bedheight_header", msg(SInfoResultType.meanBedHeight.getCsvHeader()));
+        source.addMetaData("sounding_name_header", msg(SInfoResultType.soundingLabel.getCsvHeader()));
+        source.addMetaData("location_header", msg(SInfoResultType.location.getCsvHeader()));
     }
 
     @Override
-    protected String[] formatPDFRow(final FlowDepthMinMaxCalculationResults results, final FlowDepthMinMaxRow row) {
-        return formatFlowDepthRow(row);
+    protected String[] formatPDFRow(final FlowDepthMinMaxCalculationResults results, final SInfoResultRow row) {
+        return formatRow(null, row);
     }
 }
\ No newline at end of file

http://dive4elements.wald.intevation.org