changeset 599:1dbffe4c6d12

Implemented the RPC stubs to set the TTL and name of a collection and to delete an existing collection. flys-client/trunk@2203 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 22 Jun 2011 12:50:20 +0000
parents 031357c3e23e
children 347cf4a5a486
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java flys-client/src/main/java/de/intevation/flys/client/server/DeleteCollectionServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/server/DoCollectionAction.java flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionNameServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionTTLServiceImpl.java
diffstat 6 files changed, 112 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Jun 22 11:47:07 2011 +0000
+++ b/flys-client/ChangeLog	Wed Jun 22 12:50:20 2011 +0000
@@ -1,3 +1,19 @@
+2011-06-22  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/DoCollectionAction.java:
+	  New. This base RPC service implementation handles collecion specific
+	  actions. It has a doAction() method that takes a Collection, the action
+	  document and a server url.
+
+	* src/main/java/de/intevation/flys/client/server/SetCollectionNameServiceImpl.java,
+	  src/main/java/de/intevation/flys/client/server/DeleteCollectionServiceImpl.java,
+	  src/main/java/de/intevation/flys/client/server/SetCollectionTTLServiceImpl.java:
+	  Trigger the collection actions on the server using the
+	  DoCollectionAction class which handles the Http stuff.
+
+	* src/main/java/de/intevation/flys/client/client/ui/ProjectList.java:
+	  Bugfix: If no user collections returned, we will clear the project list.
+
 2011-06-22  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/services/SetCollectionNameServiceAsync.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Wed Jun 22 11:47:07 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Wed Jun 22 12:50:20 2011 +0000
@@ -433,10 +433,6 @@
 
                     GWT.log("Received " + num + " user collections.");
 
-                    if (num == 0) {
-                        return;
-                    }
-
                     updateGrid(collections);
                 }
             }
@@ -456,6 +452,10 @@
     protected void updateGrid(Collection[] collections) {
         clearGrid();
 
+        if (collections == null || collections.length == 0) {
+            return;
+        }
+
         for (Collection c: collections) {
             grid.addData(new CollectionRecord(c));
         }
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DeleteCollectionServiceImpl.java	Wed Jun 22 11:47:07 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/DeleteCollectionServiceImpl.java	Wed Jun 22 12:50:20 2011 +0000
@@ -2,15 +2,8 @@
 
 import org.w3c.dom.Document;
 
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
-
 import de.intevation.artifacts.common.utils.ClientProtocolUtils;
 
-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.shared.exceptions.ServerException;
 import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.client.services.DeleteCollectionService;
@@ -20,14 +13,20 @@
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class DeleteCollectionServiceImpl
-extends      RemoteServiceServlet
+extends      DoCollectionAction
 implements   DeleteCollectionService
 {
+    public static final String XPATH_RESULT      = "/art:result/text()";
+    public static final String OPERATION_FAILURE = "FAILED";
+
     public void delete(Collection c, String url)
     throws ServerException
     {
-        // TODO IMPLEMENT ME
-        throw new ServerException("Delete Service NOT IMPLEMENTED");
+        System.out.println("Delete collection: " + c.identifier());
+
+        Document del = ClientProtocolUtils.newDeleteCollectionDocument();
+
+        doAction(c, del, url);
     }
 }
 // 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/DoCollectionAction.java	Wed Jun 22 12:50:20 2011 +0000
@@ -0,0 +1,54 @@
+package de.intevation.flys.client.server;
+
+import org.w3c.dom.Document;
+
+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.artifacts.httpclient.http.response.DocumentResponseHandler;
+
+import de.intevation.flys.client.shared.exceptions.ServerException;
+import de.intevation.flys.client.shared.model.Collection;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class DoCollectionAction extends RemoteServiceServlet {
+
+    public static final String XPATH_RESULT      = "/art:result/text()";
+    public static final String OPERATION_FAILURE = "FAILED";
+    public static final String FAILURE_EXCEPTION = "collection_action_failed";
+
+
+    protected void doAction(Collection c, Document action, String url)
+    throws    ServerException
+    {
+        HttpClient client = new HttpClientImpl(url);
+
+        try {
+            Document res  = (Document) client.doCollectionAction(
+                action, c.identifier(),
+                new DocumentResponseHandler());
+
+            String result = XMLUtils.xpathString(
+                res,
+                XPATH_RESULT,
+                ArtifactNamespaceContext.INSTANCE);
+
+            if (result == null || result.equals(OPERATION_FAILURE)) {
+                System.err.println("Operation failed.");
+                throw new ServerException(FAILURE_EXCEPTION);
+            }
+        }
+        catch (ConnectionException ce) {
+            System.err.println(ce.getLocalizedMessage());
+            throw new ServerException(FAILURE_EXCEPTION);
+        }
+    }
+}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionNameServiceImpl.java	Wed Jun 22 11:47:07 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionNameServiceImpl.java	Wed Jun 22 12:50:20 2011 +0000
@@ -2,15 +2,8 @@
 
 import org.w3c.dom.Document;
 
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
-
 import de.intevation.artifacts.common.utils.ClientProtocolUtils;
 
-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.shared.exceptions.ServerException;
 import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.client.services.SetCollectionNameService;
@@ -20,14 +13,18 @@
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class SetCollectionNameServiceImpl
-extends      RemoteServiceServlet
+extends      DoCollectionAction
 implements   SetCollectionNameService
 {
     public void setName(Collection c, String url)
     throws ServerException
     {
-        // TODO IMPLEMENT ME
-        throw new ServerException("Name Service NOT IMPLEMENTED");
+        System.out.println("Set name of collection: " + c.identifier());
+
+        String   name = c.getName();
+        Document set  = ClientProtocolUtils.newSetCollectionNameDocument(name);
+
+        doAction(c, set, url);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionTTLServiceImpl.java	Wed Jun 22 11:47:07 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionTTLServiceImpl.java	Wed Jun 22 12:50:20 2011 +0000
@@ -2,15 +2,8 @@
 
 import org.w3c.dom.Document;
 
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
-
 import de.intevation.artifacts.common.utils.ClientProtocolUtils;
 
-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.shared.exceptions.ServerException;
 import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.client.services.SetCollectionTTLService;
@@ -20,14 +13,33 @@
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class SetCollectionTTLServiceImpl
-extends      RemoteServiceServlet
+extends      DoCollectionAction
 implements   SetCollectionTTLService
 {
+    public static final String XPATH_RESULT      = "/art:result/text()";
+    public static final String OPERATION_FAILURE = "FAILED";
+
     public void setTTL(Collection c, String url)
     throws ServerException
     {
-        // TODO IMPLEMENT ME
-        throw new ServerException("TTL Service NOT IMPLEMENTED");
+        System.out.println("Set ttl of collection: " + c.identifier());
+
+        long   ttl   = c.getTTL();
+        String value = null;
+
+        if (ttl == 0) {
+            value = "INF";
+        }
+        else if (ttl < 0) {
+            value = "DEFAULT";
+        }
+        else {
+            value = String.valueOf(ttl);
+        }
+
+        Document set = ClientProtocolUtils.newSetCollectionTTLDocument(value);
+
+        doAction(c, set, url);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org