1 | /** |
---|
2 | * |
---|
3 | */ |
---|
4 | package de.mpiwg.itgroup.annotations; |
---|
5 | |
---|
6 | import java.util.List; |
---|
7 | import java.util.Set; |
---|
8 | |
---|
9 | import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; |
---|
10 | |
---|
11 | /** |
---|
12 | * @author casties |
---|
13 | * |
---|
14 | */ |
---|
15 | public class Annotation { |
---|
16 | /** |
---|
17 | * The URI of this annotation. |
---|
18 | */ |
---|
19 | protected String uri; |
---|
20 | |
---|
21 | /** |
---|
22 | * The annotation (body) text. |
---|
23 | */ |
---|
24 | protected String bodyText; |
---|
25 | |
---|
26 | /** |
---|
27 | * The URI of the annotation text |
---|
28 | */ |
---|
29 | protected String bodyUri; |
---|
30 | |
---|
31 | /** |
---|
32 | * The base URI of the annotation target. |
---|
33 | */ |
---|
34 | protected String targetBaseUri; |
---|
35 | |
---|
36 | /** |
---|
37 | * The fragment part of the annotation target. |
---|
38 | */ |
---|
39 | protected String targetFragment; |
---|
40 | |
---|
41 | /** |
---|
42 | * The types of annotation targets. |
---|
43 | * |
---|
44 | */ |
---|
45 | public static enum FragmentTypes { |
---|
46 | XPOINTER, AREA |
---|
47 | }; |
---|
48 | |
---|
49 | /** |
---|
50 | * The type of the annotation target fragment. |
---|
51 | */ |
---|
52 | protected FragmentTypes fragmentType; |
---|
53 | |
---|
54 | /** |
---|
55 | * The creator of this annotation. |
---|
56 | */ |
---|
57 | protected Actor creator; |
---|
58 | |
---|
59 | /** |
---|
60 | * The creation date of this annotation. |
---|
61 | */ |
---|
62 | protected String created; |
---|
63 | |
---|
64 | /** |
---|
65 | * The user or group that has admin permissions. |
---|
66 | * null means any user. |
---|
67 | */ |
---|
68 | protected Actor adminPermission; |
---|
69 | |
---|
70 | /** |
---|
71 | * The user or group that has delete permissions. |
---|
72 | * null means any user. |
---|
73 | */ |
---|
74 | protected Actor deletePermission; |
---|
75 | |
---|
76 | /** |
---|
77 | * The user or group that has update permissions. |
---|
78 | * null means any user. |
---|
79 | */ |
---|
80 | protected Actor updatePermission; |
---|
81 | |
---|
82 | /** |
---|
83 | * The user or group that has read permissions. |
---|
84 | * null means any user. |
---|
85 | */ |
---|
86 | protected Actor readPermission; |
---|
87 | |
---|
88 | /** |
---|
89 | * List of tags on this Annotation. |
---|
90 | */ |
---|
91 | protected Set<String> tags; |
---|
92 | |
---|
93 | /** |
---|
94 | * Returns if the requested action is allowed on this annotation. |
---|
95 | * |
---|
96 | * @param action |
---|
97 | * @param user |
---|
98 | * @param store AnnotationStore to check group membership |
---|
99 | * @return |
---|
100 | */ |
---|
101 | public boolean isActionAllowed(String action, Person user, AnnotationStore store) { |
---|
102 | if (action.equals("read")) { |
---|
103 | Actor reader = getReadPermission(); |
---|
104 | if (reader == null) { |
---|
105 | return true; |
---|
106 | } else { |
---|
107 | return reader.isEquivalentWith(user, store); |
---|
108 | } |
---|
109 | } else if (action.equals("update")) { |
---|
110 | // require at least an authenticated user |
---|
111 | if (user == null) return false; |
---|
112 | Actor updater = getUpdatePermission(); |
---|
113 | if (updater == null) { |
---|
114 | return true; |
---|
115 | } else { |
---|
116 | return updater.isEquivalentWith(user, store); |
---|
117 | } |
---|
118 | } else if (action.equals("delete")) { |
---|
119 | // require at least an authenticated user |
---|
120 | if (user == null) return false; |
---|
121 | Actor updater = getUpdatePermission(); |
---|
122 | if (updater == null) { |
---|
123 | return true; |
---|
124 | } else { |
---|
125 | return updater.isEquivalentWith(user, store); |
---|
126 | } |
---|
127 | } else if (action.equals("admin")) { |
---|
128 | // require at least an authenticated user |
---|
129 | if (user == null) return false; |
---|
130 | Actor admin = getAdminPermission(); |
---|
131 | if (admin == null) { |
---|
132 | return true; |
---|
133 | } else { |
---|
134 | return admin.isEquivalentWith(user, store); |
---|
135 | } |
---|
136 | } |
---|
137 | return false; |
---|
138 | } |
---|
139 | |
---|
140 | /** |
---|
141 | * @return the uri |
---|
142 | */ |
---|
143 | public String getUri() { |
---|
144 | return uri; |
---|
145 | } |
---|
146 | |
---|
147 | /** |
---|
148 | * @param uri the uri to set |
---|
149 | */ |
---|
150 | public void setUri(String uri) { |
---|
151 | this.uri = uri; |
---|
152 | } |
---|
153 | |
---|
154 | /** |
---|
155 | * @return the bodyText |
---|
156 | */ |
---|
157 | public String getBodyText() { |
---|
158 | return bodyText; |
---|
159 | } |
---|
160 | |
---|
161 | /** |
---|
162 | * @param bodyText the bodyText to set |
---|
163 | */ |
---|
164 | public void setBodyText(String bodyText) { |
---|
165 | this.bodyText = bodyText; |
---|
166 | } |
---|
167 | |
---|
168 | /** |
---|
169 | * @return the bodyUri |
---|
170 | */ |
---|
171 | public String getBodyUri() { |
---|
172 | return bodyUri; |
---|
173 | } |
---|
174 | |
---|
175 | /** |
---|
176 | * @param bodyUri the bodyUri to set |
---|
177 | */ |
---|
178 | public void setBodyUri(String bodyUri) { |
---|
179 | this.bodyUri = bodyUri; |
---|
180 | } |
---|
181 | |
---|
182 | /** |
---|
183 | * @return the targetBaseUri |
---|
184 | */ |
---|
185 | public String getTargetBaseUri() { |
---|
186 | return targetBaseUri; |
---|
187 | } |
---|
188 | |
---|
189 | /** |
---|
190 | * @param targetBaseUri the targetBaseUri to set |
---|
191 | */ |
---|
192 | public void setTargetBaseUri(String targetBaseUri) { |
---|
193 | this.targetBaseUri = targetBaseUri; |
---|
194 | } |
---|
195 | |
---|
196 | /** |
---|
197 | * @return the targetFragment |
---|
198 | */ |
---|
199 | public String getTargetFragment() { |
---|
200 | return targetFragment; |
---|
201 | } |
---|
202 | |
---|
203 | /** |
---|
204 | * @param targetFragment the targetFragment to set |
---|
205 | */ |
---|
206 | public void setTargetFragment(String targetFragment) { |
---|
207 | this.targetFragment = targetFragment; |
---|
208 | } |
---|
209 | |
---|
210 | /** |
---|
211 | * @return the targetType |
---|
212 | */ |
---|
213 | public FragmentTypes getFragmentType() { |
---|
214 | return fragmentType; |
---|
215 | } |
---|
216 | |
---|
217 | /** |
---|
218 | * @param fragmentType the fragmentType to set |
---|
219 | */ |
---|
220 | public void setFragmentType(FragmentTypes fragmentType) { |
---|
221 | this.fragmentType = fragmentType; |
---|
222 | } |
---|
223 | |
---|
224 | /** |
---|
225 | * @return the creator |
---|
226 | */ |
---|
227 | public Actor getCreator() { |
---|
228 | return creator; |
---|
229 | } |
---|
230 | |
---|
231 | /** |
---|
232 | * @param creator the creator to set |
---|
233 | */ |
---|
234 | public void setCreator(Actor creator) { |
---|
235 | this.creator = creator; |
---|
236 | } |
---|
237 | |
---|
238 | /** |
---|
239 | * @return the creatorUri |
---|
240 | */ |
---|
241 | public String getCreatorUri() { |
---|
242 | if (creator != null) { |
---|
243 | return creator.getUri(); |
---|
244 | } |
---|
245 | return null; |
---|
246 | } |
---|
247 | |
---|
248 | /** |
---|
249 | * @return the creatorName |
---|
250 | */ |
---|
251 | public String getCreatorName() { |
---|
252 | if (creator != null) { |
---|
253 | return creator.getName(); |
---|
254 | } |
---|
255 | return null; |
---|
256 | } |
---|
257 | |
---|
258 | /** |
---|
259 | * @return the created |
---|
260 | */ |
---|
261 | public String getCreated() { |
---|
262 | return created; |
---|
263 | } |
---|
264 | |
---|
265 | /** |
---|
266 | * @param created the created to set |
---|
267 | */ |
---|
268 | public void setCreated(String created) { |
---|
269 | this.created = created; |
---|
270 | } |
---|
271 | |
---|
272 | /** |
---|
273 | * @return the adminPermission |
---|
274 | */ |
---|
275 | public Actor getAdminPermission() { |
---|
276 | return adminPermission; |
---|
277 | } |
---|
278 | |
---|
279 | /** |
---|
280 | * @param adminPermission the adminPermission to set |
---|
281 | */ |
---|
282 | public void setAdminPermission(Actor adminPermission) { |
---|
283 | this.adminPermission = adminPermission; |
---|
284 | } |
---|
285 | |
---|
286 | /** |
---|
287 | * @return the deletePermission |
---|
288 | */ |
---|
289 | public Actor getDeletePermission() { |
---|
290 | return deletePermission; |
---|
291 | } |
---|
292 | |
---|
293 | /** |
---|
294 | * @param deletePermission the deletePermission to set |
---|
295 | */ |
---|
296 | public void setDeletePermission(Actor deletePermission) { |
---|
297 | this.deletePermission = deletePermission; |
---|
298 | } |
---|
299 | |
---|
300 | /** |
---|
301 | * @return the updatePermission |
---|
302 | */ |
---|
303 | public Actor getUpdatePermission() { |
---|
304 | return updatePermission; |
---|
305 | } |
---|
306 | |
---|
307 | /** |
---|
308 | * @param updatePermission the updatePermission to set |
---|
309 | */ |
---|
310 | public void setUpdatePermission(Actor updatePermission) { |
---|
311 | this.updatePermission = updatePermission; |
---|
312 | } |
---|
313 | |
---|
314 | /** |
---|
315 | * @return the readPermission |
---|
316 | */ |
---|
317 | public Actor getReadPermission() { |
---|
318 | return readPermission; |
---|
319 | } |
---|
320 | |
---|
321 | /** |
---|
322 | * @param readPermission the readPermission to set |
---|
323 | */ |
---|
324 | public void setReadPermission(Actor readPermission) { |
---|
325 | this.readPermission = readPermission; |
---|
326 | } |
---|
327 | |
---|
328 | /** |
---|
329 | * @return the tags |
---|
330 | */ |
---|
331 | public Set<String> getTags() { |
---|
332 | return tags; |
---|
333 | } |
---|
334 | |
---|
335 | /** |
---|
336 | * @param tags the tags to set |
---|
337 | */ |
---|
338 | public void setTags(Set<String> tags) { |
---|
339 | this.tags = tags; |
---|
340 | } |
---|
341 | |
---|
342 | |
---|
343 | } |
---|