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