[PATCH] Moved waterlevel metadata block to global metadata, because its only written once

Wald Commits scm-commit at wald.intevation.org
Tue Jul 24 16:55:48 CEST 2018


# HG changeset patch
# User gernotbelger
# Date 1532444143 -7200
# Node ID 7a8b9331a94672331aa680da89e56f00970a5555
# Parent  e3e465766cfe8823cb4b7507e2d2fe5770844260
Moved waterlevel metadata block to global metadata, because its only written once

diff -r e3e465766cfe -r 7a8b9331a946 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java	Tue Jul 24 16:02:40 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java	Tue Jul 24 16:55:43 2018 +0200
@@ -24,7 +24,6 @@
 import org.dive4elements.river.artifacts.common.IResultType;
 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
 import org.dive4elements.river.artifacts.common.ResultRow;
-import org.dive4elements.river.artifacts.sinfo.common.SInfoI18NStrings;
 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
 import org.dive4elements.river.model.Attribute.AttributeKey;
@@ -58,8 +57,6 @@
 
     private final String[] waterlevelLabels;
 
-    // private final WstInfo wstInfo;
-
     private final int maxWaterlevelPdf = 3;
 
     public interface ValueGetter {
@@ -94,21 +91,7 @@
 
     @Override
     protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) {
-        if (this.waterlevelLabels.length >= 1) {
-            // "##METADATEN WASSERSPIEGELLAGE"
-            exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL);
-            for (int i = 1; i <= getWaterlevelCount(); i++) {
-                // "# Bezeichnung der Wasserspiegellage: "
-                final String label = this.getWaterlevelLabel(i - 1);
-                exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_NAME, String.format("%d: %s", i, label));
-            }
-            // "# Bezugspegel: "
-            for (final ResultRow row : getRows()) {
-                exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_GAUGE, row.getValue(SInfoResultType.gaugeLabel));
-                break;
-            }
-        }
-        exportContextCSV.writeBlankLine();
+        /* nothing to do, as we never have several results, everything is written into the general header */
     }
 
     @Override
diff -r e3e465766cfe -r 7a8b9331a946 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationExporter.java	Tue Jul 24 16:02:40 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationExporter.java	Tue Jul 24 16:55:43 2018 +0200
@@ -8,11 +8,16 @@
 
 package org.dive4elements.river.artifacts.sinfo.flood_duration;
 
+import java.util.List;
+
 import org.dive4elements.river.artifacts.common.AbstractCommonExporter;
 import org.dive4elements.river.artifacts.common.ExportContextCSV;
 import org.dive4elements.river.artifacts.common.ExportContextPDF;
 import org.dive4elements.river.artifacts.common.JasperDesigner;
 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
+import org.dive4elements.river.artifacts.common.ResultRow;
+import org.dive4elements.river.artifacts.sinfo.common.SInfoI18NStrings;
+import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
 
 /**
  * Generates different output formats (csv, pdf) of data that resulted from a flood duration computation.
@@ -27,6 +32,33 @@
     @Override
     protected void writeCSVGlobalMetadata(final ExportContextCSV exportContext, final FloodDurationCalculationResults results) {
         exportContext.writeCSVGlobalMetadataDefaults();
+
+        exportContext.writeBlankLine();
+
+        final List<FloodDurationCalculationResult> resultList = results.getResults();
+        if (resultList.isEmpty())
+            return;
+
+        final FloodDurationCalculationResult result = resultList.get(0);
+
+        final int waterlevelCount = result.getWaterlevelCount();
+        if (waterlevelCount >= 1) {
+
+            // "##METADATEN WASSERSPIEGELLAGE"
+            exportContext.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL);
+
+            for (int i = 0; i < waterlevelCount; i++) {
+                // "# Bezeichnung der Wasserspiegellage: "
+                final String label = result.getWaterlevelLabel(i);
+                exportContext.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_NAME, String.format("%d: %s", i + 1, label));
+            }
+
+            // "# Bezugspegel: "
+            for (final ResultRow row : result.getRows()) {
+                exportContext.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_GAUGE, row.getValue(SInfoResultType.gaugeLabel));
+                break;
+            }
+        }
     }
 
     @Override
@@ -36,14 +68,12 @@
 
     @Override
     protected void configureDesign(final FloodDurationCalculationResult result, final JasperDesigner design) {
-        if (result instanceof FloodDurationCalculationResult) {
-            final int wlCount = result.getWaterlevelCount();
-            if (wlCount == 0 || wlCount == 2) {
-                design.removeColumn("wOpt");
-                design.removeColumn("qOpt");
-                design.removeColumn("bezOpt");
-                design.removeColumn("durOpt");
-            }
+        final int wlCount = result.getWaterlevelCount();
+        if (wlCount == 0 || wlCount == 2) {
+            design.removeColumn("wOpt");
+            design.removeColumn("qOpt");
+            design.removeColumn("bezOpt");
+            design.removeColumn("durOpt");
         }
     }
 }
\ No newline at end of file


More information about the Dive4Elements-commits mailing list