changeset 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 72de5c373c9b
children d9a99b28a847
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java
diffstat 3 files changed, 51 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri May 27 08:11:34 2011 +0000
+++ b/ChangeLog	Fri May 27 08:47:31 2011 +0000
@@ -1,3 +1,16 @@
+2011-05-27  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
+	  The setCollectionAttribute() method will now set the incoming document
+	  as new attribute for the collection. Before, we looked for a xpath
+	  expression that contained the attribute. In the current implementation,
+	  the incoming document IS the attribute.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java:
+	  Extract the new attribute for a collection and call the
+	  setCollectionAttribute() method of ArtifactDatabase with this document
+	  instead of calling it with the incoming request document.
+
 2011-05-27  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Fri May 27 08:11:34 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Fri May 27 08:47:31 2011 +0000
@@ -1284,20 +1284,7 @@
         Document attribute)
     throws ArtifactDatabaseException
     {
-        logger.debug("Set the attribute for the collection: " + collectionId);
-
-        Document attributes = null;
-
-        Node attr = (Node) XMLUtils.xpath(
-            attribute,
-            XPATH_COLLECTION_ATTRIBUTE,
-            XPathConstants.NODE,
-            ArtifactNamespaceContext.INSTANCE);
-
-        if (attr != null) {
-            attributes = XMLUtils.newDocument();
-            attributes.appendChild(attributes.importNode(attr, true));
-        }
+        logger.debug("Set new attribute for the collection: " + collectionId);
 
         Document result = XMLUtils.newDocument();
 
@@ -1310,7 +1297,7 @@
         result.appendChild(root);
 
         boolean success = backend.setCollectionAttribute(
-            collectionId, attributes);
+            collectionId, attribute);
 
         root.setTextContent(success ? OPERATION_SUCCESSFUL: OPERATION_FAILURE);
 
--- 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