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