annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java @ 942:796c54058dc4

Added artifacts/states for WMS background an river axis and a configuration for the output-defaults. flys-artifacts/trunk@2351 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 18 Jul 2011 10:13:25 +0000
parents 95356252c309
children a63d79107289
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;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 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
14 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
15
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 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
17
316
4aa078e28cfd Bugfix: repaired broken imports of the session holder.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 314
diff changeset
18 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
19 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
20 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
21 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
22 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
23 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
24
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 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
26
314
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
27 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
28
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
29 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
30
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
31 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
32
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 /**
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 * 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
35 *
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 * @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
37 */
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 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
39
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
40 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
41 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
42 }
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
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 /** 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
45 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
46
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
47 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
48
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
49 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
50
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
51 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
52
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
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 * The default constructor.
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 */
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 public DistanceInfoService() {
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 }
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 public Document process(
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 Document data,
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 Object globalContext,
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 CallMeta callMeta)
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 {
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 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
67
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 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
69 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
70
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
71 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
72 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
73
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
74 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
75 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
76 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
77 }
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 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
80
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
81 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
82
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
83 if (cache == null) {
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
84 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
85 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
86 }
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
87
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
88
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
89 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
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 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
92
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
93 if (element != null) {
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
94 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
95 return (Document)element.getValue();
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
96 }
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
97
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
98 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
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 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
101
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
102 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
103
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
104 cache.put(element);
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 return result;
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
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
109
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 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
111 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
112 ? 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
113 : 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
114 }
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
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 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
118
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
119 Document result = XMLUtils.newDocument();
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
120
314
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
121 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
122
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
123 try {
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
124 Iterator<Annotation> iter =
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
125 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
126
686
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
127 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
128
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
129 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
130
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
131 while (iter.hasNext()) {
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
132 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
133 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
134
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 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
136 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
137 }
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 }
314
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
139
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
140 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
141 }
314
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
142 finally {
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
143 session.close();
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
144 SessionHolder.release();
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
145 }
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 return result;
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
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150
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
151 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
152 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
153 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
154 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
155 }
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 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
157 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
158 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
159 }
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
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 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
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 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
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
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
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167 /**
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 * 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
169 *
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 * @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
171 * @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
172 *
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 * @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
174 */
686
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
175 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
176 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
177 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
178 DistanceFilter filter
686
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
179 ) {
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
180 Position pos = anno.getPosition();
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
181 Range range = anno.getRange();
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
182 Attribute attr = anno.getAttribute();
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
183 Edge edge = anno.getEdge();
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
184 BigDecimal a = range.getA();
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
185 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
186
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
187 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
188 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
189 }
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 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
192 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
193 }
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
686
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
195 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
196
686
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
197 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
198
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
199 String riverSide = attr.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 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
202 distance.setAttribute("riverside", riverSide);
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
203 }
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 (a != null) {
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
206 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
207 }
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
208 if (b != null) {
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
209 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
210 }
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
211 if (edge != null) {
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
212 BigDecimal bottom = edge.getBottom();
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
213 BigDecimal top = edge.getTop();
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
214 if (bottom != null) {
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
215 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
216 }
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
217 if (top != null) {
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
218 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
219 }
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 644
diff changeset
220 }
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222 return distance;
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 }
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org