changeset 9294:7a8b9331a946

Moved waterlevel metadata block to global metadata, because its only written once
author gernotbelger
date Tue, 24 Jul 2018 16:55:43 +0200
parents e3e465766cfe
children 385b52ccde23
files artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationExporter.java
diffstat 2 files changed, 39 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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

http://dive4elements.wald.intevation.org