[PATCH 2 of 2] Changed hard coded standard vegetation zone table to fetching it from the database, i18n for the standard zone names

Wald Commits scm-commit at wald.intevation.org
Tue Aug 14 14:04:25 CEST 2018


# HG changeset patch
# User mschaefer
# Date 1534248241 -7200
# Node ID e511eb935ccd45c6fc91393893cc4e5343226726
# Parent  361de818f76e354136bb7afaf990a4e4b741d81f
Changed hard coded standard vegetation zone table to fetching it from the database, i18n for the standard zone names

diff -r 361de818f76e -r e511eb935ccd artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DataFromArtifactXPathFunction.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DataFromArtifactXPathFunction.java	Tue Aug 14 14:02:26 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DataFromArtifactXPathFunction.java	Tue Aug 14 14:04:01 2018 +0200
@@ -21,8 +21,7 @@
 import org.dive4elements.river.utils.RiverUtils;
 
 /**
- * Very specialized function the resolves the 'year' (als middle of all used events) from a fix-analysis-vollmer
- * artifact).
+ * Very specialized function that gets state data from an artifact
  *
  * @author Gernot Belger
  */
diff -r 361de818f76e -r e511eb935ccd artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DefaultVegetationZoneXPathFunction.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DefaultVegetationZoneXPathFunction.java	Tue Aug 14 14:02:26 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DefaultVegetationZoneXPathFunction.java	Tue Aug 14 14:04:01 2018 +0200
@@ -10,15 +10,19 @@
 package org.dive4elements.river.artifacts.datacage.templating;
 
 import java.util.List;
+import java.util.UUID;
 
 import javax.xml.xpath.XPathFunction;
 import javax.xml.xpath.XPathFunctionException;
 
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RiverAccess;
 import org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZone;
+import org.dive4elements.river.utils.RiverUtils;
 
 /**
- * Very specialized function the resolves the 'year' (als middle of all used events) from a fix-analysis-vollmer
- * artifact).
+ * Very specialized function that fetches the default vegetation zones for the river specified by an artifact
  *
  * @author Gernot Belger
  */
@@ -26,10 +30,25 @@
 
     public static final String ID = "defaultvegetationzone";
 
-    public static final int ARITY = 0;
+    public static final int ARITY = 1;
+
+    private final CallContext context;
+
+    public DefaultVegetationZoneXPathFunction(final CallContext context) {
+        this.context = context;
+    }
 
     @Override
     public Object evaluate(final List args) throws XPathFunctionException {
-        return VegetationZone.parseListToDataString(VegetationZone.getStandardList());
+
+        final UUID uuid = (UUID) args.get(0);
+        if (uuid == null)
+            return null;
+
+        final D4EArtifact artifact = RiverUtils.getArtifact(uuid.toString(), this.context);
+
+        final RiverAccess access = new RiverAccess(artifact);
+
+        return VegetationZone.parseListToDataString(VegetationZone.getStandardList(access.getRiver(), this.context));
     }
 }
\ No newline at end of file
diff -r 361de818f76e -r e511eb935ccd artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java	Tue Aug 14 14:02:26 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java	Tue Aug 14 14:04:01 2018 +0200
@@ -226,7 +226,8 @@
 
         addFunction(FixAnalysisYearXPathFunction.ID, FixAnalysisYearXPathFunction.ARITY, new FixAnalysisYearXPathFunction(buildHelper.getContext()));
 
-        addFunction(DefaultVegetationZoneXPathFunction.ID, DefaultVegetationZoneXPathFunction.ARITY, new DefaultVegetationZoneXPathFunction());
+        addFunction(DefaultVegetationZoneXPathFunction.ID, DefaultVegetationZoneXPathFunction.ARITY,
+                new DefaultVegetationZoneXPathFunction(buildHelper.getContext()));
 
         addFunction(DataFromArtifactXPathFunction.ID, DataFromArtifactXPathFunction.ARITY, new DataFromArtifactXPathFunction(buildHelper.getContext()));
     }
diff -r 361de818f76e -r e511eb935ccd artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZone.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZone.java	Tue Aug 14 14:02:26 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZone.java	Tue Aug 14 14:04:01 2018 +0200
@@ -13,6 +13,10 @@
 import java.util.List;
 import java.util.TreeSet;
 
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.model.River;
+
 /**
  * @author Domenico Nardi Tironi
  *
@@ -87,19 +91,13 @@
         return this.min_day_overflow;
     }
 
-    public static final List<VegetationZone> getStandardList() {
+    public static final List<VegetationZone> getStandardList(final River river, final CallContext context) {
 
         final List<VegetationZone> list = new ArrayList<>();
-        list.add(new VegetationZone("Zonaler Wald", 0, 5, "#336600"));
-        list.add(new VegetationZone("Hartholzaue, trocken", 6, 40, "#00cc00"));
-        list.add(new VegetationZone("Hartholzaue, feucht", 41, 80, "#66ff33"));
-        list.add(new VegetationZone("Silberweidenwald", 81, 140, "#008080"));
-        list.add(new VegetationZone("Weidengebüsch", 141, 200, "#33cccc"));
-        list.add(new VegetationZone("Uferröhricht", 201, 260, "#ffa8ff"));
-        list.add(new VegetationZone("Uferpioniere", 261, 320, "#ff0000"));
-        list.add(new VegetationZone("Vegetationslos", 321, 364, "#b2b2b2"));
-        list.add(new VegetationZone("Wasserfläche", 365, 365, "#0066ff"));
-
+        for (final org.dive4elements.river.model.uinfo.VegetationZone vz : org.dive4elements.river.model.uinfo.VegetationZone.getValues(river)) {
+            final String zn = Resources.getMsg(context.getMeta(), "uinfo_vegetation_type_" + vz.getVegetationType().getId().toString());
+            list.add(new VegetationZone(zn, vz.getMin_overflow_days(), vz.getMax_overflow_days(), vz.getColor()));
+        }
         return list;
     }
 
diff -r 361de818f76e -r e511eb935ccd artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableEditState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableEditState.java	Tue Aug 14 14:02:26 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableEditState.java	Tue Aug 14 14:04:01 2018 +0200
@@ -14,7 +14,9 @@
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
 import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RiverAccess;
 import org.dive4elements.river.artifacts.states.DefaultState;
+import org.dive4elements.river.model.River;
 import org.w3c.dom.Element;
 
 /**
@@ -37,7 +39,8 @@
             final Element label = ProtocolUtils.createArtNode(cr, "label", null, null);
             final Element value = ProtocolUtils.createArtNode(cr, "value", null, null);
             final D4EArtifact flys = (D4EArtifact) artifact;
-            final String s = flys.getDataAsString(datakey) == null ? VegetationZone.parseListToDataString(VegetationZone.getStandardList())
+            final River river = new RiverAccess(flys).getRiver();
+            final String s = flys.getDataAsString(datakey) == null ? VegetationZone.parseListToDataString(VegetationZone.getStandardList(river, context))
                     : flys.getDataAsString(datakey);
 
             value.setTextContent(s);
diff -r 361de818f76e -r e511eb935ccd artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableState.java	Tue Aug 14 14:02:26 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableState.java	Tue Aug 14 14:04:01 2018 +0200
@@ -14,7 +14,9 @@
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
 import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RiverAccess;
 import org.dive4elements.river.artifacts.states.DefaultState;
+import org.dive4elements.river.model.River;
 import org.w3c.dom.Element;
 
 /**
@@ -38,7 +40,8 @@
             final Element label = ProtocolUtils.createArtNode(cr, "label", null, null);
             final Element value = ProtocolUtils.createArtNode(cr, "value", null, null);
             final D4EArtifact flys = (D4EArtifact) artifact;
-            final String s = flys.getDataAsString(datakey) == null ? VegetationZone.parseListToDataString(VegetationZone.getStandardList())
+            final River river = new RiverAccess(flys).getRiver();
+            final String s = flys.getDataAsString(datakey) == null ? VegetationZone.parseListToDataString(VegetationZone.getStandardList(river, context))
                     : flys.getDataAsString(datakey);
 
             value.setTextContent(s);
diff -r 361de818f76e -r e511eb935ccd artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties	Tue Aug 14 14:02:26 2018 +0200
+++ b/artifacts/src/main/resources/messages.properties	Tue Aug 14 14:04:01 2018 +0200
@@ -1125,6 +1125,15 @@
 uinfo_salix_line = Iota (Fluss/Aue-Konnektivit\u00e4t)
 uinfo_inundation_duration = \u00dcberflutungsdauern Aue
 uinfo_vegetation_zones = Vegetationszonen
+uinfo_vegetation_type_1 = zonal forest
+uinfo_vegetation_type_2 = dry hartwood forest floodplain
+uinfo_vegetation_type_3 = wet hartwood forest floodplain
+uinfo_vegetation_type_4 = salix alba forest
+uinfo_vegetation_type_5 = salix shrubs
+uinfo_vegetation_type_6 = reed bed
+uinfo_vegetation_type_7 = bank pioneers
+uinfo_vegetation_type_8 = no vegetation
+uinfo_vegetation_type_9 = water
 
 state.uinfo.river = Gew\u00e4sser
 state.uinfo.calculation_mode=Berechnungsart
diff -r 361de818f76e -r e511eb935ccd artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties	Tue Aug 14 14:02:26 2018 +0200
+++ b/artifacts/src/main/resources/messages_de.properties	Tue Aug 14 14:04:01 2018 +0200
@@ -1125,6 +1125,15 @@
 uinfo_salix_line = Iota (Fluss/Aue-Konnektivit\u00e4t)
 uinfo_inundation_duration = \u00dcberflutungsdauern Aue
 uinfo_vegetation_zones = Vegetationszonen
+uinfo_vegetation_type_1 = Zonaler Wald
+uinfo_vegetation_type_2 = Hartholzaue, trocken
+uinfo_vegetation_type_3 = Hartholzaue, feucht
+uinfo_vegetation_type_4 = Silberweidenwald
+uinfo_vegetation_type_5 = Weidengeb\u00fcsch
+uinfo_vegetation_type_6 = Uferr\u00f6hricht
+uinfo_vegetation_type_7 = Uferpioniere
+uinfo_vegetation_type_8 = Vegetationslos
+uinfo_vegetation_type_9 = Wasserfl\u00e4che
 
 state.uinfo.river = Gew\u00e4sser
 state.uinfo.calculation_mode=Berechnungsart


More information about the Dive4Elements-commits mailing list