bjoern@3936: package de.intevation.flys.artifacts; bjoern@3936: bjoern@4190: import java.math.BigDecimal; bjoern@3936: import java.util.ArrayList; bjoern@3936: import java.util.List; bjoern@3936: bjoern@3936: import org.apache.log4j.Logger; bjoern@3936: bjoern@3936: import org.w3c.dom.Document; bjoern@3936: bjoern@3936: import de.intevation.artifactdatabase.state.DefaultOutput; bjoern@3936: import de.intevation.artifactdatabase.state.Facet; bjoern@4034: import de.intevation.artifactdatabase.data.DefaultStateData; bjoern@3936: bjoern@3936: import de.intevation.artifacts.ArtifactFactory; bjoern@3936: import de.intevation.artifacts.CallMeta; bjoern@3936: bjoern@3936: import de.intevation.artifacts.common.ArtifactNamespaceContext; bjoern@3936: import de.intevation.artifacts.common.utils.XMLUtils; bjoern@3936: bjoern@4032: import de.intevation.flys.artifacts.model.GaugeDischargeCurveFacet; bjoern@4032: import de.intevation.flys.artifacts.resources.Resources; bjoern@3936: import de.intevation.flys.artifacts.states.StaticState; bjoern@4032: bjoern@4032: import de.intevation.flys.model.Gauge; bjoern@4032: import de.intevation.flys.utils.FLYSUtils; bjoern@3936: bjoern@3936: bjoern@3936: /** bjoern@3936: * Artifact to calculate a discharge curve from a gauge overview info bjoern@3936: * bjoern@3936: * @author Björn Ricks bjoern@3936: */ bjoern@3936: public class GaugeDischargeCurveArtifact bjoern@3936: extends AbstractStaticStateArtifact bjoern@3936: { bjoern@3936: bjoern@3936: private static final Logger logger = bjoern@3936: Logger.getLogger(GaugeDischargeCurveArtifact.class); bjoern@3936: bjoern@4027: public static final String XPATH_RIVER = "/art:action/art:river/@art:name"; bjoern@4027: public static final String XPATH_GAUGE = "/art:action/art:gauge/@art:reference"; bjoern@3936: public static final String NAME = "gaugedischargecurve"; bjoern@3936: public static final String STATIC_STATE_NAME = "state.gaugedischargecurve.static"; bjoern@4159: public static final String UIPROVIDER = "gauge_discharge_curve"; bjoern@4188: public static final String GAUGE_DISCHARGE_CURVE_FACET = bjoern@4188: "gauge_discharge_curve"; bjoern@4188: public static final String GAUGE_DISCHARGE_CURVE_AT_EXPORT_FACET = bjoern@4305: "at"; bjoern@4188: public static final String GAUGE_DISCHARGE_CURVE_OUT = bjoern@4188: "discharge_curve"; bjoern@4188: public static final String GAUGE_DISCHARGE_CURVE_AT_EXPORT_OUT = bjoern@4188: "computed_dischargecurve_at_export"; bjoern@4188: bjoern@4188: private Facet atexportfacet; bjoern@4188: private Facet curvefacet; bjoern@3936: bjoern@3936: /** bjoern@3936: * Setup initializes the data by extracting the river and gauge from bjoern@3936: * the XML Document. bjoern@3936: */ bjoern@3936: @Override bjoern@3936: public void setup( bjoern@3936: String identifier, bjoern@3936: ArtifactFactory factory, bjoern@3936: Object context, bjoern@3936: CallMeta callmeta, bjoern@3936: Document data) bjoern@3936: { bjoern@3936: logger.debug("GaugeDischargeCurveArtifact.setup"); bjoern@3936: bjoern@3936: if (logger.isDebugEnabled()) { bjoern@4028: logger.debug("GaugeDischargeCurveArtifact.setup" + XMLUtils.toString(data)); bjoern@3936: } bjoern@3936: String gaugeref = XMLUtils.xpathString(data, XPATH_GAUGE, bjoern@3936: ArtifactNamespaceContext.INSTANCE); bjoern@3936: String rivername = XMLUtils.xpathString(data, XPATH_RIVER, bjoern@3936: ArtifactNamespaceContext.INSTANCE); bjoern@3936: bjoern@4034: addData("river", new DefaultStateData("river", bjoern@4034: Resources.getMsg(callmeta, bjoern@4034: "facet.gauge_discharge_curve.river", bjoern@4034: "Name of the river"), bjoern@4034: "String", rivername)); bjoern@4034: addData("reference_gauge", new DefaultStateData("reference_gauge", bjoern@4034: Resources.getMsg(callmeta, bjoern@4034: "facet.gauge_discharge_curve.reference_gauge", bjoern@4034: "Gauge official number"), bjoern@4186: "Long", gaugeref)); bjoern@3936: bjoern@4032: Gauge gauge = FLYSUtils.getReferenceGauge(this); bjoern@4034: String gaugename = ""; bjoern@4190: Double gaugelocation = null; bjoern@4034: if (gauge != null) { bjoern@4034: gaugename = gauge.getName(); bjoern@4190: BigDecimal station = gauge.getStation(); bjoern@4190: if (station != null) { bjoern@4190: gaugelocation = station.doubleValue(); bjoern@4190: } bjoern@4034: } bjoern@4032: bjoern@4164: addData("gauge_name", new DefaultStateData("gauge_name", bjoern@4164: Resources.getMsg(callmeta, bjoern@4164: "facet.gauge_discharge_curve.gauge_name", bjoern@4164: "Name of the gauge"), bjoern@4164: "String", gaugename)); bjoern@4164: bjoern@4190: if (gaugelocation != null) { bjoern@4190: addData("ld_locations", new DefaultStateData("ld_locations", bjoern@4190: Resources.getMsg(callmeta, bjoern@4190: "facet.gauge_discharge_curve.gauge_location", bjoern@4190: "Location of the gauge"), bjoern@4190: "Double", gaugelocation.toString())); bjoern@4190: } bjoern@4190: bjoern@4032: String description = Resources.format(callmeta, bjoern@4032: "facet.gauge_discharge_curve.description", bjoern@4032: "Discharge curve on gauge", bjoern@4032: rivername, bjoern@4034: gaugename); bjoern@4032: bjoern@4188: List fs = new ArrayList(2); bjoern@4188: curvefacet = new GaugeDischargeCurveFacet( bjoern@4188: GAUGE_DISCHARGE_CURVE_FACET, description); bjoern@4188: fs.add(curvefacet); bjoern@3936: bjoern@4188: description = Resources.format(callmeta, bjoern@4188: "facet.gauge_discharge_curve_at_export.description", bjoern@4188: "Discharge curve AT export on gauge", bjoern@4188: rivername, bjoern@4188: gaugename); bjoern@4188: atexportfacet = new GaugeDischargeCurveFacet( bjoern@4188: GAUGE_DISCHARGE_CURVE_AT_EXPORT_FACET, description); bjoern@4188: fs.add(atexportfacet); bjoern@3936: bjoern@3936: addFacets(STATIC_STATE_NAME, fs); bjoern@3936: bjoern@3936: super.setup(identifier, factory, context, callmeta, data); bjoern@3936: } bjoern@3936: bjoern@3936: @Override bjoern@3936: public String getName() { bjoern@3936: return NAME; bjoern@3936: } bjoern@3936: bjoern@3936: @Override bjoern@3936: protected void initStaticState() { bjoern@3936: StaticState state = new StaticState(STATIC_STATE_NAME); bjoern@4188: bjoern@4188: List fs = new ArrayList(1); bjoern@4188: fs.add(curvefacet); bjoern@4188: bjoern@3936: DefaultOutput output = new DefaultOutput( bjoern@4188: GAUGE_DISCHARGE_CURVE_OUT, bjoern@4188: "output.discharge_curve", bjoern@4188: "image/png", bjoern@3936: fs, bjoern@3936: "chart"); bjoern@4188: state.addOutput(output); bjoern@3936: bjoern@4188: fs = new ArrayList(1); bjoern@4188: fs.add(atexportfacet); bjoern@4188: output = new DefaultOutput( bjoern@4188: GAUGE_DISCHARGE_CURVE_AT_EXPORT_OUT, bjoern@4188: "output.computed_dischargecurve_at_export", bjoern@4188: "text/plain", bjoern@4188: fs, bjoern@4188: "export"); bjoern@3936: state.addOutput(output); bjoern@4188: bjoern@4159: state.setUIProvider(UIPROVIDER); bjoern@3936: setStaticState(state); bjoern@3936: } bjoern@3936: }