Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java @ 2101:d54518bac974
Fix flys/issue439, made annotations available via datacage.
flys-artifacts/trunk@3655 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 11 Jan 2012 14:36:19 +0000 |
parents | 26e19cdaed5e |
children | e92bc9b0ca1d |
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.flys.model.Annotation; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 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
|
19 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
|
20 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
|
21 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
|
22 |
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.artifacts.model.AnnotationsFactory; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
25 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
|
26 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
27 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
|
28 |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 /** |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 * 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
|
31 * |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 * @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
|
33 */ |
1631
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
34 public class DistanceInfoService extends FLYSService { |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 |
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
|
36 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
|
37 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
|
38 } |
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
|
39 |
1070
b1ed0ec0236f
Smaller Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
966
diff
changeset
|
40 /** 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
|
41 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
|
42 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
43 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
|
44 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
45 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
|
46 |
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
|
47 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
|
48 |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 /** |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 * The default constructor. |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 */ |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 public DistanceInfoService() { |
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 |
966
a63d79107289
Adjusted services to implement changed signature.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
922
diff
changeset
|
57 @Override |
1631
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
58 public Document doProcess( |
966
a63d79107289
Adjusted services to implement changed signature.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
922
diff
changeset
|
59 Document data, |
a63d79107289
Adjusted services to implement changed signature.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
922
diff
changeset
|
60 GlobalContext globalContext, |
a63d79107289
Adjusted services to implement changed signature.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
922
diff
changeset
|
61 CallMeta callMeta |
a63d79107289
Adjusted services to implement changed signature.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
922
diff
changeset
|
62 ) { |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 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
|
64 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 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
|
66 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
|
67 |
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
|
68 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
|
69 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
|
70 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 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
|
77 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
78 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
|
79 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
80 if (cache == null) { |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
81 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
|
82 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
|
83 } |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
84 |
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
|
85 |
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
|
86 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
|
87 |
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
|
88 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
|
89 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
90 if (element != null) { |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
91 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
|
92 return (Document)element.getValue(); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
93 } |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
94 |
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
|
95 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
|
96 |
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
|
97 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
|
98 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
99 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
|
100 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
101 cache.put(element); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
102 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
103 return result; |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
104 } |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
105 |
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
|
106 |
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
|
107 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
|
108 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
|
109 ? 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
|
110 : 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
|
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 |
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 |
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 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
|
115 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
116 Document result = XMLUtils.newDocument(); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
117 |
1631
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
118 Iterator<Annotation> iter = |
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
119 AnnotationsFactory.getAnnotationsIterator(river); |
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
|
120 |
1631
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
121 Element all = result.createElement("distances"); |
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
|
122 |
1631
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
123 DistanceFilter filter = getDistanceFilter(filtertype); |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
124 |
1631
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
125 while (iter.hasNext()) { |
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
126 Annotation a = iter.next(); |
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
127 Element distance = buildDistanceNode(result, a, filter); |
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
128 |
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
129 if (distance != null) { |
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
130 all.appendChild(distance); |
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
131 } |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
132 } |
1631
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
133 |
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1070
diff
changeset
|
134 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
|
135 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
136 return result; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
137 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
138 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
139 |
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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 } |
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
|
145 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
|
146 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
|
147 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
|
148 } |
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
|
149 |
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
|
150 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
|
151 |
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
|
152 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
|
153 } |
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 |
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 |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
156 /** |
1070
b1ed0ec0236f
Smaller Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
966
diff
changeset
|
157 * 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
|
158 * |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
159 * @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
|
160 * |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
161 * @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
|
162 */ |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 DistanceFilter filter |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
167 ) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
168 Position pos = anno.getPosition(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
169 Range range = anno.getRange(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
170 Attribute attr = anno.getAttribute(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
171 Edge edge = anno.getEdge(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
172 BigDecimal a = range.getA(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
173 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
|
174 |
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
|
175 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
|
176 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
|
177 } |
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 |
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 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
|
180 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
|
181 } |
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
|
182 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
183 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
|
184 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
185 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
|
186 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
187 String riverSide = attr.getValue(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
188 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
189 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
|
190 distance.setAttribute("riverside", riverSide); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
191 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
192 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
193 if (a != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
194 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
|
195 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
196 if (b != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
197 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
|
198 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
199 if (edge != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
200 BigDecimal bottom = edge.getBottom(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
201 BigDecimal top = edge.getTop(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
202 if (bottom != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
203 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
|
204 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
205 if (top != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
206 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
|
207 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
208 } |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
209 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
210 return distance; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
211 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
212 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
213 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |