Mercurial > hg > AnnotationManagerN4J
annotate src/main/java/de/mpiwg/itgroup/annotations/Annotation.java @ 40:03e0f7574224
saving and loading resource targets should work now (no searching yet)
author | casties |
---|---|
date | Wed, 26 Sep 2012 14:56:42 +0200 |
parents | 715aa11d138b |
children | 0e00bf8e27fb |
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 /** | |
31 * The base URI of the annotation target. | |
32 */ | |
33 protected String targetBaseUri; | |
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 /** |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
55 * The uri of the resource that is annotated e.g. a book. |
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 */ |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
58 protected String resourceUri; |
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 /** | |
191 * @return the targetBaseUri | |
192 */ | |
193 public String getTargetBaseUri() { | |
194 return targetBaseUri; | |
195 } | |
196 | |
197 /** | |
198 * @param targetBaseUri the targetBaseUri to set | |
199 */ | |
200 public void setTargetBaseUri(String targetBaseUri) { | |
201 this.targetBaseUri = targetBaseUri; | |
202 } | |
203 | |
204 /** | |
205 * @return the targetFragment | |
206 */ | |
207 public String getTargetFragment() { | |
208 return targetFragment; | |
209 } | |
210 | |
211 /** | |
212 * @param targetFragment the targetFragment to set | |
213 */ | |
214 public void setTargetFragment(String targetFragment) { | |
215 this.targetFragment = targetFragment; | |
216 } | |
217 | |
218 /** | |
219 * @return the targetType | |
220 */ | |
221 public FragmentTypes getFragmentType() { | |
222 return fragmentType; | |
223 } | |
224 | |
225 /** | |
226 * @param fragmentType the fragmentType to set | |
227 */ | |
228 public void setFragmentType(FragmentTypes fragmentType) { | |
229 this.fragmentType = fragmentType; | |
230 } | |
231 | |
232 /** | |
40
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
233 * @return the resourceUri |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
234 */ |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
235 public String getResourceUri() { |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
236 return resourceUri; |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
237 } |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
238 |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
239 /** |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
240 * @param resourceUri the resourceUri to set |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
241 */ |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
242 public void setResourceUri(String resourceUri) { |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
243 this.resourceUri = resourceUri; |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
244 } |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
245 |
03e0f7574224
saving and loading resource targets should work now (no searching yet)
casties
parents:
20
diff
changeset
|
246 /** |
9 | 247 * @return the creator |
248 */ | |
249 public Actor getCreator() { | |
250 return creator; | |
251 } | |
252 | |
253 /** | |
254 * @param creator the creator to set | |
255 */ | |
256 public void setCreator(Actor creator) { | |
257 this.creator = creator; | |
258 } | |
259 | |
260 /** | |
4 | 261 * @return the creatorUri |
262 */ | |
263 public String getCreatorUri() { | |
9 | 264 if (creator != null) { |
265 return creator.getUri(); | |
266 } | |
267 return null; | |
4 | 268 } |
269 | |
270 /** | |
5 | 271 * @return the creatorName |
272 */ | |
273 public String getCreatorName() { | |
9 | 274 if (creator != null) { |
275 return creator.getName(); | |
276 } | |
277 return null; | |
5 | 278 } |
279 | |
280 /** | |
4 | 281 * @return the created |
282 */ | |
283 public String getCreated() { | |
284 return created; | |
285 } | |
286 | |
287 /** | |
288 * @param created the created to set | |
289 */ | |
290 public void setCreated(String created) { | |
291 this.created = created; | |
292 } | |
10 | 293 |
294 /** | |
295 * @return the adminPermission | |
296 */ | |
297 public Actor getAdminPermission() { | |
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
298 if (adminPermission != null) { |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
299 return adminPermission; |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
300 } else { |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
301 // if not specified then only creator is allowed |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
302 return this.creator; |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
303 } |
10 | 304 } |
305 | |
306 /** | |
307 * @param adminPermission the adminPermission to set | |
308 */ | |
309 public void setAdminPermission(Actor adminPermission) { | |
310 this.adminPermission = adminPermission; | |
311 } | |
312 | |
313 /** | |
314 * @return the deletePermission | |
315 */ | |
316 public Actor getDeletePermission() { | |
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
317 if (deletePermission != null) { |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
318 return deletePermission; |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
319 } else { |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
320 // if not specified then only creator is allowed |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
321 return this.creator; |
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
322 } |
10 | 323 } |
324 | |
325 /** | |
326 * @param deletePermission the deletePermission to set | |
327 */ | |
328 public void setDeletePermission(Actor deletePermission) { | |
329 this.deletePermission = deletePermission; | |
330 } | |
331 | |
332 /** | |
333 * @return the updatePermission | |
334 */ | |
335 public Actor getUpdatePermission() { | |
336 return updatePermission; | |
337 } | |
338 | |
339 /** | |
340 * @param updatePermission the updatePermission to set | |
341 */ | |
342 public void setUpdatePermission(Actor updatePermission) { | |
343 this.updatePermission = updatePermission; | |
344 } | |
345 | |
346 /** | |
347 * @return the readPermission | |
348 */ | |
349 public Actor getReadPermission() { | |
350 return readPermission; | |
351 } | |
352 | |
353 /** | |
354 * @param readPermission the readPermission to set | |
355 */ | |
356 public void setReadPermission(Actor readPermission) { | |
357 this.readPermission = readPermission; | |
358 } | |
16 | 359 |
360 /** | |
361 * @return the tags | |
362 */ | |
363 public Set<String> getTags() { | |
364 return tags; | |
365 } | |
366 | |
367 /** | |
368 * @param tags the tags to set | |
369 */ | |
370 public void setTags(Set<String> tags) { | |
371 this.tags = tags; | |
372 } | |
4 | 373 |
374 | |
375 } |