1 | /** |
---|
2 | * |
---|
3 | */ |
---|
4 | package de.mpiwg.itgroup.annotations; |
---|
5 | |
---|
6 | import java.util.Set; |
---|
7 | |
---|
8 | import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; |
---|
9 | |
---|
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 | /** |
---|
41 | * The types of annotation target fragments. |
---|
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 | |
---|
53 | |
---|
54 | /** |
---|
55 | * The uri of the resource that is annotated e.g. a book. |
---|
56 | * The target is part of this resource e.g. a page of a book. |
---|
57 | */ |
---|
58 | protected String resourceUri; |
---|
59 | |
---|
60 | /** |
---|
61 | * The creator of this annotation. |
---|
62 | */ |
---|
63 | protected Actor creator; |
---|
64 | |
---|
65 | /** |
---|
66 | * The creation date of this annotation. |
---|
67 | */ |
---|
68 | protected String created; |
---|
69 | |
---|
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; |
---|
93 | |
---|
94 | /** |
---|
95 | * List of tags on this Annotation. |
---|
96 | */ |
---|
97 | protected Set<String> tags; |
---|
98 | |
---|
99 | /** |
---|
100 | * Returns if the requested action is allowed for the given user on this annotation. |
---|
101 | * |
---|
102 | * @param action |
---|
103 | * @param user |
---|
104 | * @param store AnnotationStore to check group membership |
---|
105 | * @return |
---|
106 | */ |
---|
107 | public boolean isActionAllowed(String action, Person user, AnnotationStore store) { |
---|
108 | if (action.equals("read")) { |
---|
109 | Actor reader = getReadPermission(); |
---|
110 | if (reader == null) { |
---|
111 | // if not specified then everybody is allowed |
---|
112 | return true; |
---|
113 | } else { |
---|
114 | return reader.isEquivalentWith(user, store); |
---|
115 | } |
---|
116 | } else if (action.equals("update")) { |
---|
117 | // require at least an authenticated user |
---|
118 | if (user == null) return false; |
---|
119 | Actor updater = getUpdatePermission(); |
---|
120 | if (updater == null) { |
---|
121 | // if not specified then everybody is allowed |
---|
122 | return true; |
---|
123 | } else { |
---|
124 | return updater.isEquivalentWith(user, store); |
---|
125 | } |
---|
126 | } else if (action.equals("delete")) { |
---|
127 | // require at least an authenticated user |
---|
128 | if (user == null) return false; |
---|
129 | Actor deleter = getDeletePermission(); |
---|
130 | if (deleter == null) { |
---|
131 | // if not specified then only creator is allowed |
---|
132 | deleter = creator; |
---|
133 | } |
---|
134 | return deleter.isEquivalentWith(user, store); |
---|
135 | } else if (action.equals("admin")) { |
---|
136 | // require at least an authenticated user |
---|
137 | if (user == null) return false; |
---|
138 | Actor admin = getAdminPermission(); |
---|
139 | if (admin == null) { |
---|
140 | // if not specified then only creator is allowed |
---|
141 | admin = creator; |
---|
142 | } |
---|
143 | return admin.isEquivalentWith(user, store); |
---|
144 | } |
---|
145 | return false; |
---|
146 | } |
---|
147 | |
---|
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 | /** |
---|
233 | * @return the resourceUri |
---|
234 | */ |
---|
235 | public String getResourceUri() { |
---|
236 | return resourceUri; |
---|
237 | } |
---|
238 | |
---|
239 | /** |
---|
240 | * @param resourceUri the resourceUri to set |
---|
241 | */ |
---|
242 | public void setResourceUri(String resourceUri) { |
---|
243 | this.resourceUri = resourceUri; |
---|
244 | } |
---|
245 | |
---|
246 | /** |
---|
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 | /** |
---|
261 | * @return the creatorUri |
---|
262 | */ |
---|
263 | public String getCreatorUri() { |
---|
264 | if (creator != null) { |
---|
265 | return creator.getUri(); |
---|
266 | } |
---|
267 | return null; |
---|
268 | } |
---|
269 | |
---|
270 | /** |
---|
271 | * @return the creatorName |
---|
272 | */ |
---|
273 | public String getCreatorName() { |
---|
274 | if (creator != null) { |
---|
275 | return creator.getName(); |
---|
276 | } |
---|
277 | return null; |
---|
278 | } |
---|
279 | |
---|
280 | /** |
---|
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 | } |
---|
293 | |
---|
294 | /** |
---|
295 | * @return the adminPermission |
---|
296 | */ |
---|
297 | public Actor getAdminPermission() { |
---|
298 | if (adminPermission != null) { |
---|
299 | return adminPermission; |
---|
300 | } else { |
---|
301 | // if not specified then only creator is allowed |
---|
302 | return this.creator; |
---|
303 | } |
---|
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() { |
---|
317 | if (deletePermission != null) { |
---|
318 | return deletePermission; |
---|
319 | } else { |
---|
320 | // if not specified then only creator is allowed |
---|
321 | return this.creator; |
---|
322 | } |
---|
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 | } |
---|
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 | } |
---|
373 | |
---|
374 | |
---|
375 | } |
---|