changeset 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 28dea2714e90
children 81ad657569e1
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java
diffstat 3 files changed, 55 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Mar 03 14:00:12 2011 +0000
+++ b/ChangeLog	Thu Mar 03 14:28:02 2011 +0000
@@ -1,3 +1,12 @@
+2011-03-03  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java:
+	  Introduced the ArtifactCollectionFactory as parameter of
+	  listCollections().
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
+	  Implemented the interface method listCollections().
+
 2011-03-03  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifact-database/doc/example-conf/conf.xml: Corrected the attribute
--- 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,
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Thu Mar 03 14:00:12 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Thu Mar 03 14:28:02 2011 +0000
@@ -1197,7 +1197,10 @@
         return null;
     }
 
-    public ArtifactCollection [] listCollections(String userId) {
+    public ArtifactCollection [] listCollections(
+        String                    userId,
+        ArtifactCollectionFactory factory)
+    {
         // TODO: Implement me!
         return null;
     }

http://dive4elements.wald.intevation.org