# HG changeset patch # User Felix Wolfsteller # Date 1368714306 -7200 # Node ID a0dd303f4a08f94f09175e06da37f89cd01067b3 # Parent 7dd2f5435426673b5a9401094598f806f3b112c9 MainValuesArtifact: prepare to be created by crafted document. diff -r 7dd2f5435426 -r a0dd303f4a08 artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java --- 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 fs = new ArrayList(); 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.