Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/GaugeOverviewInfoServiceImpl.java @ 3842:44c1beb78ad1
Move GaugeTree to its own java file
flys-client/trunk@5557 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 21 Sep 2012 13:44:56 +0000 |
parents | 70976b711b7e |
children | 8e169e4e1b57 |
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"); |
3838
70976b711b7e
Extend RiverInfo and GaugeInfo to store also the info http url
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3831
diff
changeset
|
84 String rinfourl = riverresp.getAttributeNS( |
70976b711b7e
Extend RiverInfo and GaugeInfo to store also the info http url
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3831
diff
changeset
|
85 ArtifactNamespaceContext.NAMESPACE_URI, "info-url"); |
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"); |
3826
7a34af684ed4
Add station info to the gauges
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3713
diff
changeset
|
128 String gstation = gaugeele.getAttributeNS( |
7a34af684ed4
Add station info to the gauges
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3713
diff
changeset
|
129 ArtifactNamespaceContext.NAMESPACE_URI, "station"); |
3838
70976b711b7e
Extend RiverInfo and GaugeInfo to store also the info http url
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3831
diff
changeset
|
130 String ginfourl = riverresp.getAttributeNS( |
70976b711b7e
Extend RiverInfo and GaugeInfo to store also the info http url
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3831
diff
changeset
|
131 ArtifactNamespaceContext.NAMESPACE_URI, "info-url"); |
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( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
136 gname, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
137 kmup, |
3826
7a34af684ed4
Add station info to the gauges
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3713
diff
changeset
|
138 parseDouble(gstation), |
3713
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
139 parseDouble(gstart), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
140 parseDouble(gend), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
141 parseDouble(gdatum), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
142 parseDouble(gaeo), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
143 parseDouble(gminq), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
144 parseDouble(gmaxq), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
145 parseDouble(gminw), |
3831
dc505433173f
Use the wstunit from the river as unit for the Pegelnullpunkt
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3826
diff
changeset
|
146 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
|
147 rwstunit, |
70976b711b7e
Extend RiverInfo and GaugeInfo to store also the info http url
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3831
diff
changeset
|
148 ginfourl |
3713
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
149 ); |
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 gauges.add(gaugeinfo); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
152 } |
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 RiverInfo riverinfo = new DefaultRiverInfo( |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
156 rname, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
157 kmup, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
158 parseDouble(rstart), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
159 parseDouble(rend), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
160 rwstunit, |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
161 parseDouble(rminq), |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
162 parseDouble(rmaxq), |
3838
70976b711b7e
Extend RiverInfo and GaugeInfo to store also the info http url
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3831
diff
changeset
|
163 rinfourl, |
3713
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
164 gauges); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
165 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
166 logger.debug("Finished RiverInfoService."); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
167 |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
168 return riverinfo; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
169 } |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
170 catch (ConnectionException ce) { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
171 logger.error(ce, ce); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
172 } |
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 logger.warn("No gauge found"); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
175 throw new ServerException(ERROR_NO_RIVERINFO_FOUND); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
176 } |
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 * Avoids NullPointerException when parsing double value |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
180 */ |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
181 private Double parseDouble(String value) { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
182 if (value == null || value.isEmpty()) { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
183 return null; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
184 } |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
185 try { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
186 return Double.valueOf(value); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
187 } |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
188 catch(NumberFormatException e) { |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
189 logger.error(e, e); |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
190 return null; |
79ad33f41977
Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
191 } |
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 } |