Mercurial > dive4elements > river
changeset 6038:a0dd303f4a08
MainValuesArtifact: prepare to be created by crafted document.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 16 May 2013 16:25:06 +0200 |
parents | 7dd2f5435426 |
children | b6dab05553e2 |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java |
diffstat | 1 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java Thu May 16 16:20:18 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java Thu May 16 16:25:06 2013 +0200 @@ -25,6 +25,9 @@ import org.dive4elements.artifacts.ArtifactFactory; import org.dive4elements.artifacts.CallMeta; +import org.dive4elements.artifacts.common.ArtifactNamespaceContext; +import org.dive4elements.artifacts.common.utils.XMLUtils; + import org.dive4elements.river.model.Gauge; import org.dive4elements.river.model.MainValue; import org.dive4elements.river.model.River; @@ -106,6 +109,8 @@ logger.debug("MainValuesArtifact.setup"); state = new StaticState(STATIC_STATE_NAME); + initFromGaugeDoc(data, callMeta); + List<Facet> fs = new ArrayList<Facet>(); addFacets(state.getID(), fs); spawnState(); @@ -176,6 +181,41 @@ } } + /** + * The MainValueArtifact can be set up with a document giving the + * river and gauge. This happens in context of GaugeDischargeArtifact. + * In that case, initalize() is not called. + */ + private void initFromGaugeDoc(Document data, CallMeta callMeta) { + String gaugeref = XMLUtils.xpathString( + data, GaugeDischargeCurveArtifact.XPATH_GAUGE, + ArtifactNamespaceContext.INSTANCE); + String rivername = XMLUtils.xpathString( + data, GaugeDischargeCurveArtifact.XPATH_RIVER, + ArtifactNamespaceContext.INSTANCE); + + if (rivername == null || gaugeref == null || rivername.equals("") + || gaugeref.equals("")) { + logger.debug("Not setting MainValuesArtifact up from gauge doc."); + return; + } + + addData("river", new DefaultStateData("river", + Resources.getMsg(callMeta, + "facet.gauge_discharge_curve.river", + "Name of the river"), + "String", rivername)); + + try { + Long officialNumber = Long.valueOf(gaugeref); + Gauge gauge = Gauge.getGaugeByOfficialNumber(officialNumber); + addData("ld_locations", new DefaultStateData("ld_locations", null, null, + String.valueOf(gauge.getStation()))); + } catch (NumberFormatException nfe) { + logger.debug("MainValuesArtifact could not parse gaugeref from doc."); + } + } + /** * Create "the" state.