diff artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java @ 268:4edaf3073109

Repaired the setting of a new attribute for a Collection. artifacts/trunk@2016 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 27 May 2011 08:47:31 +0000
parents a2df2b48d2aa
children 22a90706d32d
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java	Fri May 27 08:11:34 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java	Fri May 27 08:47:31 2011 +0000
@@ -14,8 +14,12 @@
 import de.intevation.artifacts.common.ArtifactNamespaceContext;
 import de.intevation.artifacts.common.utils.XMLUtils;
 
+import de.intevation.artifactdatabase.ArtifactDatabaseImpl;
+
 import java.io.IOException;
 
+import javax.xml.xpath.XPathConstants;
+
 import org.apache.log4j.Logger;
 
 import org.restlet.data.MediaType;
@@ -27,6 +31,7 @@
 import org.restlet.Response;
 
 import org.w3c.dom.Document;
+import org.w3c.dom.Node;
 
 
 /**
@@ -142,7 +147,10 @@
                 String art = getArtifactIdentifier(source);
 
                 logger.info("Set attribute for collection '" + identifier + "'");
-                out = db.setCollectionAttribute(identifier, meta, source);
+
+                Document attr = getCollectionAttribute(source);
+
+                out = db.setCollectionAttribute(identifier, meta, attr);
             }
             else if (action.equals(ACTION_SET_ITEM_ATTRIBUTE)) {
                 String art = getArtifactIdentifier(source);
@@ -226,4 +234,31 @@
         return XMLUtils.xpathString(
             source, XPATH_ARTIFACT, ArtifactNamespaceContext.INSTANCE);
     }
+
+
+    /**
+     * Returns the attribute for a collection of the incoming request document.
+     *
+     * @param request The request document.
+     *
+     * @return the contained attribute as document.
+     */
+    protected Document getCollectionAttribute(Document request) {
+        Node attr = (Node) XMLUtils.xpath(
+            request,
+            ArtifactDatabaseImpl.XPATH_COLLECTION_ATTRIBUTE,
+            XPathConstants.NODE,
+            ArtifactNamespaceContext.INSTANCE);
+
+        Document newAttr = XMLUtils.newDocument();
+
+        if (attr == null) {
+            logger.error("Collection attribute document not found!");
+            return newAttr;
+        }
+
+        newAttr.appendChild(newAttr.importNode(attr, true));
+
+        return newAttr;
+    }
 }

http://dive4elements.wald.intevation.org