diff artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 164:268c2972d4a7

Implemented the interface method listCollections() in the artifact database. artifacts/trunk@1389 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 03 Mar 2011 14:28:02 +0000
parents 4ac91485b4e0
children 89db80380f7f
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Mar 03 14:00:12 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Mar 03 14:28:02 2011 +0000
@@ -1115,8 +1115,48 @@
     // Collection API
 
     public Document listCollections(String userId, CallMeta callMeta)
-        throws ArtifactDatabaseException {
-        throw new ArtifactDatabaseException("Not implemented, yet!");
+        throws ArtifactDatabaseException
+    {
+        ArtifactCollectionFactory acf = getArtifactCollectionFactory();
+
+        if (acf == null) {
+            throw new ArtifactDatabaseException(NO_SUCH_FACTORY);
+        }
+
+        logger.debug("Fetch the list of collection for user: " + userId);
+
+        ArtifactCollection [] ac = backend.listCollections(userId, acf);
+
+        Document result = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            result,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element root = ec.create("artifact-collections");
+        result.appendChild(root);
+
+        if (ac == null || ac.length == 0) {
+            logger.debug("No collections for the user existing.");
+
+            return result;
+        }
+
+        logger.debug("Found " + ac.length + " collections of the user.");
+
+        for (ArtifactCollection c: ac) {
+            Element collection = ec.create("artifact-collection");
+            ec.addAttr(collection, "name", c.getName());
+            ec.addAttr(collection, "uuid", c.identifier());
+            ec.addAttr(
+                collection, "creation",
+                Long.toString(c.getCreationTime().getTime()));
+
+            root.appendChild(collection);
+        }
+
+        return result;
     }
 
     public Document createCollection(String ownerId, Document data,

http://dive4elements.wald.intevation.org