changeset 317:8f40a57229c3

FLYSArtifact provides methods to retrieve the real River, Gauge objects. flys-artifacts/trunk@1704 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 15 Apr 2011 13:37:51 +0000
parents 4aa078e28cfd
children 8a4360ccbe1c
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java
diffstat 2 files changed, 65 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Apr 15 10:10:37 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Apr 15 13:37:51 2011 +0000
@@ -1,3 +1,9 @@
+2011-04-15  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Now
+	  provides some methods that return some basic objects inserted while
+	  parameterization: River, Gauge and so on.
+
 2011-04-15  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Fri Apr 15 10:10:37 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Fri Apr 15 13:37:51 2011 +0000
@@ -28,7 +28,11 @@
 import de.intevation.artifactdatabase.state.StateEngine;
 import de.intevation.artifactdatabase.transition.TransitionEngine;
 
+import de.intevation.flys.model.Gauge;
+import de.intevation.flys.model.River;
+
 import de.intevation.flys.artifacts.context.FLYSContext;
+import de.intevation.flys.artifacts.model.RiverFactory;
 
 
 /**
@@ -433,5 +437,60 @@
 
         return false;
     }
+
+
+    /**
+     * Returns the selected River object based on the 'river' data that might
+     * have been inserted by the user.
+     *
+     * @return the selected River or null if no river has been chosen yet.
+     */
+    public River getRiver() {
+        StateData dRiver = getData("river");
+
+        return dRiver != null
+            ? RiverFactory.getRiver((String) dRiver.getValue())
+            : null;
+    }
+
+
+    /**
+     * Returns the selected distance of points.
+     *
+     * @return the selected distance or points.
+     */
+    public double[] getDistance() {
+        StateData dFrom = getData("ld_from");
+        StateData dTo   = getData("ld_to");
+
+        double from = Double.parseDouble((String) dFrom.getValue());
+        double to   = Double.parseDouble((String) dTo.getValue());
+
+        // TODO take point selection into account
+
+        return new double[] { from, to };
+    }
+
+
+    /**
+     * Returns the gauge based on the current distance and river.
+     *
+     * @return the gauge.
+     */
+    public Gauge getGauge() {
+        River    river = getRiver();
+        double[] dist  = getDistance();
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Determine gauge for:");
+            logger.debug("... river: " + river.getName());
+            logger.debug("... distance: " + dist[0] + " - " + dist[1]);
+        }
+
+        List<Gauge> gauges = river.getGauges();
+
+        // TODO Search the desired gauge!
+        return gauges.get(0);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org