annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/LocationProvider.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4010
diff changeset
9 package org.dive4elements.river.artifacts.model;
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import net.sf.ehcache.Cache;
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import net.sf.ehcache.Element;
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 5994
diff changeset
14 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 5994
diff changeset
15 import org.apache.logging.log4j.LogManager;
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4010
diff changeset
17 import org.dive4elements.river.model.Annotation;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4010
diff changeset
18 import org.dive4elements.river.model.FastAnnotations;
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4010
diff changeset
20 import org.dive4elements.river.artifacts.cache.CacheFactory;
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
4010
efb067ab2ca4 Added TODOs for issue880.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
22
efb067ab2ca4 Added TODOs for issue880.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
23 /** Make FastAnnotations (db unbound) available. */
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 public class LocationProvider {
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
26 private static final Logger log =
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 5994
diff changeset
27 LogManager.getLogger(LocationProvider.class);
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
28
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
29
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 public static final String CACHE_KEY = "location-provider";
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
32 public static final String PREFIX = "lp-";
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
33
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 private LocationProvider() {
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 }
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
38 public static String getLocation(String river, double km) {
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
40 FastAnnotations fas = getAnnotations(river, km);
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
41
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
42 FastAnnotations.Annotation an = fas.findByKm(km);
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
43
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
44 return an != null ? an.getPosition() : null;
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 }
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
47 public static FastAnnotations getAnnotations(String river) {
2289
fe3ea0f16098 Small bugfix for fetching river annotations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2144
diff changeset
48 return getAnnotations(river, Double.MAX_VALUE);
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
49 }
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
50
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
51 protected static FastAnnotations getAnnotations(String river, double km) {
4010
efb067ab2ca4 Added TODOs for issue880.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
52 // TODO issue880: Make annotations available _per type_
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 Cache cache = CacheFactory.getCache(CACHE_KEY);
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
56 if (cache == null) {
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
57 return uncachedAnnotations(river, km);
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 }
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
59
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
60 String key = PREFIX + river;
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
61
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
62 Element element = cache.get(key);
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
63
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
64 if (element != null) {
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
65 return (FastAnnotations)element.getValue();
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 }
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
67
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
68 FastAnnotations fas = uncachedAnnotations(river, Double.MAX_VALUE);
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
69
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
70 cache.put(new Element(key, fas));
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
71
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
72 return fas;
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 }
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
75 protected static FastAnnotations uncachedAnnotations(
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 String river,
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
77 double km
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 ) {
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
79 if (km != Double.MAX_VALUE) {
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
80 // XXX Fake it by using a standard Annotation.
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
81
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
82 Annotation annotation =
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
83 AnnotationsFactory.getAnnotation(river, km);
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
84
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
85 if (annotation != null) {
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
86 FastAnnotations.Annotation fa =
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
87 new FastAnnotations.Annotation(
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
88 km, Double.NaN,
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
89 annotation.getPosition().getValue(), null, null,
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
90 Double.NaN, Double.NaN);
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
91 return new FastAnnotations(
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
92 new FastAnnotations.Annotation [] { fa });
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
93 }
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
94
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
95 return new FastAnnotations(new FastAnnotations.Annotation[0]);
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 }
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
98 long startTime = System.currentTimeMillis();
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
99
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
100 FastAnnotations fas = new FastAnnotations(river);
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
101
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
102 long stopTime = System.currentTimeMillis();
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
103
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
104 if (log.isDebugEnabled()) {
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
105 log.debug("Loading locations took " +
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
106 (stopTime-startTime)/1000f + " secs.");
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 }
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
109 return fas;
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 }
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 }
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org