changeset 324:cd9e397cc2a8

The inserted river is validated in the feed operation(). flys-artifacts/trunk@1718 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 18 Apr 2011 13:21:52 +0000
parents b33ba2cd4a3e
children 7a0907742cc0
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java
diffstat 2 files changed, 44 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Apr 18 13:00:57 2011 +0000
+++ b/flys-artifacts/ChangeLog	Mon Apr 18 13:21:52 2011 +0000
@@ -1,3 +1,9 @@
+2011-04-18  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java:
+	  The inserted river is validated now (overrides validate() of
+	  DefaultState).
+
 2011-04-18  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java	Mon Apr 18 13:00:57 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java	Mon Apr 18 13:21:52 2011 +0000
@@ -1,6 +1,7 @@
 package de.intevation.flys.artifacts.states;
 
 import java.util.List;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
 
@@ -17,8 +18,8 @@
 
 import de.intevation.flys.model.River;
 
+import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.model.RiverFactory;
-
 import de.intevation.flys.artifacts.resources.Resources;
 
 
@@ -30,6 +31,18 @@
     /** The logger used in this class. */
     private static Logger logger = Logger.getLogger(RiverSelect.class);
 
+
+    /** Error message that is thrown if no river was found based on a given
+     * name.*/
+    public static final String ERROR_NO_SUCH_RIVER =
+        "error_feed_no_such_river";
+
+    /** Error message that is thrown if no river was found based on a given
+     * name.*/
+    public static final String ERROR_NO_RIVER_SELECTED =
+        "error_feed_no_river_selected";
+
+
     /**
      * The default constructor that initializes an empty State object.
      */
@@ -116,5 +129,29 @@
 
         return item;
     }
+
+
+    @Override
+    public boolean validate(Artifact artifact, CallContext context)
+    throws IllegalArgumentException
+    {
+        logger.debug("RiverSelect.validate");
+
+        Map<String, StateData> data = getData();
+
+        StateData dRiver = data.get("river");
+
+        if (dRiver == null || dRiver.getValue() == null) {
+            throw new IllegalArgumentException(ERROR_NO_RIVER_SELECTED);
+        }
+
+        River river = RiverFactory.getRiver((String) dRiver.getValue());
+
+        if (river == null) {
+            throw new IllegalArgumentException(ERROR_NO_SUCH_RIVER);
+        }
+
+        return true;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org