Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java @ 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 | af13ceeba52a |
children | a0078e5e3b39 |
comparison
equal
deleted
inserted
replaced
6037:7dd2f5435426 | 6038:a0dd303f4a08 |
---|---|
22 import org.dive4elements.artifactdatabase.state.State; | 22 import org.dive4elements.artifactdatabase.state.State; |
23 | 23 |
24 import org.dive4elements.artifacts.Artifact; | 24 import org.dive4elements.artifacts.Artifact; |
25 import org.dive4elements.artifacts.ArtifactFactory; | 25 import org.dive4elements.artifacts.ArtifactFactory; |
26 import org.dive4elements.artifacts.CallMeta; | 26 import org.dive4elements.artifacts.CallMeta; |
27 | |
28 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; | |
29 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
27 | 30 |
28 import org.dive4elements.river.model.Gauge; | 31 import org.dive4elements.river.model.Gauge; |
29 import org.dive4elements.river.model.MainValue; | 32 import org.dive4elements.river.model.MainValue; |
30 import org.dive4elements.river.model.River; | 33 import org.dive4elements.river.model.River; |
31 | 34 |
104 Document data) | 107 Document data) |
105 { | 108 { |
106 logger.debug("MainValuesArtifact.setup"); | 109 logger.debug("MainValuesArtifact.setup"); |
107 state = new StaticState(STATIC_STATE_NAME); | 110 state = new StaticState(STATIC_STATE_NAME); |
108 | 111 |
112 initFromGaugeDoc(data, callMeta); | |
113 | |
109 List<Facet> fs = new ArrayList<Facet>(); | 114 List<Facet> fs = new ArrayList<Facet>(); |
110 addFacets(state.getID(), fs); | 115 addFacets(state.getID(), fs); |
111 spawnState(); | 116 spawnState(); |
112 super.setup(identifier, factory, context, callMeta, data); | 117 super.setup(identifier, factory, context, callMeta, data); |
113 String restriction = getDatacageIDValue(data); | 118 String restriction = getDatacageIDValue(data); |
171 "historical_discharge.mainvalues.w"), | 176 "historical_discharge.mainvalues.w"), |
172 true); | 177 true); |
173 fs.add(wfacet1); | 178 fs.add(wfacet1); |
174 fs.add(wfacet2); | 179 fs.add(wfacet2); |
175 fs.add(wfacet3); | 180 fs.add(wfacet3); |
181 } | |
182 } | |
183 | |
184 /** | |
185 * The MainValueArtifact can be set up with a document giving the | |
186 * river and gauge. This happens in context of GaugeDischargeArtifact. | |
187 * In that case, initalize() is not called. | |
188 */ | |
189 private void initFromGaugeDoc(Document data, CallMeta callMeta) { | |
190 String gaugeref = XMLUtils.xpathString( | |
191 data, GaugeDischargeCurveArtifact.XPATH_GAUGE, | |
192 ArtifactNamespaceContext.INSTANCE); | |
193 String rivername = XMLUtils.xpathString( | |
194 data, GaugeDischargeCurveArtifact.XPATH_RIVER, | |
195 ArtifactNamespaceContext.INSTANCE); | |
196 | |
197 if (rivername == null || gaugeref == null || rivername.equals("") | |
198 || gaugeref.equals("")) { | |
199 logger.debug("Not setting MainValuesArtifact up from gauge doc."); | |
200 return; | |
201 } | |
202 | |
203 addData("river", new DefaultStateData("river", | |
204 Resources.getMsg(callMeta, | |
205 "facet.gauge_discharge_curve.river", | |
206 "Name of the river"), | |
207 "String", rivername)); | |
208 | |
209 try { | |
210 Long officialNumber = Long.valueOf(gaugeref); | |
211 Gauge gauge = Gauge.getGaugeByOfficialNumber(officialNumber); | |
212 addData("ld_locations", new DefaultStateData("ld_locations", null, null, | |
213 String.valueOf(gauge.getStation()))); | |
214 } catch (NumberFormatException nfe) { | |
215 logger.debug("MainValuesArtifact could not parse gaugeref from doc."); | |
176 } | 216 } |
177 } | 217 } |
178 | 218 |
179 | 219 |
180 /** | 220 /** |