diff flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java @ 1320:5733c05ce24c

Added removeArtifact CollectionHelper method. flys-client/trunk@2961 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 13 Oct 2011 12:30:08 +0000
parents ecd0243bc09e
children ab2b1a4a9ead
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java	Thu Oct 13 12:28:21 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java	Thu Oct 13 12:30:08 2011 +0000
@@ -666,5 +666,58 @@
 
         throw new ServerException(ERROR_ADD_ARTIFACT);
     }
+
+
+    /**
+     * Remove an artifact from a collection.
+     * @param collection Collection to remove artifact to.
+     * @param artifact   Artifact to add to collection
+     */
+    public static Collection removeArtifact(
+        Collection collection,
+        String     artifactId,
+        String     url,
+        String     locale)
+    throws ServerException
+    {
+        System.out.println("Collection.removeArtifact");
+
+        if (collection == null) {
+            System.err.println("The given Collection is null!");
+            return null;
+        }
+
+        Document remove = ClientProtocolUtils.newRemoveArtifactDocument(
+            artifactId);
+
+        HttpClient client = new HttpClientImpl(url, locale);
+
+        try {
+            System.out.println("Do HTTP request now.");
+
+            Document response = (Document) client.doCollectionAction(
+                remove, collection.identifier(), new DocumentResponseHandler());
+
+            System.out.println(
+                "Finished HTTP request successfully. Parse Collection now.");
+            System.out.println(XMLUtils.toString(response));
+
+            Collection c = CollectionHelper.parseCollection(response);
+
+            if (c == null) {
+                throw new ServerException(ERROR_ADD_ARTIFACT);
+            }
+
+            return c;
+        }
+        catch (ConnectionException ce) {
+            System.err.println(ce.getLocalizedMessage());
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+        // TODO other err
+        throw new ServerException(ERROR_ADD_ARTIFACT);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org