diff artifacts/src/main/java/org/dive4elements/river/exports/injector/PNPInjector.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 c4bd57172aa7
children f5461750e5c7
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/injector/PNPInjector.java	Wed Sep 24 18:33:11 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/PNPInjector.java	Thu Sep 25 17:23:12 2014 +0200
@@ -1,5 +1,6 @@
 package org.dive4elements.river.exports.injector;
 
+import org.apache.log4j.Logger;
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.ContextInjector;
@@ -17,6 +18,7 @@
 implements ContextInjector
 {
 
+    private Logger log = Logger.getLogger(PNPInjector.class);
     @Override
     public void setup(Element cfg) {
         // TODO Auto-generated method stub
@@ -31,19 +33,26 @@
     ) {
         Object currentKm = ctx.getContextValue(CURRENT_KM);
         if (currentKm == null) {
+            log.debug("no current km. not injecting pnp");
             return;
         }
 
         RiverAccess access = new RiverAccess((D4EArtifact)artifact);
-        Double km = (Double)currentKm;
+        Double km = Double.valueOf(currentKm.toString());
+        if (Double.isNaN(km) || Double.isInfinite(km)) {
+            log.debug("current km is NAN or infinte. not injecting pnp.");
+            return;
+        }
         Gauge gauge =
             access.getRiver().determineGaugeByStation(
                 km - GAUGE_EPSILON,
                 km + GAUGE_EPSILON);
 
         if (gauge == null) {
+            log.debug("no gauge found at current km. not injecting pnp");
             return;
         }
+        log.debug("injecting pnp: " + gauge.getDatum());
         ctx.putContextValue(PNP, gauge.getDatum());
     }
 

http://dive4elements.wald.intevation.org