Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeCurveArtifact.java @ 4420:45d310b41c23
Add javadoc comment about RiverInfoServiceImpl
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Tue, 06 Nov 2012 13:30:04 +0100 |
parents | 8c51c43e59ca |
children | 319565a48182 |
line wrap: on
line source
package de.intevation.flys.artifacts; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import org.w3c.dom.Document; import de.intevation.artifactdatabase.state.DefaultOutput; import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifactdatabase.data.DefaultStateData; import de.intevation.artifacts.ArtifactFactory; import de.intevation.artifacts.CallMeta; import de.intevation.artifacts.common.ArtifactNamespaceContext; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.flys.artifacts.model.GaugeDischargeCurveFacet; import de.intevation.flys.artifacts.resources.Resources; import de.intevation.flys.artifacts.states.StaticState; import de.intevation.flys.model.Gauge; import de.intevation.flys.utils.FLYSUtils; /** * Artifact to calculate a discharge curve from a gauge overview info * * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> */ public class GaugeDischargeCurveArtifact extends AbstractStaticStateArtifact { private static final Logger logger = Logger.getLogger(GaugeDischargeCurveArtifact.class); public static final String XPATH_RIVER = "/art:action/art:river/@art:name"; public static final String XPATH_GAUGE = "/art:action/art:gauge/@art:reference"; public static final String NAME = "gaugedischargecurve"; public static final String STATIC_STATE_NAME = "state.gaugedischargecurve.static"; public static final String UIPROVIDER = "gauge_discharge_curve"; public static final String GAUGE_DISCHARGE_CURVE_FACET = "gauge_discharge_curve"; public static final String GAUGE_DISCHARGE_CURVE_AT_EXPORT_FACET = "at"; public static final String GAUGE_DISCHARGE_CURVE_OUT = "discharge_curve"; public static final String GAUGE_DISCHARGE_CURVE_AT_EXPORT_OUT = "computed_dischargecurve_at_export"; private Facet atexportfacet; private Facet curvefacet; /** * Setup initializes the data by extracting the river and gauge from * the XML Document. */ @Override public void setup( String identifier, ArtifactFactory factory, Object context, CallMeta callmeta, Document data) { logger.debug("GaugeDischargeCurveArtifact.setup"); if (logger.isDebugEnabled()) { logger.debug("GaugeDischargeCurveArtifact.setup" + XMLUtils.toString(data)); } String gaugeref = XMLUtils.xpathString(data, XPATH_GAUGE, ArtifactNamespaceContext.INSTANCE); String rivername = XMLUtils.xpathString(data, XPATH_RIVER, ArtifactNamespaceContext.INSTANCE); addData("river", new DefaultStateData("river", Resources.getMsg(callmeta, "facet.gauge_discharge_curve.river", "Name of the river"), "String", rivername)); addData("reference_gauge", new DefaultStateData("reference_gauge", Resources.getMsg(callmeta, "facet.gauge_discharge_curve.reference_gauge", "Gauge official number"), "Long", gaugeref)); Gauge gauge = FLYSUtils.getReferenceGauge(this); String gaugename = ""; Double gaugelocation = null; if (gauge != null) { gaugename = gauge.getName(); BigDecimal station = gauge.getStation(); if (station != null) { gaugelocation = station.doubleValue(); } } addData("gauge_name", new DefaultStateData("gauge_name", Resources.getMsg(callmeta, "facet.gauge_discharge_curve.gauge_name", "Name of the gauge"), "String", gaugename)); if (gaugelocation != null) { addData("ld_locations", new DefaultStateData("ld_locations", Resources.getMsg(callmeta, "facet.gauge_discharge_curve.gauge_location", "Location of the gauge"), "Double", gaugelocation.toString())); } String description = Resources.format(callmeta, "facet.gauge_discharge_curve.description", "Discharge curve on gauge", rivername, gaugename); List<Facet> fs = new ArrayList<Facet>(2); curvefacet = new GaugeDischargeCurveFacet( GAUGE_DISCHARGE_CURVE_FACET, description); fs.add(curvefacet); description = Resources.format(callmeta, "facet.gauge_discharge_curve_at_export.description", "Discharge curve AT export on gauge", rivername, gaugename); atexportfacet = new GaugeDischargeCurveFacet( GAUGE_DISCHARGE_CURVE_AT_EXPORT_FACET, description); fs.add(atexportfacet); addFacets(STATIC_STATE_NAME, fs); super.setup(identifier, factory, context, callmeta, data); } @Override public String getName() { return NAME; } @Override protected void initStaticState() { StaticState state = new StaticState(STATIC_STATE_NAME); List<Facet> fs = new ArrayList<Facet>(1); fs.add(curvefacet); DefaultOutput output = new DefaultOutput( GAUGE_DISCHARGE_CURVE_OUT, "output.discharge_curve", "image/png", fs, "chart"); state.addOutput(output); fs = new ArrayList<Facet>(1); fs.add(atexportfacet); output = new DefaultOutput( GAUGE_DISCHARGE_CURVE_AT_EXPORT_OUT, "output.computed_dischargecurve_at_export", "text/plain", fs, "export"); state.addOutput(output); state.setUIProvider(UIPROVIDER); setStaticState(state); } }