diff artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationAccess.java @ 9559:ba0561906f81

Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
author gernotbelger
date Wed, 24 Oct 2018 18:40:38 +0200
parents bf6b63208f34
children 63bbd5e45839
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationAccess.java	Wed Oct 24 12:00:49 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationAccess.java	Wed Oct 24 18:40:38 2018 +0200
@@ -11,8 +11,6 @@
 package org.dive4elements.river.artifacts.uinfo.inundationduration;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
 
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.river.artifacts.access.RangeAccess;
@@ -22,7 +20,7 @@
 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;
+import org.dive4elements.river.artifacts.uinfo.inundationduration.UedauernConfiguration.WmsConfig;
 
 /**
  * Access to the flow depth calculation type specific SInfo artifact data.
@@ -34,39 +32,37 @@
  */
 final class InundationDurationAccess extends RangeAccess {
 
-    // IMMER ABGLEICHEN MIT SuperVegZonesTablePanel.TABLE_CELL_SEPARATOR
-    public static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR";
-    public static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR";
-
     private final EpochYearAccessHelper helper;
 
-    public static enum WmsClassification {
-        asIs {
-            @Override
-            public String configureAddress(final String serverAddress, final String url, final String vegetationZoneId) {
-                return url;
-            }
-        },
-        vegetationZone {
-            @Override
-            public String configureAddress(final String serverAddress, final String url, final String vegetationZoneId) {
-
-                try {
-                    final String urlEncoded = URLEncoder.encode(url, "UTF-8");
-                    final String vegZoneIdEncoded = URLEncoder.encode(vegetationZoneId, "UTF-8");
-
-                    return String.format("%s/%s/%s/%s", serverAddress, VegetationWmsResource.BASE_PATH, vegZoneIdEncoded, urlEncoded);
-                }
-                catch (final UnsupportedEncodingException e) {
-                    /* should never happen */
-                    e.printStackTrace();
-                    return null;
-                }
-            }
-        };
-
-        public abstract String configureAddress(String serverAddress, String url, String vegetationZoneId);
-    }
+    // public static enum WmsClassification {
+    // asIs {
+    // @Override
+    // public String configureAddress(final WmsConfig config) {
+    // return config.getUrl();
+    // }
+    // }
+    // // ,
+    // // vegetationZone {
+    // // @Override
+    // // public String configureAddress(final String serverAddress, final String url, final String vegetationZoneId) {
+    // //
+    // // try {
+    // // final String urlEncoded = URLEncoder.encode(url, "UTF-8");
+    // // final String vegZoneIdEncoded = URLEncoder.encode(vegetationZoneId, "UTF-8");
+    // //
+    // // return String.format("%s/%s/%s/%s", serverAddress, VegetationWmsResource.BASE_PATH, vegZoneIdEncoded, urlEncoded);
+    // // }
+    // // catch (final UnsupportedEncodingException e) {
+    // // /* should never happen */
+    // // e.printStackTrace();
+    // // return null;
+    // // }
+    // // }
+    // // }
+    // ;
+    //
+    // public abstract String configureAddress(final WmsConfig config);
+    // }
 
     // Fields from state:
     //
@@ -94,60 +90,59 @@
         return false;
     }
 
-    public WmsLayer createWMSLayer(final CallContext context, final String i10nKey, final WmsClassification classification, final String vegZoneId)
-            throws IOException, TsvReaderException {
+    // public WmsLayer createWMSLayer(final CallContext context, final String i10nKey, final WmsConfig classification)
+    // throws IOException, TsvReaderException {
+    //
+    // final YearType type = isUseYear() ? YearType.jahre : YearType.mittel;
+    // final String selectedElement = getSelectedLabel();
+    //
+    // final String layerLabel = Resources.getMsg(context.getMeta(), i10nKey, new Object[] { selectedElement });
+    //
+    // return createWMSLayer(context, layerLabel, type, selectedElement, classification);
+    // }
 
-        final YearType type = isUseYear() ? YearType.jahre : YearType.mittel;
-        final String selectedElement = getSelectedLabel();
+    // public WmsLayer createScenarioWMSLayer(final CallContext context, final String i10nKey, final WmsConfig
+    // classification, final String vegZoneId)
+    // throws IOException, TsvReaderException {
+    //
+    // // 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(context.getMeta(), i10nKey, new Object[] { selectedElement });
+    //
+    // return createWMSLayer(context, layerLabel, type, selectedElement, classification);
+    // }
 
-        final String layerLabel = Resources.getMsg(context.getMeta(), i10nKey, new Object[] { selectedElement });
+    public WmsLayer createWMSLayer(final CallContext context, final String layerLabel, final String selectedItem, final WmsConfig config,
+            final boolean showLayerLink) throws IOException, TsvReaderException {
 
-        return createWMSLayer(context, layerLabel, type, selectedElement, classification, vegZoneId);
+        // final String serverAddress = context.getDatabase().getServerAddress();
+        // final UedauernConfiguration config = UedauernConfiguration.getInstance(getRiverName(), type);
+
+        final String layerLabelFinal = Resources.getMsg(context.getMeta(), layerLabel, new Object[] { selectedItem });
+        final String url = config.getUrl();
+        final String layer = config.getLayer();
+
+        if (url != null && layer != null) {
+            // final String realUrl = classification.configureAddress(serverAddress, url, vegZoneId);
+
+            return new WmsLayer(layerLabelFinal, url, layer, showLayerLink);
+        }
+        return null;
     }
 
-    public WmsLayer createScenarioWMSLayer(final CallContext context, final String i10nKey, final WmsClassification classification, final String vegZoneId)
-            throws IOException, TsvReaderException {
-
-        // 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(context.getMeta(), i10nKey, new Object[] { selectedElement });
-
-        return createWMSLayer(context, layerLabel, type, selectedElement, classification, vegZoneId);
-    }
-
-    private WmsLayer createWMSLayer(final CallContext context, final String layerLabel, final YearType type, final String selectedElement,
-            final WmsClassification classification, final String vegZoneId)
-                    throws IOException, TsvReaderException {
-
-        final String serverAddress = context.getDatabase().getServerAddress();
-
-        final UedauernConfiguration config = UedauernConfiguration.getInstance(getRiverName(), type);
-        final String url = config.getUrl(selectedElement);
-        final String layer = config.getLayer(selectedElement);
-
-        final String realUrl = classification.configureAddress(serverAddress, url, vegZoneId);
-
-        return new WmsLayer(layerLabel, realUrl, layer, classification == WmsClassification.asIs);
-    }
-
-    private String getSelectedLabel() {
+    public String getSelectedLabel() {
         return this.getString("year_epoch_select");
     }
 
-    private Integer getDwspl() {
+    public String getSelectedSzenario() {
         if (getIsUseScenario())
-            return super.getInteger("sedimentheight");
+            return super.getString("inundation_scenario");
 
         return null;
     }
 
-    public String getVegZones() {
-        // mit VegetationzonesAccess zusammenlegen (eine Zeile sparen...)
-        return super.getString("vegzones");
-    }
-
     public boolean getIsUseScenario() {
         return super.getBoolean("use_scenario");
     }

http://dive4elements.wald.intevation.org