changeset 158:d718a4d55662

Implemented the createCollection() method in the artifact database. artifacts/trunk@1383 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 03 Mar 2011 10:54:33 +0000
parents 6e6965873a48
children db0d20440b92
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, 59 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Mar 03 10:33:49 2011 +0000
+++ b/ChangeLog	Thu Mar 03 10:54:33 2011 +0000
@@ -1,3 +1,13 @@
+2011-03-03  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java:
+	  Changed the method signature of createCollection(). The Backend needs
+	  the ArtifactCollectionFactory to create new instances of artifact
+	  collections.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
+	  Implemented the interface method createCollection().
+
 2011-03-03	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* artifacts/src/main/java/de/intevation/artifacts/UserFactory.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Mar 03 10:33:49 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Mar 03 10:54:33 2011 +0000
@@ -11,6 +11,7 @@
 import de.intevation.artifactdatabase.Backend.PersistentArtifact;
 
 import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.ArtifactCollection;
 import de.intevation.artifacts.ArtifactCollectionFactory;
 import de.intevation.artifacts.ArtifactDatabase;
 import de.intevation.artifacts.ArtifactDatabaseException;
@@ -193,6 +194,14 @@
     public static final String NO_USERNAME =
         "Invalid username";
 
+    // Collection constants
+
+    /**
+     * Error message issued if the creation of a collection failed.
+     */
+    public static final String COLLECTION_CREATION_FAILED =
+        "Creation of collection failed";
+
 
     /**
      * Inner class that implements the call context handed
@@ -622,6 +631,10 @@
         return userFactory;
     }
 
+    public ArtifactCollectionFactory getArtifactCollectionFactory() {
+        return collectionFactory;
+    }
+
     public Document createArtifactWithFactory(
         String   factoryName,
         CallMeta callMeta,
@@ -1082,8 +1095,34 @@
 
     public Document createCollection(String ownerId, Document data,
         CallMeta callMeta)
-        throws ArtifactDatabaseException {
-        throw new ArtifactDatabaseException("Not implemented, yet!");
+        throws ArtifactDatabaseException
+    {
+        ArtifactCollectionFactory acf = getArtifactCollectionFactory();
+
+        if (acf == null) {
+            throw new ArtifactDatabaseException(NO_SUCH_FACTORY);
+        }
+
+        ArtifactCollection ac = backend.createCollection(
+            ownerId, data, context, acf);
+
+        if (ac == null) {
+            throw new ArtifactDatabaseException(COLLECTION_CREATION_FAILED);
+        }
+
+        Document result = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            result,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element root = ec.create("result");
+        result.appendChild(root);
+
+        result.setTextContent(OPERATION_SUCCESSFUL);
+
+        return result;
     }
 
     public Document deleteCollection(String collectionId, CallMeta callMeta)
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Thu Mar 03 10:33:49 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Thu Mar 03 10:54:33 2011 +0000
@@ -8,8 +8,9 @@
 
 package de.intevation.artifactdatabase;
 
+import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.ArtifactCollection;
-import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.ArtifactCollectionFactory;
 import de.intevation.artifacts.ArtifactFactory;
 import de.intevation.artifacts.ArtifactSerializer;
 import de.intevation.artifacts.User;
@@ -1094,7 +1095,12 @@
         return null;
     }
 
-    public ArtifactCollection createCollection(String ownerId, Document data) {
+    public ArtifactCollection createCollection(
+        String                    ownerId,
+        Document                  data,
+        Object                    context,
+        ArtifactCollectionFactory factory)
+    {
         // TODO: Implement me!
         return null;
     }

http://dive4elements.wald.intevation.org