# HG changeset patch # User Felix Wolfsteller # Date 1318509008 0 # Node ID 5733c05ce24cc58866b8e545b1751b3d2de0f5cf # Parent 6ba17b628552998e57f1b6d38d85c8303d1bd978 Added removeArtifact CollectionHelper method. flys-client/trunk@2961 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 6ba17b628552 -r 5733c05ce24c flys-client/ChangeLog --- a/flys-client/ChangeLog Thu Oct 13 12:28:21 2011 +0000 +++ b/flys-client/ChangeLog Thu Oct 13 12:30:08 2011 +0000 @@ -1,3 +1,11 @@ +2011-10-13 Felix Wolfsteller + + Added helper in use of new RemoveArtifactService. + + * src/main/java/de/intevation/flys/client/server/CollectionHelper.java + (removeArtifact): New method to remove an artifact from a + collection. + 2011-10-13 Felix Wolfsteller Added implementation and configuration of RemoveArtifactService. diff -r 6ba17b628552 -r 5733c05ce24c flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java --- 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 :