changeset 26:c19985f75118

Implemented a service that triggers the artifact-collection creation in the artifact server. flys-client/trunk@1413 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 07 Mar 2011 13:47:55 +0000
parents 2da6be38d8b6
children e4155a6833a9
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/services/CreateCollectionService.java flys-client/src/main/java/de/intevation/flys/client/client/services/CreateCollectionServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java flys-client/src/main/java/de/intevation/flys/client/server/CreateCollectionServiceImpl.java flys-client/src/main/webapp/WEB-INF/web.xml
diffstat 6 files changed, 156 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Mar 07 13:40:37 2011 +0000
+++ b/flys-client/ChangeLog	Mon Mar 07 13:47:55 2011 +0000
@@ -1,3 +1,18 @@
+2011-03-07  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/services/CreateCollectionService.java,
+	  src/main/java/de/intevation/flys/client/client/services/CreateCollectionServiceAsync.java,
+	  src/main/java/de/intevation/flys/client/server/CreateCollectionServiceImpl.java:
+	  New. A service that might be used to create new collections in the
+	  artifact server.
+
+	* src/main/webapp/WEB-INF/web.xml: Registered the service to create new
+	  collections.
+
+	* src/main/java/de/intevation/flys/client/client/ui/CollectionView.java:
+	  Added the service to create new collections. Currently, this service is
+	  not used.
+
 2011-03-07  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/shared/model/DefaultUser.java,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/CreateCollectionService.java	Mon Mar 07 13:47:55 2011 +0000
@@ -0,0 +1,23 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.RemoteService;
+import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+
+
+/**
+ * This interface describes the service for creating new collections.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+@RemoteServiceRelativePath("create-collection")
+public interface CreateCollectionService extends RemoteService {
+
+    /**
+     * This method creates a new collection in the artifact server and returns
+     * the uuid of this collection.
+     *
+     * @return the uuid of the created collection.
+     */
+    String create(String serverUrl, String ownerId);
+}
+// 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/CreateCollectionServiceAsync.java	Mon Mar 07 13:47:55 2011 +0000
@@ -0,0 +1,15 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+
+/**
+ * This interface describes the service for creating new collections.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface CreateCollectionServiceAsync {
+
+    void create(String serverUrl, String owner, AsyncCallback<String> callback);
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Mon Mar 07 13:40:37 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Mon Mar 07 13:47:55 2011 +0000
@@ -36,6 +36,8 @@
 import de.intevation.flys.client.client.event.CollectionChangeHandler;
 import de.intevation.flys.client.client.services.ArtifactService;
 import de.intevation.flys.client.client.services.ArtifactServiceAsync;
+import de.intevation.flys.client.client.services.CreateCollectionService;
+import de.intevation.flys.client.client.services.CreateCollectionServiceAsync;
 
 
 /**
@@ -50,6 +52,10 @@
     protected ArtifactServiceAsync artifactService =
         GWT.create(ArtifactService.class);
 
+    /** The ArtifactService used to communicate with the Artifact server. */
+    protected CreateCollectionServiceAsync createCollectionService =
+        GWT.create(CreateCollectionService.class);
+
     /** The message class that provides i18n strings.*/
     FLYSMessages messages = GWT.create(FLYSMessages.class);
 
@@ -127,6 +133,38 @@
 
 
     /**
+     * This method triggers the CreateCollectionService to create a new
+     * collection in the artifact server.
+     *
+     * @param ownerId The uuid of the user that should own the new collection.
+     */
+    protected void createNewCollection(String ownerId) {
+        Config config    = Config.getInstance();
+        String serverUrl = config.getServerUrl();
+
+        createCollectionService.create(
+            serverUrl, ownerId,
+            new AsyncCallback<String>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not create the new collection.");
+                    GWT.log(caught.getMessage());
+                }
+
+                public void onSuccess(String uuid) {
+                    GWT.log("Successfully created a new collection.");
+                    GWT.log("NEW collection uuid: " + uuid);
+                }
+            });
+    }
+
+
+    protected FLYS getFlys() {
+        return flys;
+    }
+
+
+
+    /**
      * This method registers a new ValueChangeHandler.
      *
      * @param handler The new ValueChangeHandler.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/CreateCollectionServiceImpl.java	Mon Mar 07 13:47:55 2011 +0000
@@ -0,0 +1,55 @@
+package de.intevation.flys.client.server;
+
+import org.w3c.dom.Document;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.ClientProtocolUtils;
+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.artifacts.httpclient.http.response.DocumentResponseHandler;
+
+import de.intevation.flys.client.client.services.CreateCollectionService;
+
+
+/**
+ * This interface provides the createCollection service to create new
+ * collections in the artifact server.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class CreateCollectionServiceImpl
+extends      RemoteServiceServlet
+implements   CreateCollectionService
+{
+    /** XPath to figure out the uuid of the created collection.*/
+    public static final String XPATH_COLLECTION_UUID =
+        "/art:result/art:artifact-collection/@art:uuid";
+
+
+    public String create(String serverUrl, String ownerId) {
+        GWT.log("Start creating a new collection.");
+
+        Document create   = ClientProtocolUtils.newCreateDocument(null);
+        HttpClient client = new HttpClientImpl(serverUrl);
+
+        try {
+            Document doc = (Document) client.createCollection(
+                create, ownerId, new DocumentResponseHandler());
+
+            return XMLUtils.xpathString(
+                doc, XPATH_COLLECTION_UUID, ArtifactNamespaceContext.INSTANCE);
+        }
+        catch (ConnectionException ce) {
+            System.err.println(ce.getLocalizedMessage());
+        }
+
+        return null;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Mon Mar 07 13:40:37 2011 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Mon Mar 07 13:47:55 2011 +0000
@@ -26,6 +26,16 @@
     <url-pattern>/flys/artifact</url-pattern>
   </servlet-mapping>
 
+  <servlet>
+    <servlet-name>create-collection</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.CreateCollectionServiceImpl</servlet-class>
+  </servlet>
+  
+  <servlet-mapping>
+    <servlet-name>create-collection</servlet-name>
+    <url-pattern>/flys/create-collection</url-pattern>
+  </servlet-mapping>
+
   <!-- Default page to serve -->
   <welcome-file-list>
     <welcome-file>FLYS.html</welcome-file>

http://dive4elements.wald.intevation.org