Mercurial > hg > AnnotationManagerN4J
annotate src/main/java/de/mpiwg/itgroup/annotations/Annotation.java @ 50:64aa756c60cc
annotations ui can show and delete annotations now.
author | casties |
---|---|
date | Thu, 27 Sep 2012 17:12:08 +0200 |
parents | 0e00bf8e27fb |
children | 2b1e6df5e21a |
rev | line source |
---|---|
4 | 1 /** |
2 * | |
3 */ | |
4 package de.mpiwg.itgroup.annotations; | |
5 | |
50 | 6 import java.io.UnsupportedEncodingException; |
16 | 7 import java.util.Set; |
8 | |
50 | 9 import org.apache.commons.codec.binary.Base64; |
10 | |
15 | 11 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; |
12 | |
4 | 13 /** |
14 * @author casties | |
15 * | |
16 */ | |
17 public class Annotation { | |
18 /** | |
19 * The URI of this annotation. | |
20 */ | |
21 protected String uri; | |
22 | |
23 /** | |
24 * The annotation (body) text. | |
25 */ | |
26 protected String bodyText; | |
27 | |
28 /** | |
29 * The URI of the annotation text | |
30 */ | |
31 protected String bodyUri; | |
32 | |
33 /** | |
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
34 * The annotation target. |
4 | 35 */ |
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
36 protected Target target; |
4 | 37 |
38 /** | |
39 * The fragment part of the annotation target. | |
40 */ | |
41 protected String targetFragment; | |
42 | |
43 /** | |
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
44 * The types of annotation target fragments. |
4 | 45 * |
46 */ | |
47 public static enum FragmentTypes { | |
48 XPOINTER, AREA | |
49 }; | |
50 | |
51 /** | |
52 * The type of the annotation target fragment. | |
53 */ | |
54 protected FragmentTypes fragmentType; | |
55 | |
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
56 |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
57 /** |
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
58 * The Resource that is annotated e.g. a book. |
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
59 * The target is part of this resource e.g. a page of a book. |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
60 */ |
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
61 protected Resource resource; |
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
62 |
4 | 63 /** |
9 | 64 * The creator of this annotation. |
4 | 65 */ |
9 | 66 protected Actor creator; |
5 | 67 |
68 /** | |
4 | 69 * The creation date of this annotation. |
70 */ | |
71 protected String created; | |
72 | |
10 | 73 /** |
74 * The user or group that has admin permissions. | |
75 * null means any user. | |
76 */ | |
77 protected Actor adminPermission; | |
78 | |
79 /** | |
80 * The user or group that has delete permissions. | |
81 * null means any user. | |
82 */ | |
83 protected Actor deletePermission; | |
84 | |
85 /** | |
86 * The user or group that has update permissions. | |
87 * null means any user. | |
88 */ | |
89 protected Actor updatePermission; | |
90 | |
91 /** | |
92 * The user or group that has read permissions. | |
93 * null means any user. | |
94 */ | |
95 protected Actor readPermission; | |
16 | 96 |
97 /** | |
98 * List of tags on this Annotation. | |
99 */ | |
100 protected Set<String> tags; | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
101 |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
102 /** |
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
103 * Returns if the requested action is allowed for the given user on this annotation. |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
104 * |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
105 * @param action |
15 | 106 * @param user |
107 * @param store AnnotationStore to check group membership | |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
108 * @return |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
109 */ |
15 | 110 public boolean isActionAllowed(String action, Person user, AnnotationStore store) { |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
111 if (action.equals("read")) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
112 Actor reader = getReadPermission(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
113 if (reader == null) { |
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
114 // if not specified then everybody is allowed |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
115 return true; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
116 } else { |
15 | 117 return reader.isEquivalentWith(user, store); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
118 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
119 } else if (action.equals("update")) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
120 // require at least an authenticated user |
15 | 121 if (user == null) return false; |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
122 Actor updater = getUpdatePermission(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
123 if (updater == null) { |
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
124 // if not specified then everybody is allowed |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
125 return true; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
126 } else { |
15 | 127 return updater.isEquivalentWith(user, store); |
14
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 } else if (action.equals("delete")) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
130 // require at least an authenticated user |
15 | 131 if (user == null) return false; |
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
132 Actor deleter = getDeletePermission(); |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
133 if (deleter == null) { |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
134 // if not specified then only creator is allowed |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
135 deleter = creator; |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
136 } |
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
137 return deleter.isEquivalentWith(user, store); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
138 } else if (action.equals("admin")) { |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
139 // require at least an authenticated user |
15 | 140 if (user == null) return false; |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
141 Actor admin = getAdminPermission(); |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
142 if (admin == null) { |
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
143 // if not specified then only creator is allowed |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
144 admin = creator; |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
145 } |
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
146 return admin.isEquivalentWith(user, store); |
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
147 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
148 return false; |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
149 } |
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
150 |
4 | 151 /** |
152 * @return the uri | |
153 */ | |
154 public String getUri() { | |
155 return uri; | |
156 } | |
157 | |
158 /** | |
159 * @param uri the uri to set | |
160 */ | |
161 public void setUri(String uri) { | |
162 this.uri = uri; | |
163 } | |
164 | |
165 /** | |
50 | 166 * Returns an URL-compatible id. |
167 * Currently the uri as base64 encoded string. | |
168 * @return | |
169 */ | |
170 public String getUrlId() { | |
171 if (uri == null) return null; | |
172 try { | |
173 return Base64.encodeBase64URLSafeString(uri.getBytes("UTF-8")); | |
174 } catch (UnsupportedEncodingException e) { | |
175 return null; | |
176 } | |
177 } | |
178 | |
179 public static String decodeId(String id) { | |
180 if (id == null) return null; | |
181 try { | |
182 return new String(Base64.decodeBase64(id), "UTF-8"); | |
183 } catch (UnsupportedEncodingException e) { | |
184 return null; | |
185 } | |
186 } | |
187 | |
188 /** | |
4 | 189 * @return the bodyText |
190 */ | |
191 public String getBodyText() { | |
192 return bodyText; | |
193 } | |
194 | |
195 /** | |
196 * @param bodyText the bodyText to set | |
197 */ | |
198 public void setBodyText(String bodyText) { | |
199 this.bodyText = bodyText; | |
200 } | |
201 | |
202 /** | |
203 * @return the bodyUri | |
204 */ | |
205 public String getBodyUri() { | |
206 return bodyUri; | |
207 } | |
208 | |
209 /** | |
210 * @param bodyUri the bodyUri to set | |
211 */ | |
212 public void setBodyUri(String bodyUri) { | |
213 this.bodyUri = bodyUri; | |
214 } | |
215 | |
216 /** | |
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
217 * @return the target |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
218 */ |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
219 public Target getTarget() { |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
220 return target; |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
221 } |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
222 |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
223 /** |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
224 * @param target the target to set |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
225 */ |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
226 public void setTarget(Target target) { |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
227 this.target = target; |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
228 } |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
229 |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
230 /** |
4 | 231 * @return the targetBaseUri |
232 */ | |
233 public String getTargetBaseUri() { | |
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
234 if (target == null) return null; |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
235 return target.getUri(); |
4 | 236 } |
237 | |
238 /** | |
239 * @return the targetFragment | |
240 */ | |
241 public String getTargetFragment() { | |
242 return targetFragment; | |
243 } | |
244 | |
245 /** | |
246 * @param targetFragment the targetFragment to set | |
247 */ | |
248 public void setTargetFragment(String targetFragment) { | |
249 this.targetFragment = targetFragment; | |
250 } | |
251 | |
252 /** | |
253 * @return the targetType | |
254 */ | |
255 public FragmentTypes getFragmentType() { | |
256 return fragmentType; | |
257 } | |
258 | |
259 /** | |
260 * @param fragmentType the fragmentType to set | |
261 */ | |
262 public void setFragmentType(FragmentTypes fragmentType) { | |
263 this.fragmentType = fragmentType; | |
264 } | |
265 | |
266 /** | |
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
267 * @return the resource |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
268 */ |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
269 public Resource getResource() { |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
270 return resource; |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
271 } |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
272 |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
273 /** |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
274 * @param resource the resource to set |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
275 */ |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
276 public void setResource(Resource resource) { |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
277 this.resource = resource; |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
278 } |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
279 |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
280 /** |
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
281 * @return the resourceUri |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
282 */ |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
283 public String getResourceUri() { |
48
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
284 if (resource == null) return null; |
0e00bf8e27fb
targets and resources of Annotation object are objects now.
casties
parents:
40
diff
changeset
|
285 return resource.getUri(); |
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
286 } |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
287 |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
288 /** |
9 | 289 * @return the creator |
290 */ | |
291 public Actor getCreator() { | |
292 return creator; | |
293 } | |
294 | |
295 /** | |
296 * @param creator the creator to set | |
297 */ | |
298 public void setCreator(Actor creator) { | |
299 this.creator = creator; | |
300 } | |
301 | |
302 /** | |
4 | 303 * @return the creatorUri |
304 */ | |
305 public String getCreatorUri() { | |
9 | 306 if (creator != null) { |
307 return creator.getUri(); | |
308 } | |
309 return null; | |
4 | 310 } |
311 | |
312 /** | |
5 | 313 * @return the creatorName |
314 */ | |
315 public String getCreatorName() { | |
9 | 316 if (creator != null) { |
317 return creator.getName(); | |
318 } | |
319 return null; | |
5 | 320 } |
321 | |
322 /** | |
4 | 323 * @return the created |
324 */ | |
325 public String getCreated() { | |
326 return created; | |
327 } | |
328 | |
329 /** | |
330 * @param created the created to set | |
331 */ | |
332 public void setCreated(String created) { | |
333 this.created = created; | |
334 } | |
10 | 335 |
336 /** | |
337 * @return the adminPermission | |
338 */ | |
339 public Actor getAdminPermission() { | |
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
340 if (adminPermission != null) { |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
341 return adminPermission; |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
342 } else { |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
343 // if not specified then only creator is allowed |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
344 return this.creator; |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
345 } |
10 | 346 } |
347 | |
348 /** | |
349 * @param adminPermission the adminPermission to set | |
350 */ | |
351 public void setAdminPermission(Actor adminPermission) { | |
352 this.adminPermission = adminPermission; | |
353 } | |
354 | |
355 /** | |
356 * @return the deletePermission | |
357 */ | |
358 public Actor getDeletePermission() { | |
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
359 if (deletePermission != null) { |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
360 return deletePermission; |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
361 } else { |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
362 // if not specified then only creator is allowed |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
363 return this.creator; |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
364 } |
10 | 365 } |
366 | |
367 /** | |
368 * @param deletePermission the deletePermission to set | |
369 */ | |
370 public void setDeletePermission(Actor deletePermission) { | |
371 this.deletePermission = deletePermission; | |
372 } | |
373 | |
374 /** | |
375 * @return the updatePermission | |
376 */ | |
377 public Actor getUpdatePermission() { | |
378 return updatePermission; | |
379 } | |
380 | |
381 /** | |
382 * @param updatePermission the updatePermission to set | |
383 */ | |
384 public void setUpdatePermission(Actor updatePermission) { | |
385 this.updatePermission = updatePermission; | |
386 } | |
387 | |
388 /** | |
389 * @return the readPermission | |
390 */ | |
391 public Actor getReadPermission() { | |
392 return readPermission; | |
393 } | |
394 | |
395 /** | |
396 * @param readPermission the readPermission to set | |
397 */ | |
398 public void setReadPermission(Actor readPermission) { | |
399 this.readPermission = readPermission; | |
400 } | |
16 | 401 |
402 /** | |
403 * @return the tags | |
404 */ | |
405 public Set<String> getTags() { | |
406 return tags; | |
407 } | |
408 | |
409 /** | |
410 * @param tags the tags to set | |
411 */ | |
412 public void setTags(Set<String> tags) { | |
413 this.tags = tags; | |
414 } | |
4 | 415 |
416 | |
417 } |