annotate flys-client/src/main/java/de/intevation/flys/client/server/GaugeOverviewInfoServiceImpl.java @ 3836:06c76de19b51

Fix NullPointerException Check if array is null before accessing its length property. flys-client/trunk@5545 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 21 Sep 2012 07:59:25 +0000
parents dc505433173f
children 70976b711b7e
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");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
84
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
85 logger.debug("River is " + rname);
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 boolean kmup = rkmup.equalsIgnoreCase("true");
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 NodeList gaugenodes = (NodeList) XMLUtils.xpath(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
90 result,
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
91 XPATH_GAUGES,
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
92 XPathConstants.NODESET,
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
93 ArtifactNamespaceContext.INSTANCE);
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
94
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
95 int num = gaugenodes == null ? 0 : gaugenodes.getLength();
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 ArrayList<GaugeInfo> gauges = new ArrayList<GaugeInfo>(num);
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 if (num == 0) {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
100 logger.warn("No gauge info found.");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
101 }
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
102 else {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
103 logger.debug("Found " + num + " gauges.");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
104
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
105 for (int i = 0; i < num; i++) {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
106 Element gaugeele = (Element)gaugenodes.item(i);
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
107
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
108 String gname = gaugeele.getAttributeNS(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
109 ArtifactNamespaceContext.NAMESPACE_URI, "name");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
110 String gstart = gaugeele.getAttributeNS(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
111 ArtifactNamespaceContext.NAMESPACE_URI, "start");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
112 String gend = gaugeele.getAttributeNS(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
113 ArtifactNamespaceContext.NAMESPACE_URI, "end");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
114 String gdatum = gaugeele.getAttributeNS(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
115 ArtifactNamespaceContext.NAMESPACE_URI, "datum");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
116 String gaeo = gaugeele.getAttributeNS(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
117 ArtifactNamespaceContext.NAMESPACE_URI, "aeo");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
118 String gminq = gaugeele.getAttributeNS(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
119 ArtifactNamespaceContext.NAMESPACE_URI, "minq");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
120 String gminw = gaugeele.getAttributeNS(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
121 ArtifactNamespaceContext.NAMESPACE_URI, "minw");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
122 String gmaxq = gaugeele.getAttributeNS(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
123 ArtifactNamespaceContext.NAMESPACE_URI, "maxq");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
124 String gmaxw = gaugeele.getAttributeNS(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
125 ArtifactNamespaceContext.NAMESPACE_URI, "maxw");
3826
7a34af684ed4 Add station info to the gauges
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3713
diff changeset
126 String gstation = gaugeele.getAttributeNS(
7a34af684ed4 Add station info to the gauges
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3713
diff changeset
127 ArtifactNamespaceContext.NAMESPACE_URI, "station");
3713
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
128
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
129 logger.debug("Found gauge with name " + gname);
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
130
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
131 GaugeInfo gaugeinfo = new DefaultGaugeInfo(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
132 gname,
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
133 kmup,
3826
7a34af684ed4 Add station info to the gauges
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3713
diff changeset
134 parseDouble(gstation),
3713
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
135 parseDouble(gstart),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
136 parseDouble(gend),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
137 parseDouble(gdatum),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
138 parseDouble(gaeo),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
139 parseDouble(gminq),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
140 parseDouble(gmaxq),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
141 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
142 parseDouble(gmaxw),
dc505433173f Use the wstunit from the river as unit for the Pegelnullpunkt
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3826
diff changeset
143 rwstunit
3713
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
144 );
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
145
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
146 gauges.add(gaugeinfo);
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
147 }
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
148 }
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 RiverInfo riverinfo = new DefaultRiverInfo(
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
151 rname,
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
152 kmup,
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
153 parseDouble(rstart),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
154 parseDouble(rend),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
155 rwstunit,
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
156 parseDouble(rminq),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
157 parseDouble(rmaxq),
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
158 gauges);
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
159
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
160 logger.debug("Finished RiverInfoService.");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
161
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
162 return riverinfo;
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
163 }
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
164 catch (ConnectionException ce) {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
165 logger.error(ce, ce);
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
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
168 logger.warn("No gauge found");
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
169 throw new ServerException(ERROR_NO_RIVERINFO_FOUND);
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
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 * Avoids NullPointerException when parsing double value
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 private Double parseDouble(String value) {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
176 if (value == null || value.isEmpty()) {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
177 return null;
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 try {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
180 return Double.valueOf(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 catch(NumberFormatException e) {
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
183 logger.error(e, e);
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 }
79ad33f41977 Implement a gauge service
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
187 }

http://dive4elements.wald.intevation.org