[PATCH 3 of 4] Added injector for PNP

Wald Commits scm-commit at wald.intevation.org
Mon Sep 22 17:11:27 CEST 2014


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1411398623 -7200
# Node ID c4bd57172aa7e7c9f60928c1714a524b6b0dbfd8
# Parent  519023ce3500353205e31de75f7c411c1d1c43ab
Added injector for PNP.

diff -r 519023ce3500 -r c4bd57172aa7 artifacts/src/main/java/org/dive4elements/river/exports/injector/InjectorConstants.java
--- 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;
 }
diff -r 519023ce3500 -r c4bd57172aa7 artifacts/src/main/java/org/dive4elements/river/exports/injector/PNPInjector.java
--- /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());
+    }
+
+}


More information about the Dive4Elements-commits mailing list