Mercurial > dive4elements > river
changeset 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 | 6ba17b628552 |
children | cfbfaadf4b6f |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java |
diffstat | 2 files changed, 61 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 <felix.wolfsteller@intevation.de> + + 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 <felix.wolfsteller@intevation.de> Added implementation and configuration of RemoveArtifactService.
--- 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 :