# HG changeset patch # User Ingo Weinzierl # Date 1299139648 0 # Node ID 7e5619115d5b4471bbc9f15c839941a341976538 # Parent 3d70de111af14428dde518e59dd39e0a7c659598 Implemented the deleteUser() method in the artifact server. artifacts/trunk@1377 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 3d70de111af1 -r 7e5619115d5b ChangeLog --- a/ChangeLog Thu Mar 03 08:04:57 2011 +0000 +++ b/ChangeLog Thu Mar 03 08:07:28 2011 +0000 @@ -1,3 +1,10 @@ +2011-03-03 Ingo Weinzierl + + * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java: + Implemented the deleteUser() interface method. This operation will now + remove the specified user, its collections and the artifacts stored in + these collections. + 2011-03-03 Ingo Weinzierl * artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java: diff -r 3d70de111af1 -r 7e5619115d5b 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:04:57 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Thu Mar 03 08:07:28 2011 +0000 @@ -176,6 +176,10 @@ public static final String XPATH_USERROLE = "/art:action/art:user/art:role"; + /** Error message if a specified user does not exist.*/ + public static final String NO_SUCH_USER = + "No such user"; + /** Error message if no username is given for user creation.*/ public static final String NO_USERNAME = "Invalid username"; @@ -961,6 +965,7 @@ for (User user: users) { Element ue = ec.create("user"); + ec.addAttr(ue, "uuid", user.identifier()); ec.addAttr(ue, "name", user.getName()); // TODO append the role of the user. @@ -1022,8 +1027,29 @@ } public Document deleteUser(String userId, CallMeta callMeta) - throws ArtifactDatabaseException { - throw new ArtifactDatabaseException("Not implemented, yet!"); + throws ArtifactDatabaseException + { + UserFactory factory = getUserFactory(); + + if (factory == null) { + throw new ArtifactDatabaseException(NO_SUCH_FACTORY); + } + + User toDelete = factory.getUser(userId, context); + + if (toDelete == null) { + logger.warn("There is no user with the uuid: " + userId); + throw new ArtifactDatabaseException(NO_SUCH_USER); + } + + logger.debug( + "Remove user: " + toDelete.getName() + + "(" + toDelete.identifier() + ")"); + + factory.deleteUser(toDelete, context); + + // FIXME Return a useful document! + return XMLUtils.newDocument(); }