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