diff artifacts/src/main/java/org/dive4elements/river/exports/injector/DischargeInjector.java @ 8326:10917ec29625

Inject current km and pnp into the context used to calculate W in cm at gauge.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 25 Sep 2014 17:23:12 +0200
parents b5bef15c982e
children 31272d799dad
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/injector/DischargeInjector.java	Wed Sep 24 18:33:11 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/DischargeInjector.java	Thu Sep 25 17:23:12 2014 +0200
@@ -27,17 +27,22 @@
     @Override
     public void injectContext(CallContext ctx, Artifact artifact, Document doc) {
         RangeAccess access = new RangeAccess((D4EArtifact)artifact);
-        if (!access.hasFrom()) {
+        if (access.hasFrom()) {
+            ctx.putContextValue(CURRENT_KM, access.getFrom());
             return;
         }
-        double km = access.getFrom();
-        Gauge gauge = access.getRiver().determineGaugeByStation(
-            km - GAUGE_EPSILON, km + GAUGE_EPSILON);
-        if (gauge == null) {
-            log.error("No Gauge could be found at station " + km + "!");
+        D4EArtifact d4e = (D4EArtifact)artifact;
+        String name = d4e.getDataAsString("gauge_name");
+        if (name == null || name.equals("")) {
             return;
         }
-        ctx.putContextValue(CURRENT_KM, km);
+        Gauge gauge = access.getRiver().determineGaugeByName(name);
+        if (gauge == null) {
+            log.error("No Gauge could be found for name " + name + "!");
+            return;
+        }
+        ctx.putContextValue(CURRENT_KM, gauge.getStation());
+        return;
     }
 
 }

http://dive4elements.wald.intevation.org