changeset 189:fbaeb5931d10

Implemented addCollectionArtifact() and listCollectionArtifacts() of the artifact database. artifacts/trunk@1419 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 07 Mar 2011 16:30:45 +0000
parents 946e2245a6c0
children 7acf4a325bfe
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java
diffstat 4 files changed, 78 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Mar 07 16:24:27 2011 +0000
+++ b/ChangeLog	Mon Mar 07 16:30:45 2011 +0000
@@ -1,3 +1,15 @@
+2011-03-07  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java,
+	  artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java:
+	  Modified the method signature of addCollectionArtifact(). This method
+	  got the incoming document as further parameter.
+	  Furthermore, listCollectionArtifacts() and addCollectionArtifact() are
+	  implemented now.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java:
+	  Adapted the method call of addCollectionArtifact().
+
 2011-03-07  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultCollectionItem.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Mon Mar 07 16:24:27 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Mon Mar 07 16:30:45 2011 +0000
@@ -20,6 +20,7 @@
 import de.intevation.artifacts.ArtifactSerializer;
 import de.intevation.artifacts.CallContext;
 import de.intevation.artifacts.CallMeta;
+import de.intevation.artifacts.CollectionItem;
 import de.intevation.artifacts.Service;
 import de.intevation.artifacts.ServiceFactory;
 import de.intevation.artifacts.User;
@@ -213,6 +214,13 @@
     public static final String XPATH_COLLECTION_NAME =
         "/art:action/art:type/art:collection/@name";
 
+    /**
+     * XPath to figure out the attributes for an artifact that is put into a
+     * collection.
+     */
+    public static final String XPATH_COLLECTION_ITEM_ATTRIBUTE =
+        "/art:action/art:type/art:artifact/art:attribute";
+
 
     /**
      * Inner class that implements the call context handed
@@ -1242,16 +1250,32 @@
         throw new ArtifactDatabaseException("Not implemented, yet!");
     }
 
-    public Document addCollectionArtifact(String collectionId, String artifactId,
-        CallMeta callMeta) throws ArtifactDatabaseException
+    public Document addCollectionArtifact(
+        String   collectionId,
+        String   artifactId,
+        Document input,
+        CallMeta callMeta)
+    throws ArtifactDatabaseException
     {
         logger.debug(
             "Add artifact '" + artifactId + "' collection '" +collectionId+"'");
 
+        Document attr = XMLUtils.newDocument();
+
+        Node attrNode = (Node) XMLUtils.xpath(
+            input,
+            XPATH_COLLECTION_ITEM_ATTRIBUTE,
+            XPathConstants.NODE,
+            ArtifactNamespaceContext.INSTANCE);
+
+        if (attrNode != null) {
+            attr.appendChild(attr.importNode(attrNode, true));
+        }
+
         boolean success = backend.addCollectionArtifact(
             collectionId,
             artifactId,
-            null); // XXX: Needed to be extracted from input
+            attr);
 
         Document result = XMLUtils.newDocument();
 
@@ -1274,8 +1298,43 @@
     }
 
     public Document listCollectionArtifacts(String collectionId,
-        CallMeta callMeta) throws ArtifactDatabaseException {
-        throw new ArtifactDatabaseException("Not implemented, yet!");
+        CallMeta callMeta) throws ArtifactDatabaseException
+    {
+        CollectionItem[] items = backend.listCollectionArtifacts(collectionId);
+
+        Document result = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            result,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element root = ec.create("result");
+        Element ac   = ec.create("artifact-collection");
+        ec.addAttr(ac, "uuid", collectionId, true);
+
+        for (CollectionItem item: items) {
+            Element i    = ec.create("collection-item");
+            Element attr = ec.create("attribute");
+            ec.addAttr(i, "uuid", item.getArtifactIdentifier(), true);
+
+            Document attribute = item.getAttribute();
+            if (attribute != null) {
+                Node firstChild = attribute.getFirstChild();
+                attr.appendChild(result.importNode(firstChild, true));
+            }
+            else {
+                logger.debug("No attributes for the collection item!");
+            }
+
+            i.appendChild(attr);
+            ac.appendChild(i);
+        }
+
+        root.appendChild(ac);
+        result.appendChild(root);
+
+        return result;
     }
 
     public DeferredOutput outCollection(String collectionId,
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java	Mon Mar 07 16:24:27 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java	Mon Mar 07 16:30:45 2011 +0000
@@ -112,7 +112,7 @@
                 String art = getArtifactIdentifier(source);
 
                 logger.info("Add artifact '" + art + "' to collection.");
-                out = db.addCollectionArtifact(identifier, art, meta);
+                out = db.addCollectionArtifact(identifier, art, source, meta);
             }
             else if (action.equals(ACTION_REMOVE_ARTIFACT)) {
                 String art = getArtifactIdentifier(source);
--- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java	Mon Mar 07 16:24:27 2011 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java	Mon Mar 07 16:30:45 2011 +0000
@@ -211,7 +211,7 @@
         throws ArtifactDatabaseException;
 
     Document addCollectionArtifact(String collectionId, String artifactId,
-        CallMeta callMeta) throws ArtifactDatabaseException;
+        Document input, CallMeta callMeta) throws ArtifactDatabaseException;
 
     Document removeCollectionArtifact(String collectionId, String artifactId,
         CallMeta callMeta) throws ArtifactDatabaseException;

http://dive4elements.wald.intevation.org