changeset 8304:c4bd57172aa7

Added injector for PNP.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 22 Sep 2014 17:10:23 +0200
parents 519023ce3500
children f5ed7698c4db
files artifacts/src/main/java/org/dive4elements/river/exports/injector/InjectorConstants.java artifacts/src/main/java/org/dive4elements/river/exports/injector/PNPInjector.java
diffstat 2 files changed, 51 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/injector/InjectorConstants.java	Mon Sep 22 17:08:48 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/InjectorConstants.java	Mon Sep 22 17:10:23 2014 +0200
@@ -4,5 +4,6 @@
 public interface InjectorConstants
 {
     public static final String CURRENT_KM = "currentkm";
+    public static final String PNP = "PNP";
     public static final double GAUGE_EPSILON = 0.1;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/PNPInjector.java	Mon Sep 22 17:10:23 2014 +0200
@@ -0,0 +1,50 @@
+package org.dive4elements.river.exports.injector;
+
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.artifacts.ContextInjector;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RiverAccess;
+import org.dive4elements.river.model.Gauge;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM;
+import static org.dive4elements.river.exports.injector.InjectorConstants.PNP;
+import static org.dive4elements.river.exports.injector.InjectorConstants.GAUGE_EPSILON;
+
+public class PNPInjector
+implements ContextInjector
+{
+
+    @Override
+    public void setup(Element cfg) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void injectContext(
+        CallContext ctx,
+        Artifact artifact,
+        Document request
+    ) {
+        Object currentKm = ctx.getContextValue(CURRENT_KM);
+        if (currentKm == null) {
+            return;
+        }
+
+        RiverAccess access = new RiverAccess((D4EArtifact)artifact);
+        Double km = (Double)currentKm;
+        Gauge gauge =
+            access.getRiver().determineGaugeByStation(
+                km - GAUGE_EPSILON,
+                km + GAUGE_EPSILON);
+
+        if (gauge == null) {
+            return;
+        }
+        ctx.putContextValue(PNP, gauge.getDatum());
+    }
+
+}

http://dive4elements.wald.intevation.org