annotate flys-client/src/main/java/de/intevation/flys/client/server/WQInfoServiceImpl.java @ 5586:966237892c9b

Removed obsolete import.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Apr 2013 23:28:56 +0200
parents 4b281c7046c8
children 8fce35702908
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;
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 import org.w3c.dom.NodeList;
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 245
diff changeset
14 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
15
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16 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
17
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 import de.intevation.artifacts.common.ArtifactNamespaceContext;
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 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
20
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 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
22 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
23 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
24
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 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
26 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
27 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
28 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
29
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 * @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
33 */
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 public class WQInfoServiceImpl
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 extends RemoteServiceServlet
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 implements WQInfoService
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 {
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 245
diff changeset
38 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
39 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
40
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 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
42 "error_no_wqinfo_found";
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 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
45
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 public WQInfoObject[] getWQInfo(
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 String locale,
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 String river,
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 double from,
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 double to)
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 throws ServerException
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 {
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 245
diff changeset
54 logger.info("WQInfoServiceImpl.getWQInfo");
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55
1425
bc06a671ef60 Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1367
diff changeset
56 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
57
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 Document doc = XMLUtils.newDocument();
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 doc,
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 ArtifactNamespaceContext.NAMESPACE_URI,
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 ArtifactNamespaceContext.NAMESPACE_PREFIX);
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 Element mainvalues = ec.create("mainvalues");
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 Element riverEl = ec.create("river");
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 Element startEl = ec.create("start");
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 Element endEl = ec.create("end");
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70 riverEl.setTextContent(river);
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 startEl.setTextContent(Double.valueOf(from).toString());
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 endEl.setTextContent(Double.valueOf(to).toString());
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 mainvalues.appendChild(riverEl);
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 mainvalues.appendChild(startEl);
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 mainvalues.appendChild(endEl);
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 doc.appendChild(mainvalues);
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 HttpClient client = new HttpClientImpl(url, locale);
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82 try {
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
83 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
84
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 245
diff changeset
85 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
86 WQInfoObject[] objects = extractWQInfoObjects(result);
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87
5567
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
88 if (objects.length > 0) {
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89 return objects;
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90 }
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 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
93 logger.error(ce, ce);
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
94 }
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 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
97 }
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 * 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
102 *
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103 * @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
104 *
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 * @return a list of WQInfoObjects.
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
106 */
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
107 protected WQInfoObject[] extractWQInfoObjects(Document result)
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
108 throws ServerException
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109 {
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
110 NodeList list = (NodeList) XMLUtils.xpath(
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111 result,
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 XPATH_WQS,
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 XPathConstants.NODESET,
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
114 ArtifactNamespaceContext.INSTANCE);
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
115
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
116 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
117 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
118
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
119 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
120 }
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
121
5567
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
122 boolean debug = logger.isDebugEnabled();
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
123
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
124 int num = list.getLength();
5567
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
125 if (debug) {
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
126 logger.debug("Response contains " + num + " objects.");
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
127 }
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
128
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129 List<WQInfoObject> objects =
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
130 new ArrayList<WQInfoObject>(num);
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
131
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
132 for (int i = 0; i < num; i++) {
5585
4b281c7046c8 Used DOM instead of XPath to extract main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5567
diff changeset
133 WQInfoObject obj = buildWQInfoObject((Element)list.item(i));
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
134
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
135 if (obj != null) {
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
136 objects.add(obj);
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
137 }
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
5567
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
140 if (debug) {
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
141 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
142 }
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
143
5567
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
144 WQInfoObject [] array = (WQInfoObject[])
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
145 objects.toArray(new WQInfoObject[objects.size()]);
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
146
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
147 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
148
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
149 return array;
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
150 }
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
151
5567
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
152 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
153 new Comparator<WQInfoObject>() {
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
154 @Override
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
155 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
156
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
157 // Descending by type: Qs before Ds
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
158 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
159 if (cmp < 0) return +1;
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
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
162 // Ascending by value
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
163 double diff = a.getValue() - b.getValue();
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
164 if (diff < 0d) return -1;
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 return 0;
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
167 }
42692d6868e6 Order Qs before Ds and values ascending
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4980
diff changeset
168 };
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
169
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 * 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
172 * WQInfoObject with them.
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
173 *
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
174 * @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
175 *
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
176 * @return a valid WQInfoObject.
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
177 */
5585
4b281c7046c8 Used DOM instead of XPath to extract main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5567
diff changeset
178 protected static WQInfoObject buildWQInfoObject(Element node) {
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
179
5585
4b281c7046c8 Used DOM instead of XPath to extract main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5567
diff changeset
180 String uri = ArtifactNamespaceContext.NAMESPACE_URI;
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
181
5585
4b281c7046c8 Used DOM instead of XPath to extract main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5567
diff changeset
182 String name = node.getAttributeNS(uri, "name");
4b281c7046c8 Used DOM instead of XPath to extract main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5567
diff changeset
183 String type = node.getAttributeNS(uri, "type");
4b281c7046c8 Used DOM instead of XPath to extract main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5567
diff changeset
184 String value = node.getAttributeNS(uri, "value");
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
185
5585
4b281c7046c8 Used DOM instead of XPath to extract main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5567
diff changeset
186 if (!name.isEmpty() && !type.isEmpty()) {
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
187 try {
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
188 return new WQInfoObjectImpl(
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
189 name,
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
190 type,
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
191 new Double(value));
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
192 }
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
193 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
194 logger.warn(nfe.getLocalizedMessage());
245
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
195 }
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
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("Invalid wq info object found.");
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 return null;
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
201 }
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
202 }
1e73d5a4859c Added new WQ info service and data structures.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
203 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org