Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java @ 1002:db86c665ab6e
Datacage: Pass global context to datacage if calls come from backend listener.
flys-artifacts/trunk@2442 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 01 Aug 2011 16:34:48 +0000 |
parents | a63d79107289 |
children | b1ed0ec0236f |
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 |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 /** The logger used in this service.*/ |
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 /** |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
170 * This method build an Element for a distance info. |
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 ec The ElementCreator. |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
173 * @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
|
174 * |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
175 * @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
|
176 */ |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 DistanceFilter filter |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
181 ) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
182 Position pos = anno.getPosition(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
183 Range range = anno.getRange(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
184 Attribute attr = anno.getAttribute(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
185 Edge edge = anno.getEdge(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
186 BigDecimal a = range.getA(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
187 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
|
188 |
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
|
189 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
|
190 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
|
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 |
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 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
|
194 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
|
195 } |
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
|
196 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
197 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
|
198 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
199 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
|
200 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
201 String riverSide = attr.getValue(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
202 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
203 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
|
204 distance.setAttribute("riverside", riverSide); |
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 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
207 if (a != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
208 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
|
209 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
210 if (b != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
211 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
|
212 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
213 if (edge != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
214 BigDecimal bottom = edge.getBottom(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
215 BigDecimal top = edge.getTop(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
216 if (bottom != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
217 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
|
218 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
219 if (top != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
220 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
|
221 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
222 } |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
223 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
224 return distance; |
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 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
227 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |