changeset 8367:16dc2da05aef

Overwriting the current km in context gives unexpected results if artifacts from different km have been loaded.
author Tom Gottfried <tom@intevation.de>
date Thu, 02 Oct 2014 11:46:44 +0200
parents 061e85212d25
children 6e9c01a6e90e
files artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromGaugeNameInjector.java artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromGaugeNumberInjector.java artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromLocationInjector.java artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromRequestInjector.java
diffstat 4 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromGaugeNameInjector.java	Thu Oct 02 11:04:14 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromGaugeNameInjector.java	Thu Oct 02 11:46:44 2014 +0200
@@ -25,6 +25,10 @@
 
     @Override
     public void injectContext(CallContext ctx, Artifact artifact, Document doc) {
+        if (ctx.getContextValue(CURRENT_KM) instanceof Number) {
+            return;
+        }
+
         D4EArtifact d4e = (D4EArtifact)artifact;
         RangeAccess access = new RangeAccess(d4e);
         String name = d4e.getDataAsString("gauge_name");
--- a/artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromGaugeNumberInjector.java	Thu Oct 02 11:04:14 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromGaugeNumberInjector.java	Thu Oct 02 11:46:44 2014 +0200
@@ -29,6 +29,10 @@
         Artifact artifact,
         Document request
     ) {
+        if (ctx.getContextValue(CURRENT_KM) instanceof Number) {
+            return;
+        }
+
         HistoricalDischargeAccess access =
             new HistoricalDischargeAccess((D4EArtifact)artifact);
         Long gaugeNumber = access.getOfficialGaugeNumber();
--- a/artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromLocationInjector.java	Thu Oct 02 11:04:14 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromLocationInjector.java	Thu Oct 02 11:46:44 2014 +0200
@@ -27,6 +27,10 @@
         Artifact artifact,
         Document doc
     ) {
+        if (ctx.getContextValue(CURRENT_KM) instanceof Number) {
+            return;
+        }
+
         RangeAccess access = new RangeAccess((D4EArtifact)artifact);
         if (access.getLocations() != null &&
             access.getLocations().length > 0) {
--- a/artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromRequestInjector.java	Thu Oct 02 11:04:14 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromRequestInjector.java	Thu Oct 02 11:46:44 2014 +0200
@@ -19,7 +19,6 @@
 {
     private static final Logger log = Logger.getLogger(KmFromRequestInjector.class);
 
-    public static final Double INVALID_KM = Double.valueOf(-1d);
     public static final String XPATH_CHART_CURRENTKM =
         "/art:action/art:attributes/art:currentKm/@art:km";
     @Override
@@ -31,7 +30,12 @@
     public void injectContext(
         CallContext ctx,
         Artifact artifact,
-        Document request) {
+        Document request
+    ) {
+        if (ctx.getContextValue(CURRENT_KM) instanceof Number) {
+            return;
+        }
+
         Double km = getCurrentKmFromRequest(request);
         if (Double.isNaN(km)) {
             RangeAccess access = new RangeAccess((D4EArtifact)artifact);

http://dive4elements.wald.intevation.org