Mercurial > hg > AnnotationManagerN4J
annotate src/main/java/de/mpiwg/itgroup/annotations/Annotation.java @ 14:629e15b345aa
permissions mostly work. need more server-side checking.
author | casties |
---|---|
date | Fri, 13 Jul 2012 20:41:02 +0200 |
parents | 90911b2da322 |
children | 58357a4b86de |
rev | line source |
---|---|
4 | 1 /** |
2 * | |
3 */ | |
4 package de.mpiwg.itgroup.annotations; | |
5 | |
6 /** | |
7 * @author casties | |
8 * | |
9 */ | |
10 public class Annotation { | |
11 /** | |
12 * The URI of this annotation. | |
13 */ | |
14 protected String uri; | |
15 | |
16 /** | |
17 * The annotation (body) text. | |
18 */ | |
19 protected String bodyText; | |
20 | |
21 /** | |
22 * The URI of the annotation text | |
23 */ | |
24 protected String bodyUri; | |
25 | |
26 /** | |
27 * The base URI of the annotation target. | |
28 */ | |
29 protected String targetBaseUri; | |
30 | |
31 /** | |
32 * The fragment part of the annotation target. | |
33 */ | |
34 protected String targetFragment; | |
35 | |
36 /** | |
37 * The types of annotation targets. | |
38 * | |
39 */ | |
40 public static enum FragmentTypes { | |
41 XPOINTER, AREA | |
42 }; | |
43 | |
44 /** | |
45 * The type of the annotation target fragment. | |
46 */ | |
47 protected FragmentTypes fragmentType; | |
48 | |
49 /** | |
9 | 50 * The creator of this annotation. |
4 | 51 */ |
9 | 52 protected Actor creator; |
5 | 53 |
54 /** | |
4 | 55 * The creation date of this annotation. |
56 */ | |
57 protected String created; | |
58 | |
10 | 59 /** |
60 * The user or group that has admin permissions. | |
61 * null means any user. | |
62 */ | |
63 protected Actor adminPermission; | |
64 | |
65 /** | |
66 * The user or group that has delete permissions. | |
67 * null means any user. | |
68 */ | |
69 protected Actor deletePermission; | |
70 | |
71 /** | |
72 * The user or group that has update permissions. | |
73 * null means any user. | |
74 */ | |
75 protected Actor updatePermission; | |
76 | |
77 /** | |
78 * The user or group that has read permissions. | |
79 * null means any user. | |
80 */ | |
81 protected Actor readPermission; | |
8 | 82 |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
83 |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
84 /** |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
85 * Returns if the requested action is allowed on this annotation. |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
86 * |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
87 * @param action |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
88 * @param userId |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
89 * @return |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
90 */ |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
91 public boolean isActionAllowed(String action, String userId) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
92 if (action.equals("read")) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
93 Actor reader = getReadPermission(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
94 if (reader == null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
95 return true; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
96 } else { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
97 return reader.isEquivalentWith(userId); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
98 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
99 } else if (action.equals("update")) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
100 // require at least an authenticated user |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
101 if (userId == null) return false; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
102 Actor updater = getUpdatePermission(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
103 if (updater == null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
104 return true; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
105 } else { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
106 return updater.isEquivalentWith(userId); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
107 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
108 } else if (action.equals("delete")) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
109 // require at least an authenticated user |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
110 if (userId == null) return false; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
111 Actor updater = getUpdatePermission(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
112 if (updater == null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
113 return true; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
114 } else { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
115 return updater.isEquivalentWith(userId); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
116 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
117 } else if (action.equals("admin")) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
118 // require at least an authenticated user |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
119 if (userId == null) return false; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
120 Actor admin = getAdminPermission(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
121 if (admin == null) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
122 return true; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
123 } else { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
124 return admin.isEquivalentWith(userId); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
125 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
126 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
127 return false; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
128 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
129 |
4 | 130 /** |
131 * @return the uri | |
132 */ | |
133 public String getUri() { | |
134 return uri; | |
135 } | |
136 | |
137 /** | |
138 * @param uri the uri to set | |
139 */ | |
140 public void setUri(String uri) { | |
141 this.uri = uri; | |
142 } | |
143 | |
144 /** | |
145 * @return the bodyText | |
146 */ | |
147 public String getBodyText() { | |
148 return bodyText; | |
149 } | |
150 | |
151 /** | |
152 * @param bodyText the bodyText to set | |
153 */ | |
154 public void setBodyText(String bodyText) { | |
155 this.bodyText = bodyText; | |
156 } | |
157 | |
158 /** | |
159 * @return the bodyUri | |
160 */ | |
161 public String getBodyUri() { | |
162 return bodyUri; | |
163 } | |
164 | |
165 /** | |
166 * @param bodyUri the bodyUri to set | |
167 */ | |
168 public void setBodyUri(String bodyUri) { | |
169 this.bodyUri = bodyUri; | |
170 } | |
171 | |
172 /** | |
173 * @return the targetBaseUri | |
174 */ | |
175 public String getTargetBaseUri() { | |
176 return targetBaseUri; | |
177 } | |
178 | |
179 /** | |
180 * @param targetBaseUri the targetBaseUri to set | |
181 */ | |
182 public void setTargetBaseUri(String targetBaseUri) { | |
183 this.targetBaseUri = targetBaseUri; | |
184 } | |
185 | |
186 /** | |
187 * @return the targetFragment | |
188 */ | |
189 public String getTargetFragment() { | |
190 return targetFragment; | |
191 } | |
192 | |
193 /** | |
194 * @param targetFragment the targetFragment to set | |
195 */ | |
196 public void setTargetFragment(String targetFragment) { | |
197 this.targetFragment = targetFragment; | |
198 } | |
199 | |
200 /** | |
201 * @return the targetType | |
202 */ | |
203 public FragmentTypes getFragmentType() { | |
204 return fragmentType; | |
205 } | |
206 | |
207 /** | |
208 * @param fragmentType the fragmentType to set | |
209 */ | |
210 public void setFragmentType(FragmentTypes fragmentType) { | |
211 this.fragmentType = fragmentType; | |
212 } | |
213 | |
214 /** | |
9 | 215 * @return the creator |
216 */ | |
217 public Actor getCreator() { | |
218 return creator; | |
219 } | |
220 | |
221 /** | |
222 * @param creator the creator to set | |
223 */ | |
224 public void setCreator(Actor creator) { | |
225 this.creator = creator; | |
226 } | |
227 | |
228 /** | |
4 | 229 * @return the creatorUri |
230 */ | |
231 public String getCreatorUri() { | |
9 | 232 if (creator != null) { |
233 return creator.getUri(); | |
234 } | |
235 return null; | |
4 | 236 } |
237 | |
238 /** | |
5 | 239 * @return the creatorName |
240 */ | |
241 public String getCreatorName() { | |
9 | 242 if (creator != null) { |
243 return creator.getName(); | |
244 } | |
245 return null; | |
5 | 246 } |
247 | |
248 /** | |
4 | 249 * @return the created |
250 */ | |
251 public String getCreated() { | |
252 return created; | |
253 } | |
254 | |
255 /** | |
256 * @param created the created to set | |
257 */ | |
258 public void setCreated(String created) { | |
259 this.created = created; | |
260 } | |
10 | 261 |
262 /** | |
263 * @return the adminPermission | |
264 */ | |
265 public Actor getAdminPermission() { | |
266 return adminPermission; | |
267 } | |
268 | |
269 /** | |
270 * @param adminPermission the adminPermission to set | |
271 */ | |
272 public void setAdminPermission(Actor adminPermission) { | |
273 this.adminPermission = adminPermission; | |
274 } | |
275 | |
276 /** | |
277 * @return the deletePermission | |
278 */ | |
279 public Actor getDeletePermission() { | |
280 return deletePermission; | |
281 } | |
282 | |
283 /** | |
284 * @param deletePermission the deletePermission to set | |
285 */ | |
286 public void setDeletePermission(Actor deletePermission) { | |
287 this.deletePermission = deletePermission; | |
288 } | |
289 | |
290 /** | |
291 * @return the updatePermission | |
292 */ | |
293 public Actor getUpdatePermission() { | |
294 return updatePermission; | |
295 } | |
296 | |
297 /** | |
298 * @param updatePermission the updatePermission to set | |
299 */ | |
300 public void setUpdatePermission(Actor updatePermission) { | |
301 this.updatePermission = updatePermission; | |
302 } | |
303 | |
304 /** | |
305 * @return the readPermission | |
306 */ | |
307 public Actor getReadPermission() { | |
308 return readPermission; | |
309 } | |
310 | |
311 /** | |
312 * @param readPermission the readPermission to set | |
313 */ | |
314 public void setReadPermission(Actor readPermission) { | |
315 this.readPermission = readPermission; | |
316 } | |
4 | 317 |
318 | |
319 } |