Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/WQInfoServiceImpl.java @ 5785:d38004f0c52f
Datacage: Always clone XML template for builders. If the first is not cloned they get interlinked somehow. Feels like a bug in Java's DOM implementation.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Mon, 22 Apr 2013 17:01:17 +0200 |
parents | 8fce35702908 |
children |
rev | line source |
---|---|
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.server; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 import java.util.ArrayList; |
5567
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
4 import java.util.Arrays; |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
5 import java.util.Comparator; |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 import java.util.List; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 import javax.xml.xpath.XPathConstants; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 import org.w3c.dom.Document; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 import org.w3c.dom.Element; |
5596
8fce35702908
Rolled XPath replacement back for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5586
diff
changeset
|
12 import org.w3c.dom.Node; |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 import org.w3c.dom.NodeList; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
245
diff
changeset
|
15 import org.apache.log4j.Logger; |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
245
diff
changeset
|
16 |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.artifacts.common.utils.XMLUtils; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 import de.intevation.artifacts.httpclient.http.HttpClient; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 import de.intevation.flys.client.shared.exceptions.ServerException; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 import de.intevation.flys.client.client.services.WQInfoService; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 import de.intevation.flys.client.shared.model.WQInfoObject; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 import de.intevation.flys.client.shared.model.WQInfoObjectImpl; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 /** |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 */ |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 public class WQInfoServiceImpl |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 extends RemoteServiceServlet |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 implements WQInfoService |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
245
diff
changeset
|
39 private static final Logger logger = |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
245
diff
changeset
|
40 Logger.getLogger(WQInfoServiceImpl.class); |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
245
diff
changeset
|
41 |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
42 public static final String ERROR_NO_WQINFO_FOUND = |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
43 "error_no_wqinfo_found"; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
44 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
45 public static final String XPATH_WQS = "art:service/art:mainvalues/art:mainvalue"; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 public WQInfoObject[] getWQInfo( |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 String locale, |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 String river, |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 double from, |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 double to) |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
53 throws ServerException |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
54 { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
245
diff
changeset
|
55 logger.info("WQInfoServiceImpl.getWQInfo"); |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 |
1425
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
57 String url = getServletContext().getInitParameter("server-url"); |
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
58 |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 Document doc = XMLUtils.newDocument(); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 doc, |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 ArtifactNamespaceContext.NAMESPACE_URI, |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 Element mainvalues = ec.create("mainvalues"); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
67 Element riverEl = ec.create("river"); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 Element startEl = ec.create("start"); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 Element endEl = ec.create("end"); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 riverEl.setTextContent(river); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
72 startEl.setTextContent(Double.valueOf(from).toString()); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
73 endEl.setTextContent(Double.valueOf(to).toString()); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
74 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
75 mainvalues.appendChild(riverEl); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
76 mainvalues.appendChild(startEl); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
77 mainvalues.appendChild(endEl); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
78 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 doc.appendChild(mainvalues); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 HttpClient client = new HttpClientImpl(url, locale); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
83 try { |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 Document result = client.callService(url, "mainvalues", doc); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
85 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
245
diff
changeset
|
86 logger.debug("Extract wq info objects now."); |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
87 WQInfoObject[] objects = extractWQInfoObjects(result); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
88 |
5567
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
89 if (objects.length > 0) { |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
90 return objects; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
91 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
92 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
93 catch (ConnectionException ce) { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
245
diff
changeset
|
94 logger.error(ce, ce); |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
95 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
96 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
97 throw new ServerException(ERROR_NO_WQINFO_FOUND); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
98 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
99 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
100 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
101 /** |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
102 * Extracts all wq info objects from <i>result</i> document. |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
103 * |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
104 * @param result The document retrieved by the server. |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
105 * |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
106 * @return a list of WQInfoObjects. |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
107 */ |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
108 protected WQInfoObject[] extractWQInfoObjects(Document result) |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
109 throws ServerException |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
110 { |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
111 NodeList list = (NodeList) XMLUtils.xpath( |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
112 result, |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
113 XPATH_WQS, |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
114 XPathConstants.NODESET, |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
115 ArtifactNamespaceContext.INSTANCE); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
116 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
117 if (list == null || list.getLength() == 0) { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
245
diff
changeset
|
118 logger.warn("No wq info found."); |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
119 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
120 throw new ServerException(ERROR_NO_WQINFO_FOUND); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
121 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
122 |
5567
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
123 boolean debug = logger.isDebugEnabled(); |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
124 |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
125 int num = list.getLength(); |
5567
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
126 if (debug) { |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
127 logger.debug("Response contains " + num + " objects."); |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
128 } |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
129 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
130 List<WQInfoObject> objects = |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
131 new ArrayList<WQInfoObject>(num); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
132 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
133 for (int i = 0; i < num; i++) { |
5596
8fce35702908
Rolled XPath replacement back for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5586
diff
changeset
|
134 WQInfoObject obj = buildWQInfoObject(list.item(i)); |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
135 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
136 if (obj != null) { |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
137 objects.add(obj); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
138 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
139 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
140 |
5567
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
141 if (debug) { |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
142 logger.debug("Retrieved " + objects.size() + " wq values"); |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
143 } |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
144 |
5567
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
145 WQInfoObject [] array = (WQInfoObject[]) |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
146 objects.toArray(new WQInfoObject[objects.size()]); |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
147 |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
148 Arrays.sort(array, WQ_INFO_OBJECT_CMP); |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
149 |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
150 return array; |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
151 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
152 |
5567
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
153 public static final Comparator<WQInfoObject> WQ_INFO_OBJECT_CMP = |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
154 new Comparator<WQInfoObject>() { |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
155 @Override |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
156 public int compare(WQInfoObject a, WQInfoObject b) { |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
157 |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
158 // Descending by type: Qs before Ds |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
159 int cmp = a.getType().compareTo(b.getType()); |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
160 if (cmp < 0) return +1; |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
161 if (cmp > 0) return -1; |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
162 |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
163 // Ascending by value |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
164 double diff = a.getValue() - b.getValue(); |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
165 if (diff < 0d) return -1; |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
166 if (diff > 0d) return +1; |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
167 return 0; |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
168 } |
42692d6868e6
Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4980
diff
changeset
|
169 }; |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
170 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
171 /** |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
172 * Extracts information for a single wq info object and intializes an |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
173 * WQInfoObject with them. |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
174 * |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
175 * @param node The node that contains the information. |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
176 * |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
177 * @return a valid WQInfoObject. |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
178 */ |
5596
8fce35702908
Rolled XPath replacement back for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5586
diff
changeset
|
179 protected static WQInfoObject buildWQInfoObject(Node node) { |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
180 |
5596
8fce35702908
Rolled XPath replacement back for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5586
diff
changeset
|
181 String name = XMLUtils.xpathString( |
8fce35702908
Rolled XPath replacement back for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5586
diff
changeset
|
182 node, "@name", ArtifactNamespaceContext.INSTANCE); |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
183 |
5596
8fce35702908
Rolled XPath replacement back for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5586
diff
changeset
|
184 String type = XMLUtils.xpathString( |
8fce35702908
Rolled XPath replacement back for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5586
diff
changeset
|
185 node, "@type", ArtifactNamespaceContext.INSTANCE); |
8fce35702908
Rolled XPath replacement back for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5586
diff
changeset
|
186 |
8fce35702908
Rolled XPath replacement back for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5586
diff
changeset
|
187 String value = XMLUtils.xpathString( |
8fce35702908
Rolled XPath replacement back for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5586
diff
changeset
|
188 node, "@value", ArtifactNamespaceContext.INSTANCE); |
8fce35702908
Rolled XPath replacement back for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5586
diff
changeset
|
189 |
8fce35702908
Rolled XPath replacement back for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5586
diff
changeset
|
190 if (name != null && type != null) { |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
191 try { |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
192 return new WQInfoObjectImpl( |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
193 name, |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
194 type, |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
195 new Double(value)); |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
196 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
197 catch (NumberFormatException nfe) { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
245
diff
changeset
|
198 logger.warn(nfe.getLocalizedMessage()); |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
199 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
200 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
201 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
245
diff
changeset
|
202 logger.warn("Invalid wq info object found."); |
245
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
203 |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
204 return null; |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
205 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
206 } |
1e73d5a4859c
Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
207 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |