Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/GaugeOverviewInfoServiceImpl.java @ 4043:eb5564662e19
Cosmetics, documentation.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 05 Oct 2012 15:36:42 +0200 |
parents | 22cd60315e08 |
children |
rev | line source |
---|---|
3713
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.server; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
2 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
3 import java.util.ArrayList; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
4 import javax.xml.xpath.XPathConstants; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
5 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
6 import org.apache.log4j.Logger; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
7 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
8 import org.w3c.dom.Document; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
9 import org.w3c.dom.Element; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
10 import org.w3c.dom.NodeList; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
11 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.artifacts.common.utils.XMLUtils; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.artifacts.httpclient.http.HttpClient; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
17 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
18 import de.intevation.flys.client.client.services.GaugeOverviewInfoService; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.flys.client.shared.exceptions.ServerException; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.flys.client.shared.model.DefaultGaugeInfo; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.flys.client.shared.model.DefaultRiverInfo; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.flys.client.shared.model.GaugeInfo; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
23 import de.intevation.flys.client.shared.model.RiverInfo; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
24 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
25 /** |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
26 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
27 */ |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
28 public class GaugeOverviewInfoServiceImpl |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
29 extends RemoteServiceServlet |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
30 implements GaugeOverviewInfoService |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
31 { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
32 private static final Logger logger = |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
33 Logger.getLogger(GaugeOverviewInfoServiceImpl.class); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
34 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
35 public static final String ERROR_NO_RIVERINFO_FOUND = |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
36 "error_no_gaugeoverviewinfo_found"; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
37 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
38 private static final String XPATH_RIVER = "/art:gauge-info/art:river"; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
39 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
40 private static final String XPATH_GAUGES = "/art:gauge-info/art:gauges/art:gauge"; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
41 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
42 public RiverInfo getRiverInfo(String river) throws ServerException { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
43 logger.info("RiverInfoServiceImpl.getRiverInfo"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
44 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
45 String url = getServletContext().getInitParameter("server-url"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
46 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
47 Document doc = XMLUtils.newDocument(); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
48 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
49 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
50 doc, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
51 ArtifactNamespaceContext.NAMESPACE_URI, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
52 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
53 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
54 Element riverele = ec.create("river"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
55 riverele.setTextContent(river); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
56 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
57 doc.appendChild(riverele); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
58 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
59 HttpClient client = new HttpClientImpl(url); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
60 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
61 try { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
62 Document result = client.callService(url, "gaugeoverviewinfo", doc); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
63 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
64 Element riverresp = (Element) XMLUtils.xpath( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
65 result, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
66 XPATH_RIVER, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
67 XPathConstants.NODE, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
68 ArtifactNamespaceContext.INSTANCE); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
69 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
70 String rname = riverresp.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
71 ArtifactNamespaceContext.NAMESPACE_URI, "name"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
72 String rkmup = riverresp.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
73 ArtifactNamespaceContext.NAMESPACE_URI, "kmup"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
74 String rstart = riverresp.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
75 ArtifactNamespaceContext.NAMESPACE_URI, "start"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
76 String rend = riverresp.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
77 ArtifactNamespaceContext.NAMESPACE_URI, "end"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
78 String rwstunit = riverresp.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
79 ArtifactNamespaceContext.NAMESPACE_URI, "wstunit"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
80 String rminq = riverresp.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
81 ArtifactNamespaceContext.NAMESPACE_URI, "minq"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
82 String rmaxq = riverresp.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
83 ArtifactNamespaceContext.NAMESPACE_URI, "maxq"); |
3847
f3b821735e39
Calculate the info url via i18n
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3843
diff
changeset
|
84 String rofficial = riverresp.getAttributeNS( |
f3b821735e39
Calculate the info url via i18n
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3843
diff
changeset
|
85 ArtifactNamespaceContext.NAMESPACE_URI, "official"); |
3713
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
86 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
87 logger.debug("River is " + rname); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
88 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
89 boolean kmup = rkmup.equalsIgnoreCase("true"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
90 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
91 NodeList gaugenodes = (NodeList) XMLUtils.xpath( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
92 result, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
93 XPATH_GAUGES, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
94 XPathConstants.NODESET, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
95 ArtifactNamespaceContext.INSTANCE); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
96 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
97 int num = gaugenodes == null ? 0 : gaugenodes.getLength(); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
98 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
99 ArrayList<GaugeInfo> gauges = new ArrayList<GaugeInfo>(num); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
100 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
101 if (num == 0) { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
102 logger.warn("No gauge info found."); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
103 } |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
104 else { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
105 logger.debug("Found " + num + " gauges."); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
106 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
107 for (int i = 0; i < num; i++) { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
108 Element gaugeele = (Element)gaugenodes.item(i); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
109 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
110 String gname = gaugeele.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
111 ArtifactNamespaceContext.NAMESPACE_URI, "name"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
112 String gstart = gaugeele.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
113 ArtifactNamespaceContext.NAMESPACE_URI, "start"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
114 String gend = gaugeele.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
115 ArtifactNamespaceContext.NAMESPACE_URI, "end"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
116 String gdatum = gaugeele.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
117 ArtifactNamespaceContext.NAMESPACE_URI, "datum"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
118 String gaeo = gaugeele.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
119 ArtifactNamespaceContext.NAMESPACE_URI, "aeo"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
120 String gminq = gaugeele.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
121 ArtifactNamespaceContext.NAMESPACE_URI, "minq"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
122 String gminw = gaugeele.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
123 ArtifactNamespaceContext.NAMESPACE_URI, "minw"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
124 String gmaxq = gaugeele.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
125 ArtifactNamespaceContext.NAMESPACE_URI, "maxq"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
126 String gmaxw = gaugeele.getAttributeNS( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
127 ArtifactNamespaceContext.NAMESPACE_URI, "maxw"); |
3719
e82acd5c86f7
Merged revisions 5495-5496,5509,5514-5515,5521-5526 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3713
diff
changeset
|
128 String gstation = gaugeele.getAttributeNS( |
e82acd5c86f7
Merged revisions 5495-5496,5509,5514-5515,5521-5526 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3713
diff
changeset
|
129 ArtifactNamespaceContext.NAMESPACE_URI, "station"); |
3847
f3b821735e39
Calculate the info url via i18n
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3843
diff
changeset
|
130 String gofficial = gaugeele.getAttributeNS( |
3843
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
131 ArtifactNamespaceContext.NAMESPACE_URI, "official"); |
3713
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
132 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
133 logger.debug("Found gauge with name " + gname); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
134 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
135 GaugeInfo gaugeinfo = new DefaultGaugeInfo( |
3864
c434dd2e84cf
Add the river name to the gaugeinfo
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3847
diff
changeset
|
136 rname, |
3713
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
137 gname, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
138 kmup, |
3719
e82acd5c86f7
Merged revisions 5495-5496,5509,5514-5515,5521-5526 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3713
diff
changeset
|
139 parseDouble(gstation), |
3713
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
140 parseDouble(gstart), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
141 parseDouble(gend), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
142 parseDouble(gdatum), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
143 parseDouble(gaeo), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
144 parseDouble(gminq), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
145 parseDouble(gmaxq), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
146 parseDouble(gminw), |
3719
e82acd5c86f7
Merged revisions 5495-5496,5509,5514-5515,5521-5526 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3713
diff
changeset
|
147 parseDouble(gmaxw), |
3838
70976b711b7e
Extend RiverInfo and GaugeInfo to store also the info http url
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3831
diff
changeset
|
148 rwstunit, |
3843
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
149 parseLong(gofficial) |
3713
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
150 ); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
151 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
152 gauges.add(gaugeinfo); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
153 } |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
154 } |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
155 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
156 RiverInfo riverinfo = new DefaultRiverInfo( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
157 rname, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
158 kmup, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
159 parseDouble(rstart), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
160 parseDouble(rend), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
161 rwstunit, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
162 parseDouble(rminq), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
163 parseDouble(rmaxq), |
3847
f3b821735e39
Calculate the info url via i18n
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3843
diff
changeset
|
164 parseLong(rofficial), |
3713
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
165 gauges); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
166 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
167 logger.debug("Finished RiverInfoService."); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
168 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
169 return riverinfo; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
170 } |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
171 catch (ConnectionException ce) { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
172 logger.error(ce, ce); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
173 } |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
174 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
175 logger.warn("No gauge found"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
176 throw new ServerException(ERROR_NO_RIVERINFO_FOUND); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
177 } |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
178 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
179 /** |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
180 * Avoids NullPointerException when parsing double value |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
181 */ |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
182 private Double parseDouble(String value) { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
183 if (value == null || value.isEmpty()) { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
184 return null; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
185 } |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
186 try { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
187 return Double.valueOf(value); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
188 } |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
189 catch(NumberFormatException e) { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
190 logger.error(e, e); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
191 return null; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
192 } |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
193 } |
3843
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
194 |
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
195 private Long parseLong(String value) { |
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
196 if (value == null || value.isEmpty()) { |
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
197 return null; |
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
198 } |
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
199 try { |
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
200 return Long.valueOf(value); |
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
201 } |
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
202 catch(NumberFormatException e) { |
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
203 logger.error(e, e); |
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
204 return null; |
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
205 } |
8e169e4e1b57
Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3838
diff
changeset
|
206 } |
3713
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
207 } |