# HG changeset patch # User Ingo Weinzierl # Date 1299149673 0 # Node ID d718a4d55662b7f9a549cb741e209cd4bcb04045 # Parent 6e6965873a48e6d598cabcadf665bacc8bd26058 Implemented the createCollection() method in the artifact database. artifacts/trunk@1383 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 6e6965873a48 -r d718a4d55662 ChangeLog --- 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 + + * 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 * artifacts/src/main/java/de/intevation/artifacts/UserFactory.java: diff -r 6e6965873a48 -r d718a4d55662 artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.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) diff -r 6e6965873a48 -r d718a4d55662 artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java --- 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; }