Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java @ 8202:e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 05 Sep 2014 12:58:17 +0200 |
parents | 8d5ca5175038 |
children | c086b06b81e5 |
comparison
equal
deleted
inserted
replaced
8201:4b8c5a08de04 | 8202:e4606eae8ea5 |
---|---|
54 */ | 54 */ |
55 public class MainValuesArtifact | 55 public class MainValuesArtifact |
56 extends StaticD4EArtifact | 56 extends StaticD4EArtifact |
57 implements FacetTypes | 57 implements FacetTypes |
58 { | 58 { |
59 /** The logger for this class. */ | 59 /** The log for this class. */ |
60 private static Logger logger = Logger.getLogger(MainValuesArtifact.class); | 60 private static Logger log = Logger.getLogger(MainValuesArtifact.class); |
61 | 61 |
62 /** The name of the artifact. */ | 62 /** The name of the artifact. */ |
63 public static final String ARTIFACT_NAME = "mainvalue"; | 63 public static final String ARTIFACT_NAME = "mainvalue"; |
64 | 64 |
65 /** The name of the static state for this artifact. */ | 65 /** The name of the static state for this artifact. */ |
92 | 92 |
93 /** | 93 /** |
94 * Trivial Constructor. | 94 * Trivial Constructor. |
95 */ | 95 */ |
96 public MainValuesArtifact() { | 96 public MainValuesArtifact() { |
97 logger.debug("MainValuesArtifact.MainValuesartifact()"); | 97 log.debug("MainValuesArtifact.MainValuesartifact()"); |
98 } | 98 } |
99 | 99 |
100 | 100 |
101 /** | 101 /** |
102 * Gets called from factory, to set things up. | 102 * Gets called from factory, to set things up. |
108 Object context, | 108 Object context, |
109 CallMeta callMeta, | 109 CallMeta callMeta, |
110 Document data, | 110 Document data, |
111 List<Class> loadFacets) | 111 List<Class> loadFacets) |
112 { | 112 { |
113 logger.debug("MainValuesArtifact.setup"); | 113 log.debug("MainValuesArtifact.setup"); |
114 state = new StaticState(STATIC_STATE_NAME); | 114 state = new StaticState(STATIC_STATE_NAME); |
115 | 115 |
116 initFromGaugeDoc(data, callMeta); | 116 initFromGaugeDoc(data, callMeta); |
117 | 117 |
118 List<Facet> fs = new ArrayList<Facet>(); | 118 List<Facet> fs = new ArrayList<Facet>(); |
119 addFacets(state.getID(), fs); | 119 addFacets(state.getID(), fs); |
120 spawnState(); | 120 spawnState(); |
121 super.setup(identifier, factory, context, callMeta, data, loadFacets); | 121 super.setup(identifier, factory, context, callMeta, data, loadFacets); |
122 String restriction = getDatacageIDValue(data); | 122 String restriction = getDatacageIDValue(data); |
123 logger.debug("mainvalue restriction " + restriction); | 123 log.debug("mainvalue restriction " + restriction); |
124 boolean restricted = restriction.endsWith("q") || restriction.endsWith("w"); | 124 boolean restricted = restriction.endsWith("q") || restriction.endsWith("w"); |
125 if (!restricted || restriction.endsWith("q")) { | 125 if (!restricted || restriction.endsWith("q")) { |
126 Facet qfacet0 = new MainValuesQFacet( | 126 Facet qfacet0 = new MainValuesQFacet( |
127 DURATION_MAINVALUES_Q, | 127 DURATION_MAINVALUES_Q, |
128 Resources.getMsg( | 128 Resources.getMsg( |
199 data, GaugeDischargeCurveArtifact.XPATH_RIVER, | 199 data, GaugeDischargeCurveArtifact.XPATH_RIVER, |
200 ArtifactNamespaceContext.INSTANCE); | 200 ArtifactNamespaceContext.INSTANCE); |
201 | 201 |
202 if (rivername == null || gaugeref == null || rivername.equals("") | 202 if (rivername == null || gaugeref == null || rivername.equals("") |
203 || gaugeref.equals("")) { | 203 || gaugeref.equals("")) { |
204 logger.debug("Not setting MainValuesArtifact up from gauge doc."); | 204 log.debug("Not setting MainValuesArtifact up from gauge doc."); |
205 return; | 205 return; |
206 } | 206 } |
207 | 207 |
208 addData("river", new DefaultStateData("river", | 208 addData("river", new DefaultStateData("river", |
209 Resources.getMsg(callMeta, | 209 Resources.getMsg(callMeta, |
215 Long officialNumber = Long.valueOf(gaugeref); | 215 Long officialNumber = Long.valueOf(gaugeref); |
216 Gauge gauge = Gauge.getGaugeByOfficialNumber(officialNumber); | 216 Gauge gauge = Gauge.getGaugeByOfficialNumber(officialNumber); |
217 addData("ld_locations", new DefaultStateData("ld_locations", null, null, | 217 addData("ld_locations", new DefaultStateData("ld_locations", null, null, |
218 String.valueOf(gauge.getStation()))); | 218 String.valueOf(gauge.getStation()))); |
219 } catch (NumberFormatException nfe) { | 219 } catch (NumberFormatException nfe) { |
220 logger.debug("MainValuesArtifact could not parse gaugeref from doc."); | 220 log.debug("MainValuesArtifact could not parse gaugeref from doc."); |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 | 224 |
225 /** | 225 /** |
241 | 241 |
242 | 242 |
243 /** Get important data from the 'calling' artifact. */ | 243 /** Get important data from the 'calling' artifact. */ |
244 @Override | 244 @Override |
245 protected void initialize(Artifact artifact, Object context, CallMeta meta) { | 245 protected void initialize(Artifact artifact, Object context, CallMeta meta) { |
246 logger.debug("MainValuesArtifact.initialize"); | 246 log.debug("MainValuesArtifact.initialize"); |
247 D4EArtifact winfo = (D4EArtifact) artifact; | 247 D4EArtifact winfo = (D4EArtifact) artifact; |
248 RangeAccess rangeAccess = new RangeAccess(winfo); | 248 RangeAccess rangeAccess = new RangeAccess(winfo); |
249 double [] locations = rangeAccess.getKmRange(); | 249 double [] locations = rangeAccess.getKmRange(); |
250 | 250 |
251 if (locations != null) { | 251 if (locations != null) { |
252 double location = locations[0]; | 252 double location = locations[0]; |
253 addData("ld_locations", new DefaultStateData("ld_locations", null, null, | 253 addData("ld_locations", new DefaultStateData("ld_locations", null, null, |
254 String.valueOf(location))); | 254 String.valueOf(location))); |
255 } | 255 } |
256 else { | 256 else { |
257 logger.error("No location for mainvalues given."); | 257 log.error("No location for mainvalues given."); |
258 } | 258 } |
259 importData(winfo, "river"); | 259 importData(winfo, "river"); |
260 // In the case of DischargeWQCurves, there are no locations, but a gauge. | 260 // In the case of DischargeWQCurves, there are no locations, but a gauge. |
261 if (getDataAsString("ld_locations") == null) { | 261 if (getDataAsString("ld_locations") == null) { |
262 // TODO its a tad difficult to remodel Range/Gauge-Access to | 262 // TODO its a tad difficult to remodel Range/Gauge-Access to |
266 Gauge g = Gauge.getGaugeByOfficialNumber(Integer.parseInt(refGaugeID)); | 266 Gauge g = Gauge.getGaugeByOfficialNumber(Integer.parseInt(refGaugeID)); |
267 addData("ld_locations", new DefaultStateData("ld_locations", null, null, | 267 addData("ld_locations", new DefaultStateData("ld_locations", null, null, |
268 String.valueOf(g.getStation()))); | 268 String.valueOf(g.getStation()))); |
269 } | 269 } |
270 else { | 270 else { |
271 logger.error("MainValuesArtifact: No location/gauge."); | 271 log.error("MainValuesArtifact: No location/gauge."); |
272 } | 272 } |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 | 276 |
328 */ | 328 */ |
329 protected Gauge getGauge(double km) { | 329 protected Gauge getGauge(double km) { |
330 River river = RiverUtils.getRiver(this); | 330 River river = RiverUtils.getRiver(this); |
331 | 331 |
332 if (river == null) { | 332 if (river == null) { |
333 logger.error("River is null"); | 333 log.error("River is null"); |
334 return null; | 334 return null; |
335 } | 335 } |
336 | 336 |
337 return river.determineGaugeByPosition(km); | 337 return river.determineGaugeByPosition(km); |
338 } | 338 } |
347 | 347 |
348 // TODO use helper to get location as double | 348 // TODO use helper to get location as double |
349 String locationStr = getDataAsString("ld_locations"); | 349 String locationStr = getDataAsString("ld_locations"); |
350 | 350 |
351 if (river == null) { | 351 if (river == null) { |
352 logger.error("River is null"); | 352 log.error("River is null"); |
353 return null; | 353 return null; |
354 } | 354 } |
355 | 355 |
356 if (locationStr == null) { | 356 if (locationStr == null) { |
357 logger.error("Locationstr is null"); | 357 log.error("Locationstr is null"); |
358 return null; | 358 return null; |
359 } | 359 } |
360 | 360 |
361 double location = Double.parseDouble(locationStr); | 361 double location = Double.parseDouble(locationStr); |
362 | 362 |
377 /** | 377 /** |
378 * Get a list of "Q" main values. | 378 * Get a list of "Q" main values. |
379 * @return list of Q main values. | 379 * @return list of Q main values. |
380 */ | 380 */ |
381 public List<NamedDouble> getMainValuesQ(double[] kms) { | 381 public List<NamedDouble> getMainValuesQ(double[] kms) { |
382 logger.debug("MainValuesArtifact.getMainValuesQ(d)"); | 382 log.debug("MainValuesArtifact.getMainValuesQ(d)"); |
383 List<NamedDouble> filteredList = new ArrayList<NamedDouble>(); | 383 List<NamedDouble> filteredList = new ArrayList<NamedDouble>(); |
384 boolean atGauge = false; | 384 boolean atGauge = false; |
385 Gauge gauge = getGauge(kms[0]); | 385 Gauge gauge = getGauge(kms[0]); |
386 WstValueTable interpolator = WstValueTableFactory.getTable(RiverUtils.getRiver(this)); | 386 WstValueTable interpolator = WstValueTableFactory.getTable(RiverUtils.getRiver(this)); |
387 Calculation c = new Calculation(); | 387 Calculation c = new Calculation(); |
414 * Get a list of "Q" main values. | 414 * Get a list of "Q" main values. |
415 * @param atGauge whether is at gauge or needs interpolation. | 415 * @param atGauge whether is at gauge or needs interpolation. |
416 * @return list of Q main values. | 416 * @return list of Q main values. |
417 */ | 417 */ |
418 public List<NamedDouble> getMainValuesQ(boolean atGauge) { | 418 public List<NamedDouble> getMainValuesQ(boolean atGauge) { |
419 logger.debug("MainValuesArtifact.getMainValuesQ(b)"); | 419 log.debug("MainValuesArtifact.getMainValuesQ(b)"); |
420 List<NamedDouble> filteredList = new ArrayList<NamedDouble>(); | 420 List<NamedDouble> filteredList = new ArrayList<NamedDouble>(); |
421 Gauge gauge = getGauge(); | 421 Gauge gauge = getGauge(); |
422 WstValueTable interpolator = WstValueTableFactory.getTable(RiverUtils.getRiver(this)); | 422 WstValueTable interpolator = WstValueTableFactory.getTable(RiverUtils.getRiver(this)); |
423 Calculation c = new Calculation(); | 423 Calculation c = new Calculation(); |
424 double w_out[] = {0.0f}; | 424 double w_out[] = {0.0f}; |