changeset 9184:dace17e26d33

code review uinfo.inundationduration
author gernotbelger
date Wed, 27 Jun 2018 14:07:02 +0200
parents 65543c75bfbb
children 4778333ea2cd
files artifacts/doc/conf/artifacts/uinfo.xml artifacts/doc/conf/uinfo_uedauern_aue_Beispielfluss.properties artifacts/doc/conf/uinfo_uedauern_aue_Elbe.properties artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/RiversideRadioChoice.java artifacts/src/main/java/org/dive4elements/river/artifacts/states/RadioSelect.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/CalculationSelectUinfo.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationAccess.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/LoadSingleYearSelectState.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/UedauernPropertiesHelper.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/YearChoice.java gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties
diffstat 12 files changed, 75 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/doc/conf/artifacts/uinfo.xml	Tue Jun 26 20:19:31 2018 +0200
+++ b/artifacts/doc/conf/artifacts/uinfo.xml	Wed Jun 27 14:07:02 2018 +0200
@@ -226,15 +226,6 @@
           </facets>
         </outputmode>
 
-        <!-- FIXME: i01n name in FLYSConstants -->
-        <outputmode name="uinfo_inundation_duration_export" description="output.uinfo_inundation_duration_export" mime-type="text/plain" type="export">
-          <facets>
-            <facet name="csv" description="facet.uinfo_inundation_duration_export.csv" />
-            <facet name="pdf" description="facet.uinfo_inundation_duration_export.pdf" />
-          </facets>
-        </outputmode>
-
-        <!-- FIXME: i01n name in FLYSConstants -->
         <outputmode name="uinfo_inundation_duration_report" description="output.uinfo_inundation_duration_report" mime-type="text/xml" type="report">
           <facets>
             <facet name="report" description="facet.uinfo_inundation_duration_report" />
--- a/artifacts/doc/conf/uinfo_uedauern_aue_Beispielfluss.properties	Tue Jun 26 20:19:31 2018 +0200
+++ b/artifacts/doc/conf/uinfo_uedauern_aue_Beispielfluss.properties	Wed Jun 27 14:07:02 2018 +0200
@@ -1,6 +1,10 @@
 jahre=1995,1996,1997
-url=htps://geoportal.bafg.de/wms/${jahr}
+#url=htps://geoportal.bafg.de/wms/${jahr}
+url=http://osm.intevation.de/bfg/service?
+scenario_url=htps://geoportal.bafg.de/wms/${jahr}_${scenario}
 
-mittel_url=htps://geoportal.bafg.de/wms/${jahr}
+#mittel_url=htps://geoportal.bafg.de/wms/${jahr}
+mittel_url=http://osm.intevation.de/bfg/service?
+mittel_scenario_url=htps://geoportal.bafg.de/wms/${scenario}
 mittel_start=8888
 mittel_ende=2000
\ No newline at end of file
--- a/artifacts/doc/conf/uinfo_uedauern_aue_Elbe.properties	Tue Jun 26 20:19:31 2018 +0200
+++ b/artifacts/doc/conf/uinfo_uedauern_aue_Elbe.properties	Wed Jun 27 14:07:02 2018 +0200
@@ -1,6 +1,8 @@
 jahre=1995,1996,1997
 url=htps://geoportal.bafg.de/wms/${jahr}
+scenario_url=htps://geoportal.bafg.de/wms/${jahr}_${scenario}
 
-mittel_url=htps://geoportal.bafg.de/wms/${jahr}
+mittel_url=htps://geoportal.bafg.de/wms/
 mittel_start=1998
-mittel_ende=2000
\ No newline at end of file
+mittel_ende=2000
+mittel_scenario_url=htps://geoportal.bafg.de/wms/${scenario}
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/RiversideRadioChoice.java	Tue Jun 26 20:19:31 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/RiversideRadioChoice.java	Wed Jun 27 14:07:02 2018 +0200
@@ -22,8 +22,6 @@
 
     private static final long serialVersionUID = 1L;
 
-    /***** TYPES *****/
-
     public enum RiversideChoiceKey {
         NONE("", AttributeKey.NONE), //
         LEFT("state.sinfo.riverside.left", AttributeKey.LEFT), //
@@ -55,14 +53,6 @@
         }
     }
 
-    /***** CONSTRUCTORS *****/
-
-    public RiversideRadioChoice() {
-        super();
-    }
-
-    /***** METHODS *****/
-
     @Override
     protected LinkedHashMap<String, String> makeEntries(final CallMeta meta, final Artifact artifact) {
         final LinkedHashMap<String, String> entries = new LinkedHashMap<>();
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/RadioSelect.java	Tue Jun 26 20:19:31 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/RadioSelect.java	Wed Jun 27 14:07:02 2018 +0200
@@ -26,14 +26,14 @@
 public abstract class RadioSelect extends DefaultState {
 
     private static final long serialVersionUID = 1L;
+    private Artifact artifact;
 
     public RadioSelect() {
 
     }
 
-    protected abstract LinkedHashMap<String, String> makeEntries(CallMeta meta, Artifact artifact); // AUSNAHMSWEISE EXPLIZITER TYP, damit gewährleistet ist,
-                                                                                                    // dass die Reihenfolge
-    // nicht verrutscht
+    protected abstract LinkedHashMap<String, String> makeEntries(CallMeta meta, Artifact artifact); // AUSNAHMSWEISE EXPLIZITER TYP, damit Reihenfolge nicht
+                                                                                                    // verrutscht
 
     @Override
     protected final String getUIProvider() {
@@ -42,6 +42,10 @@
 
     @Override
     protected Element[] createItems(final XMLUtils.ElementCreator ec, final Artifact artifact, final String name, final CallContext context) {
+
+        // REMEBER: we need it for getLabelFor later
+        this.artifact = artifact;
+
         final CallMeta meta = context.getMeta();
         final Map<String, String> entries = makeEntries(meta, artifact);
 
@@ -58,9 +62,8 @@
 
     @Override
     protected String getLabelFor(final CallContext cc, final String name, final String value, final String type) {
-        // könnte nicht davon ausgegangen werden, dass die entries immer zuerst in createItems erzeugt werden und da quasi
-        // "lazy" initialisiert werden?
-        final Map<String, String> entries = makeEntries(cc.getMeta(), null);
+        // artifacts must be set in "createItems" -> createItems has to be called first
+        final Map<String, String> entries = makeEntries(cc.getMeta(), this.artifact);
 
         final String valueToSet = entries.get(value) != null ? entries.get(value) : value;
         return super.getLabelFor(cc, name, valueToSet, type);
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/CalculationSelectUinfo.java	Tue Jun 26 20:19:31 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/CalculationSelectUinfo.java	Wed Jun 27 14:07:02 2018 +0200
@@ -53,10 +53,11 @@
     @Override
     public boolean validate(final Artifact artifact) throws IllegalArgumentException {
         log.debug("CalculationSelect.validate");
+        /* throws an exception if calculation mode is invalid */
 
         final UINFOArtifact uinfo = (UINFOArtifact) artifact;
-        final String calcDebug = uinfo.getCalculationMode().toString();
-        if (calcDebug.equals("uinfo_inundation_duration")) {
+        final String calcmode = uinfo.getCalculationMode().toString(); // "toString()" is important
+        if (calcmode.equals("uinfo_inundation_duration")) {
 
             final String river = uinfo.getRiver();
             if (!UedauernPropertiesHelper.fileExistsForRiver(river)) {
@@ -64,8 +65,6 @@
             }
         }
 
-        /* throws an exception if calculation mode is invalid */
-
         return true;
     }
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationAccess.java	Tue Jun 26 20:19:31 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationAccess.java	Wed Jun 27 14:07:02 2018 +0200
@@ -66,7 +66,6 @@
         return null;
     }
 
-    // TODO: eigentlich nur die WMS-Url des gewählten dingens (jahr, oder epoche)
     public String getWMSUrl() {
 
         final UedauernPropertiesHelper helper = UedauernPropertiesHelper.getInstance(getRiverName());
@@ -78,8 +77,27 @@
 
     }
 
+    public String getWMSScenarioUrl() {
+        if (super.getBoolean("use_scenario")) {
+            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...
+            }
+        }
+        return "";
+    }
+
+    private Integer getDwspl() {
+        if (super.getBoolean("use_scenario")) {
+            return super.getInteger("sedimentheight");
+        }
+        return null;
+    }
+
     public String getVegZones() {
-        // MIT VegetationzonesAccess zusammenlegen (eine Zeile sparen...)
+        // mit VegetationzonesAccess zusammenlegen (eine Zeile sparen...)
         return super.getString("vegzones");
     }
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/LoadSingleYearSelectState.java	Tue Jun 26 20:19:31 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/LoadSingleYearSelectState.java	Wed Jun 27 14:07:02 2018 +0200
@@ -9,17 +9,11 @@
 package org.dive4elements.river.artifacts.uinfo.inundationduration;
 
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
-import org.apache.log4j.Logger;
-import org.dive4elements.artifactdatabase.data.StateData;
-import org.dive4elements.artifactdatabase.state.Facet;
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.CallContext;
-import org.dive4elements.artifacts.CallMeta;
 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
-import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.artifacts.states.AddTableDataHelper;
 import org.dive4elements.river.artifacts.states.DefaultState;
 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact;
@@ -28,10 +22,6 @@
 /** State in which to fetch years for sedminent load calculation. */
 public class LoadSingleYearSelectState extends DefaultState {
     private static final long serialVersionUID = 1L;
-    /** The log used in this class. */
-    private static Logger log = Logger.getLogger(LoadSingleYearSelectState.class);
-
-    private InundationDurationAccess access;
 
     /**
      * The default constructor that initializes an empty State object.
@@ -50,14 +40,13 @@
         final String dataKey = "singleyear";
         try {
             if (dataKey.equals(name)) {
-
+                final InundationDurationAccess access = new InundationDurationAccess((UINFOArtifact) artifact);
                 final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); // pinKeycolum; nicht zu verweschseln mit
-                                                                                                                      // datakey..artifact.
+                // datakey..artifact.
 
                 helper.addColumn(0, "pinfrom", "60", "common.client.ui.selection", "ICON", "CENTER", "from");
                 helper.addColumn(1, "year", "60", "year", "INTEGER", "LEFT", null);
-                final Map<String, StateData> data = super.getData();
-                final UedauernPropertiesHelper properties = UedauernPropertiesHelper.getInstance(this.access.getRiverName());
+                final UedauernPropertiesHelper properties = UedauernPropertiesHelper.getInstance(access.getRiverName());
 
                 for (final String year : properties.getEinzeljahre()) {
                     final Map<String, String> row = new HashMap<>();
@@ -73,12 +62,4 @@
         }
     }
 
-    @Override
-    public Object computeInit(final D4EArtifact artifact, final String hash, final Object context, final CallMeta meta, final List<Facet> facets) {
-        if (artifact instanceof UINFOArtifact) {
-            this.access = new InundationDurationAccess((UINFOArtifact) artifact);
-        }
-        return super.computeInit(artifact, hash, context, meta, facets);
-    }
-
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/UedauernPropertiesHelper.java	Tue Jun 26 20:19:31 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/UedauernPropertiesHelper.java	Wed Jun 27 14:07:02 2018 +0200
@@ -60,7 +60,6 @@
         final Integer[] totalEpoch = getMittelStartEnd();
         final Object[] args = new Object[] { String.valueOf(totalEpoch[0]), String.valueOf(totalEpoch[1]) };
 
-        // final ResourceBundle rb = ResourceBundle.getBundle("Name");
         entries.put("state.uinfo.totalepoch", Resources.getMsg(meta, "state.uinfo.totalepoch", args)); //
         // String.valueOf: avoid formatting
         // (3.333,00
@@ -119,4 +118,24 @@
         }
         return true;
     }
+
+    public String getScenarioUrlFromYear(final Integer year, final Integer dMwspl) {
+        // besser kein lazy-loading, da der user nochmal zurück gehen und das Jahr ändern könnte...
+        final String templateUrl = getProperties().get("scenario_url").toString();
+        final Map<String, String> tokens = new HashMap<>();
+        tokens.put("jahr", String.valueOf(year));
+        tokens.put("scenario", String.valueOf(dMwspl));
+        final StrSubstitutor subst = new StrSubstitutor(tokens);
+        final String yearUrl = subst.replace(templateUrl);
+        return yearUrl;
+    }
+
+    public String getMittelScenarioUrl(final Integer dMwspl) {
+        final Map<String, String> tokens = new HashMap<>();
+        tokens.put("scenario", String.valueOf(dMwspl));
+        final String templateUrl = getProperties().get("mittel_scenario_url").toString();
+        final StrSubstitutor subst = new StrSubstitutor(tokens);
+        final String url = subst.replace(templateUrl);
+        return url;
+    }
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/YearChoice.java	Tue Jun 26 20:19:31 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/YearChoice.java	Wed Jun 27 14:07:02 2018 +0200
@@ -20,21 +20,19 @@
  */
 public class YearChoice extends RadioSelect {
     private static final long serialVersionUID = 1L;
-    private InundationDurationAccess access = null;
 
     @Override
     protected LinkedHashMap<String, String> makeEntries(final CallMeta meta, final Artifact artifact) {
         // in helper-klasse; dann hier label lazy loaden
         final LinkedHashMap<String, String> entries = new LinkedHashMap<>();
-        if (artifact != null && artifact instanceof UINFOArtifact) {
-            this.access = new InundationDurationAccess((UINFOArtifact) artifact);
-        }
-        if (this.access != null) {
-            final UedauernPropertiesHelper helper = UedauernPropertiesHelper.getInstance(this.access.getRiverName());
-            final LinkedHashMap<String, String> extras = helper.getExtraLayers(meta);
-            entries.put("state.uinfo.year", null);
-            entries.putAll(extras);
-        }
+
+        final InundationDurationAccess access = new InundationDurationAccess((UINFOArtifact) artifact);
+
+        final UedauernPropertiesHelper helper = UedauernPropertiesHelper.getInstance(access.getRiverName());
+        final LinkedHashMap<String, String> extras = helper.getExtraLayers(meta);
+        entries.put("state.uinfo.year", null);
+        entries.putAll(extras);
+
         return entries;
     }
 
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties	Tue Jun 26 20:19:31 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties	Wed Jun 27 14:07:02 2018 +0200
@@ -324,7 +324,7 @@
 ele_window_save_error = Error while saving elevations.
 ele_window_geometry_error = The geometry is not supported:
 
-error_river_inundationdur_file_not_found = F\u00fcr das gew\u00e4hlte Gew\u00e4sser liegen keine Daten vor oder die "uinfo_uedauern_aue_Gew\u00e4sser.properties"-Datei wurde nicht gefunden.
+error_river_inundationdur_file_not_found = F\u00fcr das gew\u00e4hlte Gew\u00e4sser liegen keine Daten vor.
 unexpected_exception = There occured an unexpected exception
 error_years_wrong = The second year needs to be bigger than the first year.
 error_read_minmax_values = Error while reading min/max values for the location input.
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties	Tue Jun 26 20:19:31 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties	Wed Jun 27 14:07:02 2018 +0200
@@ -324,7 +324,7 @@
 ele_window_save_error = Fehler beim Speichern der H\u00f6hen.
 ele_window_geometry_error = Die Geometrie wird nicht unterst\u00fctzt:
 
-error_river_inundationdur_file_not_found = F\u00fcr das gew\u00e4hlte Gew\u00e4sser liegen keine Daten vor oder die "uinfo_uedauern_aue_Gew\u00e4sser.properties"-Datei wurde nicht gefunden.
+error_river_inundationdur_file_not_found = F\u00fcr das gew\u00e4hlte Gew\u00e4sser liegen keine Daten vor.
 unexpected_exception = Ein unerwarteter Fehler ist aufgetreten
 error_years_wrong = Das zweite Jahr muss gr\u00f6\u00dfer als das erste sein.
 error_read_minmax_values = Fehler beim Lesen der min/max Werte. Es kann keine Validierung der eingegebenen Strecke durchgef\u00fchrt werden.

http://dive4elements.wald.intevation.org