comparison 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
comparison
equal deleted inserted replaced
8321:a5e7e2d833ea 8326:10917ec29625
1 package org.dive4elements.river.exports.injector; 1 package org.dive4elements.river.exports.injector;
2 2
3 import org.apache.log4j.Logger;
3 import org.dive4elements.artifacts.Artifact; 4 import org.dive4elements.artifacts.Artifact;
4 import org.dive4elements.artifacts.CallContext; 5 import org.dive4elements.artifacts.CallContext;
5 import org.dive4elements.artifacts.ContextInjector; 6 import org.dive4elements.artifacts.ContextInjector;
6 import org.dive4elements.river.artifacts.D4EArtifact; 7 import org.dive4elements.river.artifacts.D4EArtifact;
7 import org.dive4elements.river.artifacts.access.RiverAccess; 8 import org.dive4elements.river.artifacts.access.RiverAccess;
15 16
16 public class PNPInjector 17 public class PNPInjector
17 implements ContextInjector 18 implements ContextInjector
18 { 19 {
19 20
21 private Logger log = Logger.getLogger(PNPInjector.class);
20 @Override 22 @Override
21 public void setup(Element cfg) { 23 public void setup(Element cfg) {
22 // TODO Auto-generated method stub 24 // TODO Auto-generated method stub
23 25
24 } 26 }
29 Artifact artifact, 31 Artifact artifact,
30 Document request 32 Document request
31 ) { 33 ) {
32 Object currentKm = ctx.getContextValue(CURRENT_KM); 34 Object currentKm = ctx.getContextValue(CURRENT_KM);
33 if (currentKm == null) { 35 if (currentKm == null) {
36 log.debug("no current km. not injecting pnp");
34 return; 37 return;
35 } 38 }
36 39
37 RiverAccess access = new RiverAccess((D4EArtifact)artifact); 40 RiverAccess access = new RiverAccess((D4EArtifact)artifact);
38 Double km = (Double)currentKm; 41 Double km = Double.valueOf(currentKm.toString());
42 if (Double.isNaN(km) || Double.isInfinite(km)) {
43 log.debug("current km is NAN or infinte. not injecting pnp.");
44 return;
45 }
39 Gauge gauge = 46 Gauge gauge =
40 access.getRiver().determineGaugeByStation( 47 access.getRiver().determineGaugeByStation(
41 km - GAUGE_EPSILON, 48 km - GAUGE_EPSILON,
42 km + GAUGE_EPSILON); 49 km + GAUGE_EPSILON);
43 50
44 if (gauge == null) { 51 if (gauge == null) {
52 log.debug("no gauge found at current km. not injecting pnp");
45 return; 53 return;
46 } 54 }
55 log.debug("injecting pnp: " + gauge.getDatum());
47 ctx.putContextValue(PNP, gauge.getDatum()); 56 ctx.putContextValue(PNP, gauge.getDatum());
48 } 57 }
49 58
50 } 59 }

http://dive4elements.wald.intevation.org