view artifacts/src/main/java/org/dive4elements/river/exports/injector/ComputedDischargeInjector.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 e3a8aa6eee32
children
line wrap: on
line source
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;
import org.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.river.artifacts.access.RangeAccess;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM;

public class ComputedDischargeInjector
implements ContextInjector
{

    private static Logger log = Logger.getLogger(ComputedDischargeInjector.class);

    @Override
    public void setup(Element cfg) {
    }

    @Override
    public void injectContext(
        CallContext ctx,
        Artifact artifact,
        Document doc
    ) {
        RangeAccess access = new RangeAccess((D4EArtifact)artifact);
        if (access.hasFrom()) {
            ctx.putContextValue(CURRENT_KM, access.getFrom());
        }
        else if (access.getLocations() != null &&
            access.getLocations().length > 0) {
            ctx.putContextValue(CURRENT_KM, access.getLocations()[0]);
        }
    }
}

http://dive4elements.wald.intevation.org