changeset 153:bf596b83d984

Adjusted method signatures for deleting users in the UserFactory and in the Backend. artifacts/trunk@1378 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 03 Mar 2011 08:51:02 +0000
parents 7e5619115d5b
children 1a72f08ce8d7
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultUserFactory.java artifacts/src/main/java/de/intevation/artifacts/UserFactory.java
diffstat 5 files changed, 47 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Mar 03 08:07:28 2011 +0000
+++ b/ChangeLog	Thu Mar 03 08:51:02 2011 +0000
@@ -1,3 +1,16 @@
+2011-03-03  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultUserFactory.java,
+	  artifacts/src/main/java/de/intevation/artifacts/UserFactory.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java:
+	  Adapted the signature of deleteUser(). These methods don't await a User
+	  object any longer but just its identifier.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
+	  Performance improvement: there is no need to fetch the user that we want
+	  to delete from database before deleting it. Now, we just call the
+	  deleteUser() method of the UserFactory with the identifier of the user.
+
 2011-03-03  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Mar 03 08:07:28 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Mar 03 08:51:02 2011 +0000
@@ -56,6 +56,14 @@
     private static Logger logger =
         Logger.getLogger(ArtifactDatabaseImpl.class);
 
+    /** Message that is returned if an operation was successful.*/
+    public static final String OPERATION_SUCCESSFUL =
+        "SUCCESS";
+
+    /** Message that is returned if an operation failed.*/
+    public static final String OPERATION_FAILURE =
+        "FAILURE";
+
     /**
      * Error message issued if a requested artifact factory
      * is not registered to this database.
@@ -1015,10 +1023,10 @@
         Element root = ec.create("result");
 
         if (newUser != null) {
-            root.setTextContent("SUCCESS");
+            root.setTextContent(OPERATION_SUCCESSFUL);
         }
         else {
-            root.setTextContent("FAILURE");
+            root.setTextContent(OPERATION_FAILURE);
         }
 
         result.appendChild(root);
@@ -1035,21 +1043,28 @@
             throw new ArtifactDatabaseException(NO_SUCH_FACTORY);
         }
 
-        User toDelete = factory.getUser(userId, context);
+        logger.debug("Delete user: " + userId);
 
-        if (toDelete == null) {
-            logger.warn("There is no user with the uuid: " + userId);
-            throw new ArtifactDatabaseException(NO_SUCH_USER);
+        Document result = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            result,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element root = ec.create("result");
+        result.appendChild(root);
+
+        try {
+            factory.deleteUser(userId, context);
+            root.setTextContent(OPERATION_SUCCESSFUL);
+        }
+        catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            root.setTextContent(OPERATION_FAILURE);
         }
 
-        logger.debug(
-            "Remove user: " + toDelete.getName() +
-            "(" + toDelete.identifier() + ")");
-
-        factory.deleteUser(toDelete, context);
-
-        // FIXME Return a useful document!
-        return XMLUtils.newDocument();
+        return result;
     }
 
 
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Thu Mar 03 08:07:28 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Thu Mar 03 08:51:02 2011 +0000
@@ -895,14 +895,12 @@
         return null;
     }
 
-    public void deleteUser(User user) {
+    public void deleteUser(String identifier) {
 
         Connection        conn   = null;
         ResultSet         result = null;
         PreparedStatement stmnt  = null;
 
-        String identifier = user.identifier();
-
         if (!StringUtils.checkUUID(identifier)) {
             return;
         }
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultUserFactory.java	Thu Mar 03 08:07:28 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultUserFactory.java	Thu Mar 03 08:51:02 2011 +0000
@@ -67,10 +67,10 @@
      * @param user The user to be deleted.
      * @param context The CallContext.
      */
-    public void deleteUser(User user, Object context) {
-        logger.debug("DefaultUserFactory.deleteUser: " + user.identifier());
+    public void deleteUser(String identifier, Object context) {
+        logger.debug("DefaultUserFactory.deleteUser: " + identifier);
 
-        Backend.getInstance().deleteUser(user);
+        Backend.getInstance().deleteUser(identifier);
     }
 
 
--- a/artifacts/src/main/java/de/intevation/artifacts/UserFactory.java	Thu Mar 03 08:07:28 2011 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/UserFactory.java	Thu Mar 03 08:51:02 2011 +0000
@@ -16,7 +16,7 @@
 
     User createUser(String name, Document role, Object context);
 
-    void deleteUser(User user, Object context);
+    void deleteUser(String identifier, Object context);
 
     User getUser(String identifier, Object context);
 

http://dive4elements.wald.intevation.org