Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 415:d4a846ee35b8
Implement ArtifactDatabase findUser method
artifacts/trunk@5262 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 24 Aug 2012 14:08:31 +0000 |
parents | f4b14240ffa3 |
children | 410a1bfb9590 |
comparison
equal
deleted
inserted
replaced
414:c22f3a7640d7 | 415:d4a846ee35b8 |
---|---|
195 | 195 |
196 /** XPath to figure out the role of a new user.*/ | 196 /** XPath to figure out the role of a new user.*/ |
197 public static final String XPATH_USERROLE = | 197 public static final String XPATH_USERROLE = |
198 "/art:action/art:user/art:role"; | 198 "/art:action/art:user/art:role"; |
199 | 199 |
200 /** XPath to figure out the role of a new user.*/ | 200 /** XPath to figure out the account of a new user.*/ |
201 public static final String XPATH_USERACCOUNT = | 201 public static final String XPATH_USERACCOUNT = |
202 "/art:action/art:user/art:account/@name"; | 202 "/art:action/art:user/art:account/@name"; |
203 | |
204 /** XPath to figure out the account of when searching for a user .*/ | |
205 public static final String XPATH_USERACCOUNT_FIND = | |
206 "/art:action/art:account/@name"; | |
203 | 207 |
204 /** Error message if a specified user does not exist.*/ | 208 /** Error message if a specified user does not exist.*/ |
205 public static final String NO_SUCH_USER = | 209 public static final String NO_SUCH_USER = |
206 "No such user"; | 210 "No such user"; |
207 | 211 |
1233 } | 1237 } |
1234 | 1238 |
1235 return result; | 1239 return result; |
1236 } | 1240 } |
1237 | 1241 |
1242 /** Search for a user. */ | |
1243 public Document findUser(Document data, CallMeta callMeta) | |
1244 throws ArtifactDatabaseException | |
1245 { | |
1246 UserFactory factory = getUserFactory(); | |
1247 | |
1248 if (factory == null) { | |
1249 throw new ArtifactDatabaseException(NO_SUCH_FACTORY); | |
1250 } | |
1251 | |
1252 String account = XMLUtils.xpathString( | |
1253 data, XPATH_USERACCOUNT_FIND, ArtifactNamespaceContext.INSTANCE); | |
1254 | |
1255 if (account == null || account.length() == 0) { | |
1256 logger.warn("Can't find user without account!"); | |
1257 throw new ArtifactDatabaseException(NO_USERACCOUNT); | |
1258 } | |
1259 | |
1260 User user = backend.findUser(account, factory, context); | |
1261 | |
1262 Document result = XMLUtils.newDocument(); | |
1263 | |
1264 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
1265 result, | |
1266 ArtifactNamespaceContext.NAMESPACE_URI, | |
1267 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
1268 | |
1269 Element ue = ec.create("user"); | |
1270 | |
1271 if (user != null) { | |
1272 logger.debug(user + " user found in the backend."); | |
1273 | |
1274 ec.addAttr(ue, "uuid", user.identifier(), true); | |
1275 ec.addAttr(ue, "name", user.getName(), true); | |
1276 Element ua = ec.create("account"); | |
1277 ec.addAttr(ua, "name", user.getAccount(), true); | |
1278 ue.appendChild(ua); | |
1279 | |
1280 Document role = user.getRole(); | |
1281 | |
1282 if (role != null) { | |
1283 ue.appendChild(result.importNode(role.getFirstChild(), true)); | |
1284 } | |
1285 } | |
1286 | |
1287 result.appendChild(ue); | |
1288 | |
1289 return result; | |
1290 } | |
1291 | |
1238 public Document createUser(Document data, CallMeta callMeta) | 1292 public Document createUser(Document data, CallMeta callMeta) |
1239 throws ArtifactDatabaseException | 1293 throws ArtifactDatabaseException |
1240 { | 1294 { |
1241 UserFactory factory = getUserFactory(); | 1295 UserFactory factory = getUserFactory(); |
1242 | 1296 |
1253 } | 1307 } |
1254 | 1308 |
1255 String account = XMLUtils.xpathString( | 1309 String account = XMLUtils.xpathString( |
1256 data, XPATH_USERACCOUNT, ArtifactNamespaceContext.INSTANCE); | 1310 data, XPATH_USERACCOUNT, ArtifactNamespaceContext.INSTANCE); |
1257 | 1311 |
1258 if (name == null || name.length() == 0) { | 1312 if (account == null || account.length() == 0) { |
1259 logger.warn("User without account not accepted!"); | 1313 logger.warn("User without account not accepted!"); |
1260 throw new ArtifactDatabaseException(NO_USERACCOUNT); | 1314 throw new ArtifactDatabaseException(NO_USERACCOUNT); |
1261 } | 1315 } |
1262 | 1316 |
1263 Node tmp = (Node) XMLUtils.xpath( | 1317 Node tmp = (Node) XMLUtils.xpath( |