Mercurial > dive4elements > framework
diff artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 152:7e5619115d5b
Implemented the deleteUser() method in the artifact server.
artifacts/trunk@1377 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 03 Mar 2011 08:07:28 +0000 |
parents | 78a27a6b3f1f |
children | bf596b83d984 |
line wrap: on
line diff
--- 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(); }