annotate flys-client/src/main/java/de/intevation/flys/client/server/GaugeOverviewInfoServiceImpl.java @ 3844:7a096ec98596

Open gauge tree fold for historicalq reference too flys-client/trunk@5561 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 21 Sep 2012 14:21:05 +0000
parents 8e169e4e1b57
children f3b821735e39
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");
3843
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
132 String gofficial = riverresp.getAttributeNS(
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
133 ArtifactNamespaceContext.NAMESPACE_URI, "official");
3713
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 logger.debug("Found gauge with name " + gname);
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
136
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
137 GaugeInfo gaugeinfo = new DefaultGaugeInfo(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
138 gname,
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
139 kmup,
3826
7a34af684ed4 Add station info to the gauges
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3713
diff changeset
140 parseDouble(gstation),
3713
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
141 parseDouble(gstart),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
142 parseDouble(gend),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
143 parseDouble(gdatum),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
144 parseDouble(gaeo),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
145 parseDouble(gminq),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
146 parseDouble(gmaxq),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
147 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
148 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
149 rwstunit,
3843
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
150 ginfourl,
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
151 parseLong(gofficial)
3713
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 gauges.add(gaugeinfo);
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 }
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
157
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
158 RiverInfo riverinfo = new DefaultRiverInfo(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
159 rname,
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
160 kmup,
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
161 parseDouble(rstart),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
162 parseDouble(rend),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
163 rwstunit,
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
164 parseDouble(rminq),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
165 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
166 rinfourl,
3713
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
167 gauges);
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 logger.debug("Finished RiverInfoService.");
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 return riverinfo;
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 catch (ConnectionException ce) {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
174 logger.error(ce, ce);
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
175 }
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 logger.warn("No gauge found");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
178 throw new ServerException(ERROR_NO_RIVERINFO_FOUND);
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
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 * Avoids NullPointerException when parsing double value
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
183 */
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
184 private Double parseDouble(String value) {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
185 if (value == null || value.isEmpty()) {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
186 return null;
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 try {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
189 return Double.valueOf(value);
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
190 }
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
191 catch(NumberFormatException e) {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
192 logger.error(e, e);
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
193 return null;
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
194 }
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
195 }
3843
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
196
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
197 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
198 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
199 return null;
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
200 }
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
201 try {
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
202 return Long.valueOf(value);
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
203 }
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
204 catch(NumberFormatException e) {
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
205 logger.error(e, e);
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
206 return null;
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
207 }
8e169e4e1b57 Add the official gauge number to the GaugeInfo class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3838
diff changeset
208 }
3713
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
209 }

http://dive4elements.wald.intevation.org