changeset 157:6e6965873a48

Simplified creation of users. artifacts/trunk@1382 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 03 Mar 2011 10:33:49 +0000
parents a76de72ad6d1
children d718a4d55662
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, 39 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Mar 03 09:53:02 2011 +0000
+++ b/ChangeLog	Thu Mar 03 10:33:49 2011 +0000
@@ -1,3 +1,17 @@
+2011-03-03	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* artifacts/src/main/java/de/intevation/artifacts/UserFactory.java:
+	  Throw out useless stuff from interface.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultUserFactory.java:
+	  Adjusted default implementation.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java:
+	  Use user factory to create new users.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
+	  Call the backend with the new semantic.
+
 2011-03-03	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Mar 03 09:53:02 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Mar 03 10:33:49 2011 +0000
@@ -971,7 +971,7 @@
             throw new ArtifactDatabaseException(NO_SUCH_FACTORY);
         }
 
-        User[] users = factory.getUsers(context);
+        User [] users = backend.getUsers(factory, context);
 
         if (users != null) {
             logger.debug(users.length + " users found in the backend.");
@@ -1022,7 +1022,7 @@
         User newUser = null;
 
         try {
-            newUser = factory.createUser(name, role, context);
+            newUser = backend.createUser(name, role, userFactory, context);
         }
         catch (Exception e) {
             logger.error(e.getMessage(), e);
@@ -1053,12 +1053,6 @@
     public Document deleteUser(String userId, CallMeta callMeta)
         throws ArtifactDatabaseException
     {
-        UserFactory factory = getUserFactory();
-
-        if (factory == null) {
-            throw new ArtifactDatabaseException(NO_SUCH_FACTORY);
-        }
-
         logger.debug("Delete user: " + userId);
 
         Document result = XMLUtils.newDocument();
@@ -1071,7 +1065,7 @@
         Element root = ec.create("result");
         result.appendChild(root);
 
-        boolean success = factory.deleteUser(userId, context);
+        boolean success = backend.deleteUser(userId);
 
         root.setTextContent(success ? OPERATION_SUCCESSFUL: OPERATION_FAILURE);
 
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Thu Mar 03 09:53:02 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Thu Mar 03 10:33:49 2011 +0000
@@ -8,10 +8,12 @@
 
 package de.intevation.artifactdatabase;
 
+import de.intevation.artifacts.ArtifactCollection;
 import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.ArtifactFactory;
 import de.intevation.artifacts.ArtifactSerializer;
 import de.intevation.artifacts.User;
+import de.intevation.artifacts.UserFactory;
 
 import de.intevation.artifacts.common.utils.XMLUtils;
 
@@ -818,8 +820,10 @@
     }
 
     public User createUser(
-        String   name, 
-        Document role
+        String      name, 
+        Document    role,
+        UserFactory factory,
+        Object      context
     ) {
         Connection        connection    = null;
         PreparedStatement stmnt_next_id = null;
@@ -864,7 +868,7 @@
 
                 connection.commit();
 
-                return new DefaultUser(identifier, name, role);
+                return factory.createUser(identifier, name, role, context);
             }
             catch (SQLException sqle) {
                 connection.rollback();
@@ -985,8 +989,11 @@
         return false;
     }
 
-    public User getUser(String identifier) {
-
+    public User getUser(
+        String      identifier, 
+        UserFactory factory,
+        Object      context
+    ) {
         Connection        conn   = null;
         ResultSet         result = null;
         PreparedStatement stmnt  = null;
@@ -1011,7 +1018,7 @@
 
             Document role = XMLUtils.fromByteArray(roleData);
 
-            return new DefaultUser(identifier, name, role);
+            return factory.createUser(identifier, name, role, context);
         }
         catch (SQLException sqle) {
             logger.error(sqle.getLocalizedMessage(), sqle);
@@ -1034,7 +1041,7 @@
         return null;
     }
 
-    public User [] getUsers() {
+    public User [] getUsers(UserFactory factory, Object context) {
         Connection        conn   = null;
         ResultSet         result = null;
         PreparedStatement stmnt  = null;
@@ -1054,7 +1061,8 @@
                 byte [] roleData   = result.getBytes(4);
 
                 Document role = XMLUtils.fromByteArray(roleData);
-                User     user = new DefaultUser(identifier, name, role);
+                User     user =
+                    factory.createUser(identifier, name, role, context);
                 users.add(user);
             }
 
@@ -1081,12 +1089,12 @@
         return null;
     }
 
-    public Collection [] listCollections(String userId) {
+    public ArtifactCollection [] listCollections(String userId) {
         // TODO: Implement me!
         return null;
     }
 
-    public Collection createCollection(String ownerId, Document data) {
+    public ArtifactCollection createCollection(String ownerId, Document data) {
         // TODO: Implement me!
         return null;
     }
@@ -1129,7 +1137,7 @@
         return false;
     }
 
-    public Collection [] listCollectionArtifacts(String collectionId) {
+    public ArtifactCollection [] listCollectionArtifacts(String collectionId) {
         // TODO: Implement me!
         return null;
     }
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultUserFactory.java	Thu Mar 03 09:53:02 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultUserFactory.java	Thu Mar 03 10:33:49 2011 +0000
@@ -51,55 +51,13 @@
      * @param context The CallContext.
      */
     public User createUser(
+        String   identifier,
         String   name,
         Document role,
         Object   context)
     {
         logger.debug("DefaultUserFactory.createUser: " + name);
-
-        return Backend.getInstance().createUser(name, role);
-    }
-
-
-    /**
-     * Deletes the given user.
-     *
-     * @param user The user to be deleted.
-     * @param context The CallContext.
-     */
-    public boolean deleteUser(String identifier, Object context) {
-        logger.debug("DefaultUserFactory.deleteUser: " + identifier);
-
-        return Backend.getInstance().deleteUser(identifier);
-    }
-
-
-    /**
-     * Returns the user with the given identifier.
-     *
-     * @param identifier The identifier of a user.
-     * @param context The CallContext.
-     *
-     * @return the user with the given identifier.
-     */
-    public User getUser(String identifier, Object context) {
-        logger.debug("DefaultUserFactory.getUser: " + identifier);
-
-        return Backend.getInstance().getUser(identifier);
-    }
-
-
-    /**
-     * Returns a list of users available for this application.
-     *
-     * @param context The CallContext.
-     *
-     * @return a list of users.
-     */
-    public User [] getUsers(Object context) {
-        logger.debug("DefaultUserFactory.getUsers");
-
-        return Backend.getInstance().getUsers();
+        return new DefaultUser(identifier, name, role);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifacts/src/main/java/de/intevation/artifacts/UserFactory.java	Thu Mar 03 09:53:02 2011 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/UserFactory.java	Thu Mar 03 10:33:49 2011 +0000
@@ -14,12 +14,6 @@
 {
     void setup(Document config, Node factoryNode);
 
-    User createUser(String name, Document role, Object context);
-
-    boolean deleteUser(String identifier, Object context);
-
-    User getUser(String identifier, Object context);
-
-    User [] getUsers(Object context);
+    User createUser(String identifier, String name, Document role, Object context);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org