Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java @ 5867:59ff03ff48f1
River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 28 Apr 2013 15:23:01 +0200 |
parents | 9a6741ccf6d4 |
children | af13ceeba52a |
comparison
equal
deleted
inserted
replaced
5866:9a6741ccf6d4 | 5867:59ff03ff48f1 |
---|---|
11 import org.dive4elements.artifactdatabase.state.State; | 11 import org.dive4elements.artifactdatabase.state.State; |
12 import org.dive4elements.artifacts.Artifact; | 12 import org.dive4elements.artifacts.Artifact; |
13 import org.dive4elements.artifacts.CallContext; | 13 import org.dive4elements.artifacts.CallContext; |
14 import org.dive4elements.artifacts.common.utils.Config; | 14 import org.dive4elements.artifacts.common.utils.Config; |
15 import org.dive4elements.artifacts.common.utils.XMLUtils; | 15 import org.dive4elements.artifacts.common.utils.XMLUtils; |
16 import org.dive4elements.river.artifacts.FLYSArtifact; | 16 import org.dive4elements.river.artifacts.D4EArtifact; |
17 import org.dive4elements.river.artifacts.StaticWKmsArtifact; | 17 import org.dive4elements.river.artifacts.StaticWKmsArtifact; |
18 import org.dive4elements.river.artifacts.WINFOArtifact; | 18 import org.dive4elements.river.artifacts.WINFOArtifact; |
19 import org.dive4elements.river.artifacts.access.RangeAccess; | 19 import org.dive4elements.river.artifacts.access.RangeAccess; |
20 import org.dive4elements.river.artifacts.context.RiverContext; | 20 import org.dive4elements.river.artifacts.context.RiverContext; |
21 import org.dive4elements.river.artifacts.model.LocationProvider; | 21 import org.dive4elements.river.artifacts.model.LocationProvider; |
48 import org.hibernate.impl.SessionFactoryImpl; | 48 import org.hibernate.impl.SessionFactoryImpl; |
49 import org.w3c.dom.Document; | 49 import org.w3c.dom.Document; |
50 | 50 |
51 | 51 |
52 /** | 52 /** |
53 * Static helper methods to e.g. access FLYSArtifacts data. | 53 * Static helper methods to e.g. access D4EArtifacts data. |
54 * | 54 * |
55 * @deprecated Don't use RiverUtils to get data from an {@link Artifact} anymore. | 55 * @deprecated Don't use RiverUtils to get data from an {@link Artifact} anymore. |
56 * Instead use and/or create a {@link Access} class hierarchy. | 56 * Instead use and/or create a {@link Access} class hierarchy. |
57 **/ | 57 **/ |
58 @Deprecated | 58 @Deprecated |
109 } | 109 } |
110 | 110 |
111 | 111 |
112 /** | 112 /** |
113 * Pulls Artifact with given UUID fromm database. | 113 * Pulls Artifact with given UUID fromm database. |
114 * @return FLYSArtifact with given UUID or null (in case of errors). | 114 * @return D4EArtifact with given UUID or null (in case of errors). |
115 */ | 115 */ |
116 public static FLYSArtifact getArtifact(String uuid, CallContext context) { | 116 public static D4EArtifact getArtifact(String uuid, CallContext context) { |
117 try { | 117 try { |
118 Artifact artifact = context.getDatabase().getRawArtifact(uuid); | 118 Artifact artifact = context.getDatabase().getRawArtifact(uuid); |
119 | 119 |
120 if (artifact == null) { | 120 if (artifact == null) { |
121 logger.error("Artifact '" + uuid + "' does not exist."); | 121 logger.error("Artifact '" + uuid + "' does not exist."); |
122 return null; | 122 return null; |
123 } | 123 } |
124 | 124 |
125 if (!(artifact instanceof FLYSArtifact)) { | 125 if (!(artifact instanceof D4EArtifact)) { |
126 logger.error("Artifact '" +uuid+ "' is no valid FLYSArtifact."); | 126 logger.error("Artifact '" +uuid+ "' is no valid D4EArtifact."); |
127 return null; | 127 return null; |
128 } | 128 } |
129 | 129 |
130 return (FLYSArtifact) artifact; | 130 return (D4EArtifact) artifact; |
131 } | 131 } |
132 // TODO: catch more selective | 132 // TODO: catch more selective |
133 catch (Exception e) { | 133 catch (Exception e) { |
134 logger.error("Cannot get FLYSArtifact " + uuid | 134 logger.error("Cannot get D4EArtifact " + uuid |
135 + " from database (" + e.getMessage() + ")."); | 135 + " from database (" + e.getMessage() + ")."); |
136 return null; | 136 return null; |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
180 /** | 180 /** |
181 * This method returns an WQ_MODE enum which is based on the parameters | 181 * This method returns an WQ_MODE enum which is based on the parameters |
182 * stored in <i>flys</i> Artifact. If there is no <i>wq_isq</i> parameter | 182 * stored in <i>flys</i> Artifact. If there is no <i>wq_isq</i> parameter |
183 * existing, WQ_MODE.NONE is returned. | 183 * existing, WQ_MODE.NONE is returned. |
184 * | 184 * |
185 * @param flys The FLYSArtifact that stores wq mode relevant parameters. | 185 * @param flys The D4EArtifact that stores wq mode relevant parameters. |
186 * | 186 * |
187 * @return an enum WQ_MODE. | 187 * @return an enum WQ_MODE. |
188 */ | 188 */ |
189 public static WQ_MODE getWQMode(FLYSArtifact flys) { | 189 public static WQ_MODE getWQMode(D4EArtifact flys) { |
190 if (flys == null) { | 190 if (flys == null) { |
191 return WQ_MODE.NONE; | 191 return WQ_MODE.NONE; |
192 } | 192 } |
193 | 193 |
194 String values = flys.getDataAsString("wq_values"); | 194 String values = flys.getDataAsString("wq_values"); |
210 return WQ_MODE.NONE; | 210 return WQ_MODE.NONE; |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 | 214 |
215 public static WQ_INPUT getWQInputMode(FLYSArtifact flys) { | 215 public static WQ_INPUT getWQInputMode(D4EArtifact flys) { |
216 if (flys == null) { | 216 if (flys == null) { |
217 return WQ_INPUT.NONE; | 217 return WQ_INPUT.NONE; |
218 } | 218 } |
219 | 219 |
220 Boolean selection = flys.getDataAsBoolean("wq_isrange"); | 220 Boolean selection = flys.getDataAsBoolean("wq_isrange"); |
236 /** | 236 /** |
237 * Get bounds for river of artifact. | 237 * Get bounds for river of artifact. |
238 * @param flysArtifact artifact which has a "river" data. | 238 * @param flysArtifact artifact which has a "river" data. |
239 * @return double array. min is at[0], max at[1]. null if given artifact is null | 239 * @return double array. min is at[0], max at[1]. null if given artifact is null |
240 */ | 240 */ |
241 public static double[] getRiverMinMax(FLYSArtifact flysArtifact) { | 241 public static double[] getRiverMinMax(D4EArtifact flysArtifact) { |
242 if (flysArtifact == null) { | 242 if (flysArtifact == null) { |
243 return null; | 243 return null; |
244 } | 244 } |
245 | 245 |
246 String riverName = flysArtifact.getDataAsString("river"); | 246 String riverName = flysArtifact.getDataAsString("river"); |
257 ? river.determineMinMaxDistance() | 257 ? river.determineMinMaxDistance() |
258 : null; | 258 : null; |
259 } | 259 } |
260 | 260 |
261 | 261 |
262 public static double[] getKmFromTo(FLYSArtifact flys) { | 262 public static double[] getKmFromTo(D4EArtifact flys) { |
263 String strFrom = flys.getDataAsString("ld_from"); | 263 String strFrom = flys.getDataAsString("ld_from"); |
264 String strTo = flys.getDataAsString("ld_to"); | 264 String strTo = flys.getDataAsString("ld_to"); |
265 | 265 |
266 if (strFrom == null) { | 266 if (strFrom == null) { |
267 strFrom = flys.getDataAsString("from"); | 267 strFrom = flys.getDataAsString("from"); |
289 /** | 289 /** |
290 * Return sorted array of locations at which stuff was calculated | 290 * Return sorted array of locations at which stuff was calculated |
291 * (from ld_locations data), null if not parameterized this way. | 291 * (from ld_locations data), null if not parameterized this way. |
292 */ | 292 */ |
293 // TODO moved to RangeAccess. Resolve remaining calls. | 293 // TODO moved to RangeAccess. Resolve remaining calls. |
294 private static double[] getLocations(FLYSArtifact flys) { | 294 private static double[] getLocations(D4EArtifact flys) { |
295 String locationStr = flys.getDataAsString("ld_locations"); | 295 String locationStr = flys.getDataAsString("ld_locations"); |
296 | 296 |
297 if (locationStr == null || locationStr.length() == 0) { | 297 if (locationStr == null || locationStr.length() == 0) { |
298 if (flys instanceof WINFOArtifact) { | 298 if (flys instanceof WINFOArtifact) { |
299 WINFOArtifact winfo = (WINFOArtifact) flys; | 299 WINFOArtifact winfo = (WINFOArtifact) flys; |
325 return locations.toNativeArray(); | 325 return locations.toNativeArray(); |
326 } | 326 } |
327 | 327 |
328 | 328 |
329 /** | 329 /** |
330 * Returns the Qs for a given FLYSArtifact. This method currently accepts | 330 * Returns the Qs for a given D4EArtifact. This method currently accepts |
331 * only instances of WINFOArtifact. | 331 * only instances of WINFOArtifact. |
332 * | 332 * |
333 * @param flys A FLYSArtifact. | 333 * @param flys A D4EArtifact. |
334 * | 334 * |
335 * @return the Qs. | 335 * @return the Qs. |
336 */ | 336 */ |
337 public static double[] getQs(FLYSArtifact flys) { | 337 public static double[] getQs(D4EArtifact flys) { |
338 // XXX this is not nice! | 338 // XXX this is not nice! |
339 if (flys instanceof WINFOArtifact) { | 339 if (flys instanceof WINFOArtifact) { |
340 return ((WINFOArtifact) flys).getQs(); | 340 return ((WINFOArtifact) flys).getQs(); |
341 } | 341 } |
342 | 342 |
345 return null; | 345 return null; |
346 } | 346 } |
347 | 347 |
348 | 348 |
349 /** | 349 /** |
350 * Returns the Ws for a given FLYSArtifact. This method currently accepts | 350 * Returns the Ws for a given D4EArtifact. This method currently accepts |
351 * only instances of WINFOArtifact. | 351 * only instances of WINFOArtifact. |
352 * | 352 * |
353 * @param flys A FLYSArtifact. | 353 * @param flys A D4EArtifact. |
354 * | 354 * |
355 * @return the Ws. | 355 * @return the Ws. |
356 */ | 356 */ |
357 public static double[] getWs(FLYSArtifact flys) { | 357 public static double[] getWs(D4EArtifact flys) { |
358 // XXX this is not nice! | 358 // XXX this is not nice! |
359 if (flys instanceof WINFOArtifact) { | 359 if (flys instanceof WINFOArtifact) { |
360 return ((WINFOArtifact) flys).getWs(); | 360 return ((WINFOArtifact) flys).getWs(); |
361 } | 361 } |
362 | 362 |
370 * Returns the selected River object based on the 'river' data that might | 370 * Returns the selected River object based on the 'river' data that might |
371 * have been inserted by the user. | 371 * have been inserted by the user. |
372 * | 372 * |
373 * @return the selected River or null if no river has been chosen yet. | 373 * @return the selected River or null if no river has been chosen yet. |
374 */ | 374 */ |
375 public static River getRiver(FLYSArtifact flys) { | 375 public static River getRiver(D4EArtifact flys) { |
376 String sRiver = getRivername(flys); | 376 String sRiver = getRivername(flys); |
377 | 377 |
378 return (sRiver != null) | 378 return (sRiver != null) |
379 ? RiverFactory.getRiver(sRiver) | 379 ? RiverFactory.getRiver(sRiver) |
380 : null; | 380 : null; |
383 | 383 |
384 /** | 384 /** |
385 * Returns the name of the river specified in the given <i>flys</i> | 385 * Returns the name of the river specified in the given <i>flys</i> |
386 * Artifact. | 386 * Artifact. |
387 * | 387 * |
388 * @param flys The FLYSArtifact that stores a river relevant information. | 388 * @param flys The D4EArtifact that stores a river relevant information. |
389 * | 389 * |
390 * @return the name of the specified river or null. | 390 * @return the name of the specified river or null. |
391 */ | 391 */ |
392 public static String getRivername(FLYSArtifact flys) { | 392 public static String getRivername(D4EArtifact flys) { |
393 return flys != null ? flys.getDataAsString("river") : null; | 393 return flys != null ? flys.getDataAsString("river") : null; |
394 } | 394 } |
395 | 395 |
396 | 396 |
397 /** | 397 /** |
398 * Extracts the SRID defined in the global configuration for the river | 398 * Extracts the SRID defined in the global configuration for the river |
399 * specified in <i>artifact</i>. | 399 * specified in <i>artifact</i>. |
400 * | 400 * |
401 * @param artifact The FLYSArtifact that stores the name of the river. | 401 * @param artifact The D4EArtifact that stores the name of the river. |
402 * | 402 * |
403 * @return the SRID as string (e.g. "31466"). | 403 * @return the SRID as string (e.g. "31466"). |
404 */ | 404 */ |
405 public static String getRiverSrid(FLYSArtifact artifact) { | 405 public static String getRiverSrid(D4EArtifact artifact) { |
406 String river = artifact.getDataAsString("river"); | 406 String river = artifact.getDataAsString("river"); |
407 | 407 |
408 if (river == null || river.length() == 0) { | 408 if (river == null || river.length() == 0) { |
409 return null; | 409 return null; |
410 } | 410 } |
449 * Return the (first) Gauge corresponding to the given location(s) of | 449 * Return the (first) Gauge corresponding to the given location(s) of |
450 * the artifact. | 450 * the artifact. |
451 * @param flys the artifact in question. | 451 * @param flys the artifact in question. |
452 * @return (First) gauge of locations of river of artifact. | 452 * @return (First) gauge of locations of river of artifact. |
453 */ | 453 */ |
454 public static Gauge getGauge(FLYSArtifact flys) { | 454 public static Gauge getGauge(D4EArtifact flys) { |
455 River river = getRiver(flys); | 455 River river = getRiver(flys); |
456 | 456 |
457 if (river == null) { | 457 if (river == null) { |
458 logger.debug("no river found"); | 458 logger.debug("no river found"); |
459 return null; | 459 return null; |
480 | 480 |
481 return gauge; | 481 return gauge; |
482 } | 482 } |
483 | 483 |
484 | 484 |
485 public static String getGaugename(FLYSArtifact flys) { | 485 public static String getGaugename(D4EArtifact flys) { |
486 Gauge gauge = getGauge(flys); | 486 Gauge gauge = getGauge(flys); |
487 | 487 |
488 return gauge != null ? gauge.getName() : null; | 488 return gauge != null ? gauge.getName() : null; |
489 } | 489 } |
490 | 490 |
491 | 491 |
492 public static Gauge getReferenceGauge(FLYSArtifact flys) { | 492 public static Gauge getReferenceGauge(D4EArtifact flys) { |
493 Long officialNumber = flys.getDataAsLong("reference_gauge"); | 493 Long officialNumber = flys.getDataAsLong("reference_gauge"); |
494 | 494 |
495 return officialNumber != null | 495 return officialNumber != null |
496 ? Gauge.getGaugeByOfficialNumber(officialNumber) | 496 ? Gauge.getGaugeByOfficialNumber(officialNumber) |
497 : null; | 497 : null; |
498 } | 498 } |
499 | 499 |
500 | 500 |
501 public static String getReferenceGaugeName(FLYSArtifact flys) { | 501 public static String getReferenceGaugeName(D4EArtifact flys) { |
502 Gauge refGauge = getReferenceGauge(flys); | 502 Gauge refGauge = getReferenceGauge(flys); |
503 | 503 |
504 return refGauge != null | 504 return refGauge != null |
505 ? refGauge.getName() | 505 ? refGauge.getName() |
506 : "-- not found --"; | 506 : "-- not found --"; |
696 } | 696 } |
697 | 697 |
698 | 698 |
699 /** | 699 /** |
700 * This method returns the description for a given <i>km</i> for a specific | 700 * This method returns the description for a given <i>km</i> for a specific |
701 * river. The river is provided by the FLYSArtifact <i>flys</i>. | 701 * river. The river is provided by the D4EArtifact <i>flys</i>. |
702 * | 702 * |
703 * @param flys The FLYSArtifact that provides a river. | 703 * @param flys The D4EArtifact that provides a river. |
704 * @param km The kilometer. | 704 * @param km The kilometer. |
705 * | 705 * |
706 * @return the description for <i>km</i> or an empty string if no | 706 * @return the description for <i>km</i> or an empty string if no |
707 * description was found. | 707 * description was found. |
708 */ | 708 */ |
709 public static String getLocationDescription(FLYSArtifact flys, double km) { | 709 public static String getLocationDescription(D4EArtifact flys, double km) { |
710 String river = getRivername(flys); | 710 String river = getRivername(flys); |
711 | 711 |
712 if (river == null) { | 712 if (river == null) { |
713 return ""; | 713 return ""; |
714 } | 714 } |
905 * @param flys the flys artifact. | 905 * @param flys the flys artifact. |
906 * | 906 * |
907 * @return the gauges based on the selected kilometer range (null if | 907 * @return the gauges based on the selected kilometer range (null if |
908 * none/no range set). | 908 * none/no range set). |
909 */ | 909 */ |
910 public static List<Gauge> getGauges(FLYSArtifact flys) { | 910 public static List<Gauge> getGauges(D4EArtifact flys) { |
911 | 911 |
912 River river = getRiver(flys); | 912 River river = getRiver(flys); |
913 if (river == null) { | 913 if (river == null) { |
914 logger.debug("getGauges: no river!"); | 914 logger.debug("getGauges: no river!"); |
915 return null; | 915 return null; |