annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/LocationProvider.java @ 8870:c26fb37899ca

Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui. Also using now the localization info from the server instead of localizing the modules again on the client side.
author gernotbelger
date Wed, 07 Feb 2018 11:59:13 +0100
parents af13ceeba52a
children 0a5239a1e46e
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
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 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
15
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4010
diff changeset
16 import org.dive4elements.river.model.Annotation;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4010
diff changeset
17 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
18
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4010
diff changeset
19 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
20
4010
efb067ab2ca4 Added TODOs for issue880.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
21
efb067ab2ca4 Added TODOs for issue880.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
22 /** 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
23 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
24
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
25 private static final Logger log =
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
26 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
27
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
28
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 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
30
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
31 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
32
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 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
35 }
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
37 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
38
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
39 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
40
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
41 FastAnnotations.Annotation an = fas.findByKm(km);
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
42
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
43 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
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
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
46 public static FastAnnotations getAnnotations(String river) {
2289
fe3ea0f16098 Small bugfix for fetching river annotations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2144
diff changeset
47 return getAnnotations(river, Double.MAX_VALUE);
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
48 }
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 protected static FastAnnotations getAnnotations(String river, double km) {
4010
efb067ab2ca4 Added TODOs for issue880.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
51 // 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
52
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 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
54
2127
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 (cache == null) {
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
56 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
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
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
59 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
60
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
61 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
62
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
63 if (element != null) {
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
64 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
65 }
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
66
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
67 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
68
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
69 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
70
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
71 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
72 }
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
74 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
75 String river,
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
76 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
77 ) {
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
78 if (km != Double.MAX_VALUE) {
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
79 // XXX Fake it by using a standard Annotation.
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
80
2127
0c7847b8e85e Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2063
diff changeset
81 Annotation annotation =
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
82 AnnotationsFactory.getAnnotation(river, km);
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
83
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 if (annotation != null) {
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
85 FastAnnotations.Annotation fa =
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
86 new FastAnnotations.Annotation(
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
87 km, Double.NaN,
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
88 annotation.getPosition().getValue(), null, null,
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
89 Double.NaN, Double.NaN);
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
90 return new FastAnnotations(
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
91 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
92 }
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
93
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
94 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
95 }
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
97 long startTime = System.currentTimeMillis();
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
98
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
99 FastAnnotations fas = new FastAnnotations(river);
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
100
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
101 long stopTime = System.currentTimeMillis();
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
102
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
103 if (log.isDebugEnabled()) {
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
104 log.debug("Loading locations took " +
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
105 (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
106 }
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107
2144
a4bdf7d8527e Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2127
diff changeset
108 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
109 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org