diff artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationAccess.java @ 9481:787fc085459b

TSV introduced; uinfo.inundationWMS-Config
author gernotbelger
date Wed, 12 Sep 2018 10:55:09 +0200
parents 0633f963c5be
children bf6b63208f34
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationAccess.java	Mon Sep 10 17:06:23 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationAccess.java	Wed Sep 12 10:55:09 2018 +0200
@@ -10,10 +10,17 @@
 
 package org.dive4elements.river.artifacts.uinfo.inundationduration;
 
+import java.io.IOException;
+
+import org.dive4elements.artifacts.CallMeta;
 import org.dive4elements.river.artifacts.access.RangeAccess;
 import org.dive4elements.river.artifacts.common.EpochYearAccessHelper;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper.TsvReaderException;
 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact;
 import org.dive4elements.river.artifacts.uinfo.UinfoCalcMode;
+import org.dive4elements.river.artifacts.uinfo.inundationduration.InundationDurationCalculationResult.WmsLayer;
+import org.dive4elements.river.artifacts.uinfo.inundationduration.UedauernConfiguration.YearType;
 
 /**
  * Access to the flow depth calculation type specific SInfo artifact data.
@@ -36,7 +43,7 @@
     // calculation_mode (String)
     // ld_from, ld_to
     // ye_select (String; state.uinfo.totalepoch oder state.uinfo.year)
-    // singleyear (String)
+    // year_epoch_select
     // totalepoch (String; TODO: minmax totalEpoch herausfinden und setzen (nicht hier.. aber trotzdem die Erinnerung hier))
     // use_scenario boolean (danach kommt kein radioBtn, sondern sedimentheight-Eingabe)
     // sedimentheight String
@@ -51,41 +58,63 @@
         assert (calculationMode == UinfoCalcMode.uinfo_inundation_duration);
     }
 
-    public Integer getYear() {
-        final int[] years = this.helper.getYears("state.uinfo.year", "singleyear");
-        if (years != null) {
-            return years[0];
-        }
-        return null;
+    public boolean isUseYear() {
+        if (this.helper.getYearEpoch().equals("state.uinfo.year"))
+            return true;
+        return false;
     }
 
-    public String getWMSUrl() {
+    public WmsLayer createWMSLayer(final CallMeta meta, final String i10nKey) {
 
-        final UedauernPropertiesHelper helper = UedauernPropertiesHelper.getInstance(getRiverName());
-        if (this.getYear() != null) {
-            return helper.urlFromYear(this.getYear());
-        } else {
-            return helper.getMittelUrl(); // nur 2 cases...
+        final YearType type = isUseYear() ? YearType.jahre : YearType.mittel;
+        final String selectedElement = getSelectedLabel();
+
+        final String layerLabel = Resources.getMsg(meta, i10nKey, new Object[] { selectedElement });
+
+        try {
+            final UedauernConfiguration helper = UedauernConfiguration.getInstance(getRiverName(), type);
+            final String url = helper.getUrl(selectedElement);
+            final String layer = helper.getLayer(selectedElement);
+
+            return new WmsLayer(layerLabel, url, layer, true);
         }
+        catch (final IOException | TsvReaderException e) {
+            e.printStackTrace();
+        }
+        return null;
 
     }
 
-    public String getWMSScenarioUrl() {
-        if (getIsUseScenario()) {
-            final UedauernPropertiesHelper helper = UedauernPropertiesHelper.getInstance(getRiverName());
-            if (this.getYear() != null) {
-                return helper.getScenarioUrlFromYear(this.getYear(), this.getDwspl());
-            } else {
-                return helper.getMittelScenarioUrl(this.getDwspl()); // nur 2 cases...
-            }
+    public WmsLayer createScenarioWMSLayer(final CallMeta meta, final String i10nKey) {
+
+        // FIXME: use scenario-cm as label, and scenario-type
+        final YearType type = YearType.jahre;
+        final String selectedElement = Integer.toString(getDwspl());
+
+        final String layerLabel = Resources.getMsg(meta, i10nKey, new Object[] { selectedElement });
+
+        try {
+            final UedauernConfiguration helper = UedauernConfiguration.getInstance(getRiverName(), type);
+            final String url = helper.getUrl(selectedElement);
+            final String layer = helper.getLayer(selectedElement);
+
+            return new WmsLayer(layerLabel, url, layer, false);
         }
-        return "";
+        catch (final IOException | TsvReaderException e) {
+            e.printStackTrace();
+        }
+        return null;
+
     }
 
-    public Integer getDwspl() {
-        if (getIsUseScenario()) {
+    private String getSelectedLabel() {
+        return this.getString("year_epoch_select");
+    }
+
+    private Integer getDwspl() {
+        if (getIsUseScenario())
             return super.getInteger("sedimentheight");
-        }
+
         return null;
     }
 
@@ -97,12 +126,4 @@
     public boolean getIsUseScenario() {
         return super.getBoolean("use_scenario");
     }
-
-    public Integer[] mittelStartEndYears() {
-        if (getIsUseScenario()) {
-            final UedauernPropertiesHelper helper = UedauernPropertiesHelper.getInstance(getRiverName());
-            return helper.getMittelStartEnd();
-        }
-        return null;
-    }
 }
\ No newline at end of file

http://dive4elements.wald.intevation.org