diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculationResult.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 2ed3824a3d53
children a4121ec450d6
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculationResult.java	Thu Jun 14 15:12:25 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculationResult.java	Thu Jun 14 16:56:31 2018 +0200
@@ -9,11 +9,17 @@
  */
 package org.dive4elements.river.artifacts.sinfo.flowdepthminmax;
 
+import java.util.ArrayList;
 import java.util.Collection;
 
+import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
+import org.dive4elements.river.artifacts.common.ExportContextCSV;
+import org.dive4elements.river.artifacts.common.GeneralResultType;
+import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
 import org.dive4elements.river.artifacts.common.ResultRow;
-import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoCalculationResult;
+import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo;
+import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
 import org.dive4elements.river.artifacts.sinfo.util.WstInfo;
 
 /**
@@ -21,20 +27,112 @@
  *
  * @author Gernot Belger
  */
-final class FlowDepthMinMaxCalculationResult extends AbstractSInfoCalculationResult {
+final class FlowDepthMinMaxCalculationResult extends AbstractCalculationExportableResult<FlowDepthMinMaxCalculationResults> {
 
     private static final long serialVersionUID = 1L;
+    private static final String JASPER_FILE = "/jasper/templates/sinfo.flowdepthminmax.jrxml";
 
     private final BedHeightInfo sounding;
+    private final WstInfo wst;
 
-    public FlowDepthMinMaxCalculationResult(final String label, final WstInfo wst, final BedHeightInfo sounding,
-            final Collection<ResultRow> rows) {
-        super(label, wst, rows);
-
+    public FlowDepthMinMaxCalculationResult(final String label, final WstInfo wst, final BedHeightInfo sounding, final Collection<ResultRow> rows) {
+        super(label, rows);
+        this.wst = wst;
         this.sounding = sounding;
     }
 
     public BedHeightInfo getSounding() {
         return this.sounding;
     }
+
+    @Override
+    public void writeCSVHeader(final ExportContextCSV exportContextCSV, final FlowDepthMinMaxCalculationResults results, final RiverInfo river) {
+
+        final Collection<String> header = new ArrayList<>(11);
+
+        header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station));
+        header.add(exportContextCSV.msgUnitCSV(SInfoResultType.flowdepthmin));
+        header.add(exportContextCSV.msgUnitCSV(SInfoResultType.flowdepthmax));
+        header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel, river.getWstUnit()));
+        header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge));
+        header.add(exportContextCSV.formatCsvHeader(SInfoResultType.waterlevelLabel));
+        header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel));
+        header.add(exportContextCSV.msgUnitCSV(SInfoResultType.meanBedHeight, river.getWstUnit()));
+        header.add(exportContextCSV.formatCsvHeader(SInfoResultType.soundingLabel));
+        header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location));
+
+        exportContextCSV.writeCSVLine(header.toArray(new String[header.size()]));
+
+    }
+
+    @Override
+    protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV, final FlowDepthMinMaxCalculationResults results) {
+
+        exportContextCSV.writeCSVSoundingMetadata(this.sounding);
+        exportContextCSV.writeBlankLine();
+
+        exportContextCSV.writeCSVWaterlevelMetadata(this.wst);
+        exportContextCSV.writeBlankLine();
+
+    }
+
+    @Override
+    protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final FlowDepthMinMaxCalculationResults results, final ResultRow row) {
+
+        return formatRow(exportContextCSV, results, row);
+    }
+
+    @Override
+    protected String[] formatPDFRow(final ExportContextCSV exportContextPDF, final FlowDepthMinMaxCalculationResults results, final ResultRow row) {
+
+        return formatRow(exportContextPDF, results, row);
+    }
+
+    @Override
+    protected String getJasperFile() {
+        return this.JASPER_FILE;
+    }
+
+    @Override
+    protected void addJRTableHeader(final ExportContextCSV exportContextPDF, final MetaAndTableJRDataSource source,
+            final FlowDepthMinMaxCalculationResults results) {
+
+        /* column headings */
+        exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station);
+        exportContextPDF.addJRMetadata(source, "flowdepthmin_header", SInfoResultType.flowdepthmin);
+        exportContextPDF.addJRMetadata(source, "flowdepthmax_header", SInfoResultType.flowdepthmax);
+        exportContextPDF.addJRMetadata(source, "waterlevel_header", SInfoResultType.waterlevel);
+        exportContextPDF.addJRMetadata(source, "discharge_header", SInfoResultType.discharge);
+        exportContextPDF.addJRMetadata(source, "waterlevel_name_header", SInfoResultType.waterlevelLabel);
+        exportContextPDF.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel);
+        exportContextPDF.addJRMetadata(source, "bedheight_header", SInfoResultType.meanBedHeight);
+        exportContextPDF.addJRMetadata(source, "sounding_name_header", SInfoResultType.soundingLabel);
+        exportContextPDF.addJRMetadata(source, "location_header", SInfoResultType.location);
+
+    }
+
+    protected String[] formatRow(final ExportContextCSV exportContextCSV, final FlowDepthMinMaxCalculationResults results, final ResultRow row) {
+
+        final Collection<String> lines = new ArrayList<>(10);
+
+        lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station));
+
+        // 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(exportContextCSV.formatRowValue(row, SInfoResultType.flowdepthmin));
+        // if (result == null || result.getMaxSounding() != null)
+        lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.flowdepthmax));
+
+        lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevel));
+        lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.discharge));
+        lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevelLabel));
+        lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.gaugeLabel));
+        lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.meanBedHeight));
+        lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.soundingLabel));
+        lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.location));
+
+        return lines.toArray(new String[lines.size()]);
+    }
 }
\ No newline at end of file

http://dive4elements.wald.intevation.org