changeset 3507:59c77a9551c8

User new find-user REST service in UserClient Use new find-user REST interface to check if a user already exists in the database or a new user must be created. flys-client/trunk@5265 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 24 Aug 2012 14:14:30 +0000
parents f2a4e6e92ffd
children 60984be9bcfa
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/auth/UserClient.java
diffstat 2 files changed, 47 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Aug 24 11:42:31 2012 +0000
+++ b/flys-client/ChangeLog	Fri Aug 24 14:14:30 2012 +0000
@@ -1,3 +1,9 @@
+2012-08-24	Björn Ricks	<bjoern.ricks@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/auth/UserClient.java:
+	  Use new find-user REST interface to check if a user already exists in the
+	  database or a new user must be created.
+
 2012-08-24	Björn Ricks <bjoern.ricks@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/server/auth/UserClient.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/UserClient.java	Fri Aug 24 11:42:31 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/auth/UserClient.java	Fri Aug 24 14:14:30 2012 +0000
@@ -31,21 +31,21 @@
     }
 
     public boolean userExists(User user) throws ConnectionException {
-        NodeList users = this.listUsers();
+        Element data = this.findUser(user);
 
-        if (users == null || users.getLength() == 0) {
+        if (user == null) {
             return false;
         }
-        for(int i=0; i < users.getLength(); i++) {
-            Element usernode = (Element)users.item(i);
-            String name = usernode.getAttributeNS(
-                    ArtifactNamespaceContext.NAMESPACE_URI, "name");
+        String XPATH_USERACCOUNT = "/art:user/art:account/@name";
 
-            if (name.equals(user.getName())) {
-                return true;
-            }
+        String account = XMLUtils.xpathString(
+            data, XPATH_USERACCOUNT, ArtifactNamespaceContext.INSTANCE);
+
+        if (account == null) {
+            return false;
         }
-        return false;
+
+        return account.equals(user.getAccount());
     }
 
     public boolean createUser(User user) throws ConnectionException {
@@ -104,6 +104,37 @@
             XPathConstants.NODESET,
             ArtifactNamespaceContext.INSTANCE);
     }
+
+    public Element findUser(User user) throws ConnectionException {
+        HttpClient client = new HttpClientImpl(this.url);
+
+        Document document = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
+            document,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX
+        );
+
+        Element action = creator.create("action");
+
+        Element type = creator.create("type");
+        type.setAttribute("name", "find");
+        Element account = creator.create("account");
+        account.setAttribute("name", user.getAccount());
+
+        action.appendChild(type);
+        action.appendChild(account);
+        document.appendChild(action);
+
+        logger.debug("Find user request xml: " + XMLUtils.toString(document));
+
+        Document resp = client.findUser(document);
+
+        logger.debug("Find user request response xml: " + XMLUtils.toString(resp));
+
+        return resp.getDocumentElement();
+    }
 }
 // vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80:
 

http://dive4elements.wald.intevation.org