Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/LazyBackendUser.java @ 416:733e76413bf8
Add REST service to be able to find a user by its account name
artifacts/trunk@5263 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 24 Aug 2012 14:09:53 +0000 |
parents | 4748949c4f19 |
children |
rev | line source |
---|---|
165
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 /* |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 * Copyright (c) 2011 by Intevation GmbH |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 * |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 */ |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 package de.intevation.artifactdatabase; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.artifacts.User; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.artifacts.UserFactory; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import org.w3c.dom.Document; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 public class LazyBackendUser |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 implements User |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 { |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 protected UserFactory factory; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 protected Backend backend; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 protected String identifier; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 protected User user; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 protected Object context; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 public LazyBackendUser( |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 String identifier, |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
26 UserFactory factory, |
165
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 Backend backend, |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 Object context |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 ) { |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 this.identifier = identifier; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 this.factory = factory; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 this.backend = backend; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 this.context = context; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 } |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 protected User getUser() { |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 if (user == null) { |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 user = backend.getUser(identifier, factory, context); |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 if (user == null) { |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 throw new IllegalStateException("loading user failed"); |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 } |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 } |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 return user; |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 } |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
409
4748949c4f19
Extend user class implementations to handle account information
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
233
diff
changeset
|
46 @Override |
165
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 public String identifier() { |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 return getUser().identifier(); |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 } |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
409
4748949c4f19
Extend user class implementations to handle account information
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
233
diff
changeset
|
51 @Override |
165
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 public String getName() { |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 return getUser().getName(); |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 } |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
409
4748949c4f19
Extend user class implementations to handle account information
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
233
diff
changeset
|
56 @Override |
165
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 public void setName(String name) { |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 getUser().setName(name); |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 } |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
409
4748949c4f19
Extend user class implementations to handle account information
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
233
diff
changeset
|
61 @Override |
165
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 public void setIdentifier(String identifier) { |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 getUser().setIdentifier(identifier); |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 } |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 |
409
4748949c4f19
Extend user class implementations to handle account information
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
233
diff
changeset
|
66 @Override |
165
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 public Document getRole() { |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 return getUser().getRole(); |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 } |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
409
4748949c4f19
Extend user class implementations to handle account information
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
233
diff
changeset
|
71 @Override |
165
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 public void setRole(Document document) { |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 getUser().setRole(document); |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 } |
409
4748949c4f19
Extend user class implementations to handle account information
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
233
diff
changeset
|
75 |
4748949c4f19
Extend user class implementations to handle account information
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
233
diff
changeset
|
76 @Override |
4748949c4f19
Extend user class implementations to handle account information
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
233
diff
changeset
|
77 public String getAccount() { |
4748949c4f19
Extend user class implementations to handle account information
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
233
diff
changeset
|
78 return getUser().getAccount(); |
4748949c4f19
Extend user class implementations to handle account information
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
233
diff
changeset
|
79 } |
165
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 } |
81ad657569e1
Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |