Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java @ 1178:1b432c260e97
Enabled the FloodMapState to fetch waterlevel data from external Artifact.
flys-artifacts/trunk@2764 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 15 Sep 2011 15:36:05 +0000 |
parents | b1ed0ec0236f |
children | 26e19cdaed5e |
rev | line source |
---|---|
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.services; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.math.BigDecimal; |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
4 import java.util.Iterator; |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import org.apache.log4j.Logger; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import org.w3c.dom.Document; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import org.w3c.dom.Element; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.artifacts.CallMeta; |
966
a63d79107289
Adjusted services to implement changed signature.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
922
diff
changeset
|
12 import de.intevation.artifacts.GlobalContext; |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.artifacts.common.utils.XMLUtils; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.artifactdatabase.DefaultService; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 |
316
4aa078e28cfd
Bugfix: repaired broken imports of the session holder.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
314
diff
changeset
|
19 import de.intevation.flys.backend.SessionHolder; |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.flys.model.Annotation; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.flys.model.Attribute; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.flys.model.Position; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 import de.intevation.flys.model.Range; |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
24 import de.intevation.flys.model.Edge; |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 import de.intevation.flys.artifacts.model.AnnotationsFactory; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
28 import org.hibernate.Session; |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
30 import de.intevation.flys.artifacts.cache.CacheFactory; |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
31 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
32 import net.sf.ehcache.Cache; |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
33 |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 /** |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 * This service provides information about distances of a specified river. |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 * |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 */ |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 public class DistanceInfoService extends DefaultService { |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
41 private static enum DistanceFilter { |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
42 NONE, LOCATIONS, DISTANCES |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
43 } |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
44 |
1070
b1ed0ec0236f
Smaller Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
966
diff
changeset
|
45 /** The logger used in this service. */ |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 private static Logger logger = Logger.getLogger(DistanceInfoService.class); |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
48 public static final String CACHE_NAME = "service-distanceinfo"; |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
49 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
50 public static final String RIVER_XPATH = "/art:river/text()"; |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
51 |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
52 public static final String FILTER_XPATH = "/art:river/art:filter/text()"; |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
53 |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 /** |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 * The default constructor. |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 */ |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 public DistanceInfoService() { |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 |
966
a63d79107289
Adjusted services to implement changed signature.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
922
diff
changeset
|
62 @Override |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 public Document process( |
966
a63d79107289
Adjusted services to implement changed signature.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
922
diff
changeset
|
64 Document data, |
a63d79107289
Adjusted services to implement changed signature.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
922
diff
changeset
|
65 GlobalContext globalContext, |
a63d79107289
Adjusted services to implement changed signature.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
922
diff
changeset
|
66 CallMeta callMeta |
a63d79107289
Adjusted services to implement changed signature.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
922
diff
changeset
|
67 ) { |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 logger.debug("DistanceInfoService.process"); |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 String river = XMLUtils.xpathString( |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
71 data, RIVER_XPATH, ArtifactNamespaceContext.INSTANCE); |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
73 String filter = XMLUtils.xpathString( |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
74 data, FILTER_XPATH, ArtifactNamespaceContext.INSTANCE); |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
75 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
76 if (river == null || (river = river.trim()).length() == 0) { |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 logger.warn("No river specified. Cannot return distance info!"); |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
78 return XMLUtils.newDocument(); |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 logger.debug("Search distances for river: " + river); |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
83 Cache cache = CacheFactory.getCache(CACHE_NAME); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
84 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
85 if (cache == null) { |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
86 logger.debug("no cache configured for distance info"); |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
87 return getUncached(river, filter); |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
88 } |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
89 |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
90 |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
91 String key = getCacheKey(river, filter); |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
92 |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
93 net.sf.ehcache.Element element = cache.get(key); |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
94 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
95 if (element != null) { |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
96 logger.debug("distance info found in cache"); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
97 return (Document)element.getValue(); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
98 } |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
99 |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
100 Document result = getUncached(river, filter); |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
101 |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
102 element = new net.sf.ehcache.Element(key, result); |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
103 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
104 logger.debug("store distance info found into cache"); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
105 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
106 cache.put(element); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
107 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
108 return result; |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
109 } |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
110 |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
111 |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
112 protected String getCacheKey(String river, String filtertype) { |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
113 return filtertype != null && filtertype.length() > 0 |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
114 ? river + "_" + filtertype |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
115 : river; |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
116 } |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
117 |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
118 |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
119 protected Document getUncached(String river, String filtertype) { |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
120 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
121 Document result = XMLUtils.newDocument(); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
122 |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
123 Session session = SessionHolder.acquire(); |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
124 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
125 try { |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
126 Iterator<Annotation> iter = |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
127 AnnotationsFactory.getAnnotationsIterator(river); |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
128 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
129 Element all = result.createElement("distances"); |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
130 |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
131 DistanceFilter filter = getDistanceFilter(filtertype); |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
132 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
133 while (iter.hasNext()) { |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
134 Annotation a = iter.next(); |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
135 Element distance = buildDistanceNode(result, a, filter); |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
136 |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
137 if (distance != null) { |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
138 all.appendChild(distance); |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
139 } |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
140 } |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
141 |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
142 result.appendChild(all); |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
143 } |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
144 finally { |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
145 session.close(); |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
146 SessionHolder.release(); |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
147 } |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
148 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
149 return result; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
150 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
151 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
152 |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
153 protected static DistanceFilter getDistanceFilter(String type) { |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
154 if (type.equals("locations")) { |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
155 logger.debug("Found 'location' filter."); |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
156 return DistanceFilter.LOCATIONS; |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
157 } |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
158 else if (type.equals("distances")) { |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
159 logger.debug("Found 'distances' filter."); |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
160 return DistanceFilter.DISTANCES; |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
161 } |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
162 |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
163 logger.debug("Do not use any filter at all."); |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
164 |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
165 return DistanceFilter.NONE; |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
166 } |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
167 |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
168 |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
169 /** |
1070
b1ed0ec0236f
Smaller Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
966
diff
changeset
|
170 * Builds an Element for a distance info. |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
171 * |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
172 * @param anno The Annotation that provides information about the distance. |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
173 * |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
174 * @return an Element that contains information about a distance. |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
175 */ |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
176 protected static Element buildDistanceNode( |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
177 Document document, |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
178 Annotation anno, |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
179 DistanceFilter filter |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
180 ) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
181 Position pos = anno.getPosition(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
182 Range range = anno.getRange(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
183 Attribute attr = anno.getAttribute(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
184 Edge edge = anno.getEdge(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
185 BigDecimal a = range.getA(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
186 BigDecimal b = range.getB(); |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
187 |
922
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
188 if (b == null && filter == DistanceFilter.DISTANCES) { |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
189 return null; |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
190 } |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
191 |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
192 if (b != null && filter == DistanceFilter.LOCATIONS) { |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
193 return null; |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
194 } |
95356252c309
Added the option to call the distance info service with a filter to fetch locations or distances only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
704
diff
changeset
|
195 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
196 Element distance = document.createElement("distance"); |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
197 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
198 distance.setAttribute("description", pos.getValue()); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
199 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
200 String riverSide = attr.getValue(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
201 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
202 if (riverSide != null && riverSide.length() > 0) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
203 distance.setAttribute("riverside", riverSide); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
204 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
205 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
206 if (a != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
207 distance.setAttribute("from", a.toString()); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
208 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
209 if (b != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
210 distance.setAttribute("to", b.toString()); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
211 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
212 if (edge != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
213 BigDecimal bottom = edge.getBottom(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
214 BigDecimal top = edge.getTop(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
215 if (bottom != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
216 distance.setAttribute("bottom", bottom.toString()); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
217 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
218 if (top != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
219 distance.setAttribute("top", top.toString()); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
220 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
221 } |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
222 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
223 return distance; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
224 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
225 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
226 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |