changeset 160:dc687827439f

Enabled the artifact database to store and load roles of users. artifacts/trunk@1385 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 03 Mar 2011 12:17:27 +0000
parents db0d20440b92
children e4a1562dfc21
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java
diffstat 2 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Mar 03 12:13:24 2011 +0000
+++ b/ChangeLog	Thu Mar 03 12:17:27 2011 +0000
@@ -1,3 +1,8 @@
+2011-03-03  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
+	  The roles of users are stored into and loaded from database now.
+
 2011-03-03	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* artifact-database/src/main/resources/sql/org-h2-driver.properties,
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Mar 03 12:13:24 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Mar 03 12:17:27 2011 +0000
@@ -37,6 +37,8 @@
 import java.util.HashSet;
 import java.util.List;
 
+import javax.xml.xpath.XPathConstants;
+
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.codec.binary.Hex;
 
@@ -44,6 +46,7 @@
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 
 /**
  * The core implementation of artifact database. This layer exposes
@@ -1005,8 +1008,14 @@
             ec.addAttr(ue, "uuid", user.identifier());
             ec.addAttr(ue, "name", user.getName());
 
-            // TODO append the role of the user.
+            Document role = user.getRole();
+
+            if (role != null) {
+                ue.appendChild(result.importNode(role.getFirstChild(), true));
+            }
+
             root.appendChild(ue);
+
         }
 
         return result;
@@ -1029,9 +1038,19 @@
             throw new ArtifactDatabaseException(NO_USERNAME);
         }
 
-        // TODO Extract the role is contained as node in the xml document.
+        Node tmp = (Node) XMLUtils.xpath(
+            data,
+            XPATH_USERROLE,
+            XPathConstants.NODE,
+            ArtifactNamespaceContext.INSTANCE);
+
         Document role = XMLUtils.newDocument();
 
+        if (tmp != null) {
+            Node    clone = role.importNode(tmp, true);
+            role.appendChild(clone);
+        }
+
         User newUser = null;
 
         try {

http://dive4elements.wald.intevation.org