# HG changeset patch # User Ingo Weinzierl # Date 1299162482 0 # Node ID 268c2972d4a72973fb0370ae4b5417dea91b4966 # Parent 28dea2714e90ad1175b23fc8424381fcfc447c52 Implemented the interface method listCollections() in the artifact database. artifacts/trunk@1389 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 28dea2714e90 -r 268c2972d4a7 ChangeLog --- 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 + + * 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 * artifact-database/doc/example-conf/conf.xml: Corrected the attribute diff -r 28dea2714e90 -r 268c2972d4a7 artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java --- 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, diff -r 28dea2714e90 -r 268c2972d4a7 artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java --- 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; }