changeset 245:1e73d5a4859c

Added new WQ info service and data structures. flys-client/trunk@1825 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 04 May 2011 14:54:38 +0000
parents 1bc787eeb556
children ccba1a0b743e
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/services/WQInfoService.java flys-client/src/main/java/de/intevation/flys/client/client/services/WQInfoServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/server/WQInfoServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/WQInfoObject.java flys-client/src/main/java/de/intevation/flys/client/shared/model/WQInfoObjectImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/WQInfoRecord.java flys-client/src/main/webapp/WEB-INF/web.xml
diffstat 8 files changed, 377 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed May 04 14:40:50 2011 +0000
+++ b/flys-client/ChangeLog	Wed May 04 14:54:38 2011 +0000
@@ -1,3 +1,17 @@
+2011-05-04  Raimund Renkert <rrenkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/WQInfoServiceImpl.java,
+	  src/main/java/de/intevation/flys/client/client/services/WQInfoServiceAsync.java,
+	  src/main/java/de/intevation/flys/client/client/services/WQInfoService.java:
+	  New. This service fetches WQ information from the server.
+
+	* src/main/java/de/intevation/flys/client/shared/model/WQInfoRecord.java,
+	  src/main/java/de/intevation/flys/client/shared/model/WQInfoObjectImpl.java,
+	  src/main/java/de/intevation/flys/client/shared/model/WQInfoObject.java:
+	  New. Data structures for the WQ information.
+
+	* src/main/webapp/WEB-INF/web.xml: Added new service.
+
 2011-05-04  Raimund Renkert <rrenkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/WQInfoService.java	Wed May 04 14:54:38 2011 +0000
@@ -0,0 +1,29 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.RemoteService;
+import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+
+import de.intevation.flys.client.shared.exceptions.ServerException;
+import de.intevation.flys.client.shared.model.WQInfoObject;
+
+/**
+ * This service is used to fetch a list of DistanceInfoObjects from artifact
+ * server for a specific river.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+@RemoteServiceRelativePath("mainvalues")
+public interface WQInfoService extends RemoteService {
+
+    /**
+     * This method returns a list of DistanceInfoObjects for a specific river.
+     */
+    WQInfoObject[] getWQInfo(
+        String serverUrl,
+        String locale,
+        String river,
+        double start,
+        double end)
+    throws ServerException;
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/WQInfoServiceAsync.java	Wed May 04 14:54:38 2011 +0000
@@ -0,0 +1,21 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import de.intevation.flys.client.shared.model.WQInfoObject;
+
+
+/**
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public interface WQInfoServiceAsync {
+
+    void getWQInfo(
+        String url,
+        String locale,
+        String river,
+        double start,
+        double end,
+        AsyncCallback<WQInfoObject[]> cb);
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/WQInfoServiceImpl.java	Wed May 04 14:54:38 2011 +0000
@@ -0,0 +1,172 @@
+package de.intevation.flys.client.server;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.xpath.XPathConstants;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
+import de.intevation.artifacts.httpclient.http.HttpClient;
+import de.intevation.artifacts.httpclient.http.HttpClientImpl;
+
+import de.intevation.flys.client.shared.exceptions.ServerException;
+import de.intevation.flys.client.client.services.WQInfoService;
+import de.intevation.flys.client.shared.model.WQInfoObject;
+import de.intevation.flys.client.shared.model.WQInfoObjectImpl;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class WQInfoServiceImpl
+extends      RemoteServiceServlet
+implements   WQInfoService
+{
+    public static final String ERROR_NO_WQINFO_FOUND =
+        "error_no_wqinfo_found";
+
+    public static final String XPATH_WQS = "art:service/art:mainvalues/art:mainvalue";
+
+
+    public WQInfoObject[] getWQInfo(
+        String url,
+        String locale,
+        String river,
+        double from,
+        double to)
+    throws ServerException
+    {
+        System.out.println("WQInfoServiceImpl.getWQInfo");
+
+        Document doc = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            doc,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element mainvalues = ec.create("mainvalues");
+        Element riverEl = ec.create("river");
+        Element startEl = ec.create("start");
+        Element endEl   = ec.create("end");
+
+        riverEl.setTextContent(river);
+        startEl.setTextContent(Double.valueOf(from).toString());
+        endEl.setTextContent(Double.valueOf(to).toString());
+
+        mainvalues.appendChild(riverEl);
+        mainvalues.appendChild(startEl);
+        mainvalues.appendChild(endEl);
+
+        doc.appendChild(mainvalues);
+
+        HttpClient client = new HttpClientImpl(url, locale);
+
+        try {
+            Document result = client.callService(url, "mainvalues", doc);
+
+            System.out.println("Extract wq info objects now.");
+            WQInfoObject[] objects = extractWQInfoObjects(result);
+
+            if (objects != null && objects.length > 0) {
+                return objects;
+            }
+        }
+        catch (ConnectionException ce) {
+            System.err.println(ce.getLocalizedMessage());
+        }
+
+        throw new ServerException(ERROR_NO_WQINFO_FOUND);
+    }
+
+
+    /**
+     * Extracts all wq info objects from <i>result</i> document.
+     *
+     * @param result The document retrieved by the server.
+     *
+     * @return a list of WQInfoObjects.
+     */
+    protected WQInfoObject[] extractWQInfoObjects(Document result)
+    throws    ServerException
+    {
+        NodeList list = (NodeList) XMLUtils.xpath(
+            result,
+            XPATH_WQS,
+            XPathConstants.NODESET,
+            ArtifactNamespaceContext.INSTANCE);
+
+        if (list == null || list.getLength() == 0) {
+            System.err.println("No wq info found.");
+
+            throw new ServerException(ERROR_NO_WQINFO_FOUND);
+        }
+
+        int num = list.getLength();
+        System.out.println("Response contains " + num + " objects.");
+
+        List<WQInfoObject> objects =
+            new ArrayList<WQInfoObject>(num);
+
+        for (int i = 0; i < num; i++) {
+            WQInfoObject obj = buildWQInfoObject(list.item(i));
+
+            if (obj != null) {
+                objects.add(obj);
+            }
+        }
+
+        System.out.println("Retrieved " + objects.size() + " wq values");
+
+        return (WQInfoObject[])
+            objects.toArray(new WQInfoObject[num]);
+    }
+
+
+    /**
+     * Extracts information for a single wq info object and intializes an
+     * WQInfoObject with them.
+     *
+     * @param node The node that contains the information.
+     *
+     * @return a valid WQInfoObject.
+     */
+    protected WQInfoObject buildWQInfoObject(Node node) {
+        String name = XMLUtils.xpathString(
+            node, "@name", ArtifactNamespaceContext.INSTANCE);
+
+        String type = XMLUtils.xpathString(
+            node, "@type", ArtifactNamespaceContext.INSTANCE);
+
+        String value = XMLUtils.xpathString(
+            node, "@value", ArtifactNamespaceContext.INSTANCE);
+
+
+        if (name != null && type != null) {
+            try {
+                return new WQInfoObjectImpl(
+                    name,
+                    type,
+                    new Double(value));
+            }
+            catch (NumberFormatException nfe) {
+                System.err.println(nfe.getLocalizedMessage());
+            }
+        }
+
+        System.err.println("Invalid wq info object found.");
+
+        return null;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/WQInfoObject.java	Wed May 04 14:54:38 2011 +0000
@@ -0,0 +1,17 @@
+package de.intevation.flys.client.shared.model;
+
+import java.io.Serializable;
+
+
+/**
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public interface WQInfoObject extends Serializable {
+
+    String getName();
+
+    String getType();
+
+    Double getValue();
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/WQInfoObjectImpl.java	Wed May 04 14:54:38 2011 +0000
@@ -0,0 +1,45 @@
+package de.intevation.flys.client.shared.model;
+
+
+/**
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class WQInfoObjectImpl implements WQInfoObject {
+
+    protected String name;
+
+    protected String type;
+
+    protected Double value;
+
+
+    public WQInfoObjectImpl() {
+    }
+
+
+    public WQInfoObjectImpl(
+        String name,
+        String type,
+        Double value)
+    {
+        this.name  = name;
+        this.type  = type;
+        this.value = value;
+    }
+
+
+    public String getName() {
+        return name;
+    }
+
+
+    public String getType() {
+        return type;
+    }
+
+
+    public Double getValue() {
+        return value;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/WQInfoRecord.java	Wed May 04 14:54:38 2011 +0000
@@ -0,0 +1,68 @@
+package de.intevation.flys.client.shared.model;
+
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+
+
+/**
+ * The WQInfoRecord is a wrapper to put  WQ Info objects into
+ * a ListGrid.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class WQInfoRecord extends ListGridRecord {
+
+    /** The artifact collection. */
+    protected WQInfoObject wqInfo;
+
+
+    /**
+     * The default constructor.
+     *
+     * @param info The wq info object.
+     */
+    public WQInfoRecord(WQInfoObject info) {
+        this.wqInfo = info;
+
+        setName(info.getName());
+        setType(info.getType());
+        if (info.getValue() != null)
+            setValue(info.getValue());
+        else
+            setValue(info.getValue());
+    }
+
+
+    public void setName(String name) {
+        setAttribute("name", name);
+    }
+
+
+    public String getName() {
+        return getAttributeAsString("name");
+    }
+
+
+    public void setType(String type) {
+        setAttribute("type", type);
+    }
+
+
+    public String getType() {
+        return getAttributeAsString("type");
+    }
+
+    public void setValue(double value) {
+        setAttribute("value", value);
+    }
+
+
+    public double getValue() {
+        return getAttributeAsDouble("value");
+    }
+
+
+    public WQInfoObject getWQInfo() {
+        return wqInfo;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Wed May 04 14:40:50 2011 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Wed May 04 14:54:38 2011 +0000
@@ -117,6 +117,17 @@
     <url-pattern>/flys/distanceinfo</url-pattern>
   </servlet-mapping>
 
+  <servlet>
+    <servlet-name>mainvalues</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.WQInfoServiceImpl</servlet-class>
+  </servlet>
+  
+  <servlet-mapping>
+    <servlet-name>mainvalues</servlet-name>
+    <url-pattern>/flys/mainvalues</url-pattern>
+  </servlet-mapping>
+
+
   
   <servlet>
     <servlet-name>ChartOutputService</servlet-name>

http://dive4elements.wald.intevation.org