changeset 29:44c63e7fd0d0

Added a service to list the supported rivers of the artifact server. The FLYS instance serves a method that retrieves this list. flys-client/trunk@1431 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 09 Mar 2011 08:00:06 +0000
parents dfdb927b137d
children 5709bd8f4d7c
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java flys-client/src/main/java/de/intevation/flys/client/client/services/RiverService.java flys-client/src/main/java/de/intevation/flys/client/client/services/RiverServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/server/RiverServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultRiver.java flys-client/src/main/java/de/intevation/flys/client/shared/model/River.java flys-client/src/main/webapp/WEB-INF/web.xml
diffstat 8 files changed, 255 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Mar 08 16:20:34 2011 +0000
+++ b/flys-client/ChangeLog	Wed Mar 09 08:00:06 2011 +0000
@@ -1,3 +1,21 @@
+2011-03-09  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/services/RiverServiceAsync.java,
+	  src/main/java/de/intevation/flys/client/client/services/RiverService.java,
+	  src/main/java/de/intevation/flys/client/server/RiverServiceImpl.java:
+	  New. A service that retrieves a list of supported rivers by the artifact
+	  server.
+
+	* src/main/java/de/intevation/flys/client/shared/model/River.java,
+	  src/main/java/de/intevation/flys/client/shared/model/DefaultRiver.java:
+	  New. A model class and its default implementation to store rivers.
+
+	* src/main/java/de/intevation/flys/client/client/FLYS.java: At application
+	  start, the provided rivers by the artifact server are fetched using the
+	  RiverService. The rivers are queriable via a getRivers() method.
+
+	* src/main/webapp/WEB-INF/web.xml: Registered the RiverService.
+
 2011-03-08  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Tue Mar 08 16:20:34 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Wed Mar 09 08:00:06 2011 +0000
@@ -11,10 +11,13 @@
 import de.intevation.flys.client.shared.model.Artifact;
 import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.shared.model.DefaultCollection;
+import de.intevation.flys.client.shared.model.River;
 import de.intevation.flys.client.shared.model.User;
 
 import de.intevation.flys.client.client.services.ArtifactService;
 import de.intevation.flys.client.client.services.ArtifactServiceAsync;
+import de.intevation.flys.client.client.services.RiverService;
+import de.intevation.flys.client.client.services.RiverServiceAsync;
 import de.intevation.flys.client.client.services.UserService;
 import de.intevation.flys.client.client.services.UserServiceAsync;
 import de.intevation.flys.client.client.ui.CollectionView;
@@ -35,6 +38,9 @@
     /** The UserService used to retrieve information about the current user. */
     protected UserServiceAsync userService = GWT.create(UserService.class);
 
+    /** The RiverService used to retrieve the supported rivers of the server.*/
+    protected RiverServiceAsync riverService = GWT.create(RiverService.class);
+
     /** The ArtifactService used to communicate with the Artifact server. */
     protected ArtifactServiceAsync artifactService =
         GWT.create(ArtifactService.class);
@@ -54,6 +60,9 @@
     /** The user who is currently logged in.*/
     protected User currentUser;
 
+    /** The list of rivers supported by the server.*/
+    protected River[] rivers;
+
 
     /**
      * This is the entry point method.
@@ -78,6 +87,8 @@
         initConfiguration();
         String serverUrl = Config.getInstance().getServerUrl();
 
+        getRivers();
+
         userService.getCurrentUser(serverUrl, new AsyncCallback<User>() {
             public void onFailure(Throwable caught) {
                 GWT.log("Could not find a logged in user.");
@@ -136,6 +147,33 @@
 
 
     /**
+     * Returns a list of rivers supported by the artifact server.
+     *
+     * @return a list of rivers supported by the artifact server.
+     */
+    public River[] getRivers() {
+        if (rivers == null) {
+            String url = Config.getInstance().getServerUrl();
+            GWT.log("Fetch rivers from server '" + url + "'");
+
+            riverService.list(url, new AsyncCallback<River[]>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not recieve a list of rivers.");
+                    GWT.log(caught.getMessage());
+                }
+
+                public void onSuccess(River[] newRivers) {
+                    GWT.log("Retrieved " + newRivers.length + " new rivers.");
+                    rivers = newRivers;
+                }
+            });
+        }
+
+        return rivers;
+    }
+
+
+    /**
      * This method creates a new CollectionView and adds it to the workspace.
      */
     public void newProject() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/RiverService.java	Wed Mar 09 08:00:06 2011 +0000
@@ -0,0 +1,26 @@
+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.model.River;
+
+/**
+ * This interface provides a method to list the supported rivers of the artifact
+ * server.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+@RemoteServiceRelativePath("rivers")
+public interface RiverService extends RemoteService {
+
+    /**
+     * This method returns a list of rivers provided by the artifact server.
+     *
+     * @param serverUrl The url of the artifact server.
+     *
+     * @return a list of rivers provided by the artifact server.
+     */
+    public River[] list(String serverUrl);
+}
+// 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/RiverServiceAsync.java	Wed Mar 09 08:00:06 2011 +0000
@@ -0,0 +1,18 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import de.intevation.flys.client.shared.model.River;
+
+
+/**
+ * This interface provides a method to list the supported rivers of the artifact
+ * server.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface RiverServiceAsync {
+
+    public void list(String serverUrl, AsyncCallback<River[]> callback);
+}
+// 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/RiverServiceImpl.java	Wed Mar 09 08:00:06 2011 +0000
@@ -0,0 +1,83 @@
+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.NodeList;
+import org.w3c.dom.Node;
+
+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.model.DefaultRiver;
+import de.intevation.flys.client.shared.model.River;
+import de.intevation.flys.client.client.services.RiverService;
+
+
+/**
+ * This interface provides a method to list the supported rivers of the artifact
+ * server.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class RiverServiceImpl
+extends      RemoteServiceServlet
+implements   RiverService
+{
+    /** The XPath string that points to the rivers in the resulting document.*/
+    public static final String XPATH_RIVERS = "/art:rivers/art:river";
+
+
+    public River[] list(String serverUrl) {
+        Document doc      = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            doc,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        doc.appendChild(ec.create("action"));
+
+        HttpClient client = new HttpClientImpl(serverUrl);
+
+        try {
+            Document res = client.callService(serverUrl, "rivers", doc);
+
+            NodeList rivers = (NodeList) XMLUtils.xpath(
+                res,
+                XPATH_RIVERS,
+                XPathConstants.NODESET,
+                ArtifactNamespaceContext.INSTANCE);
+
+            int count = rivers.getLength();
+
+            List<River> theRivers = new ArrayList<River>(count);
+
+            for (int i = 0; i < count; i++) {
+                Node tmp = rivers.item(i);
+
+                String name = XMLUtils.xpathString(
+                    tmp, "@art:name", ArtifactNamespaceContext.INSTANCE);
+
+                theRivers.add(new DefaultRiver(name));
+            }
+
+            return (River[]) theRivers.toArray(new River[count]);
+        }
+        catch (ConnectionException ce) {
+            System.err.println(ce.getLocalizedMessage());
+        }
+
+        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/DefaultRiver.java	Wed Mar 09 08:00:06 2011 +0000
@@ -0,0 +1,50 @@
+package de.intevation.flys.client.shared.model;
+
+
+/**
+ * The simpliest default implementation of a River that just stores a name.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class DefaultRiver implements River {
+
+    /** The name of the river.*/
+    protected String name;
+
+    /**
+     * The default constructor that creates empty river objects.
+     */
+    public DefaultRiver() {
+    }
+
+
+    /**
+     * This constructor should be used to create new rivers.
+     *
+     * @param name The name of the river.
+     */
+    public DefaultRiver(String name) {
+        this.name = name;
+    }
+
+
+    /**
+     * Sets the name of the river.
+     *
+     * @param name The name of the river.
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+
+    /**
+     * Returns the name of the river.
+     *
+     * @return the name of the river.
+     */
+    public String getName() {
+        return name;
+    }
+}
+// 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/River.java	Wed Mar 09 08:00:06 2011 +0000
@@ -0,0 +1,12 @@
+package de.intevation.flys.client.shared.model;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface River extends Serializable {
+
+    String getName();
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Tue Mar 08 16:20:34 2011 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Wed Mar 09 08:00:06 2011 +0000
@@ -36,6 +36,16 @@
     <url-pattern>/flys/create-collection</url-pattern>
   </servlet-mapping>
 
+  <servlet>
+    <servlet-name>rivers</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.RiverServiceImpl</servlet-class>
+  </servlet>
+  
+  <servlet-mapping>
+    <servlet-name>rivers</servlet-name>
+    <url-pattern>/flys/rivers</url-pattern>
+  </servlet-mapping>
+
   <!-- Default page to serve -->
   <welcome-file-list>
     <welcome-file>FLYS.html</welcome-file>

http://dive4elements.wald.intevation.org