Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/LocationProvider.java @ 4369:8ddab49ff297
Added i18n string for sediment load output tab title.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Fri, 02 Nov 2012 14:44:11 +0100 |
parents | efb067ab2ca4 |
children |
rev | line source |
---|---|
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 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
|
4 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
|
5 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import org.apache.log4j.Logger; |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import de.intevation.flys.model.Annotation; |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
9 import de.intevation.flys.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
|
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 de.intevation.flys.artifacts.cache.CacheFactory; |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
4010
efb067ab2ca4
Added TODOs for issue880.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3317
diff
changeset
|
13 |
efb067ab2ca4
Added TODOs for issue880.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3317
diff
changeset
|
14 /** 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
|
15 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
|
16 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
17 private static final Logger log = |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
18 Logger.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
|
19 |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
20 |
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 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
|
22 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
23 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
|
24 |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 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
|
27 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
29 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
|
30 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
31 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
|
32 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
33 FastAnnotations.Annotation an = fas.findByKm(km); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
34 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
35 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
|
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 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
38 public static FastAnnotations getAnnotations(String river) { |
2289
fe3ea0f16098
Small bugfix for fetching river annotations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2144
diff
changeset
|
39 return getAnnotations(river, Double.MAX_VALUE); |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
40 } |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
41 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
42 protected static FastAnnotations getAnnotations(String river, double km) { |
4010
efb067ab2ca4
Added TODOs for issue880.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3317
diff
changeset
|
43 // 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
|
44 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 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
|
46 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
47 if (cache == null) { |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
48 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
|
49 } |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
50 |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
51 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
|
52 |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
53 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
|
54 |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
55 if (element != null) { |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
56 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
|
57 } |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
58 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
59 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
|
60 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
61 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
|
62 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
63 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
|
64 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
66 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
|
67 String river, |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
68 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
|
69 ) { |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
70 if (km != Double.MAX_VALUE) { |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
71 // XXX Fake it by using a standard Annotation. |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
72 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
73 Annotation annotation = |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
74 AnnotationsFactory.getAnnotation(river, km); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
75 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
76 if (annotation != null) { |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
77 FastAnnotations.Annotation fa = |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
78 new FastAnnotations.Annotation( |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
79 km, Double.NaN, |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
80 annotation.getPosition().getValue(), null, null, |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
81 Double.NaN, Double.NaN); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
82 return new FastAnnotations( |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
83 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
|
84 } |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
85 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
86 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
|
87 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
89 long startTime = System.currentTimeMillis(); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
90 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
91 FastAnnotations fas = new FastAnnotations(river); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
92 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
93 long stopTime = System.currentTimeMillis(); |
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 if (log.isDebugEnabled()) { |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
96 log.debug("Loading locations took " + |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
97 (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
|
98 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
100 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
|
101 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |