source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/Annotation.java @ 48:0e00bf8e27fb

Last change on this file since 48:0e00bf8e27fb was 48:0e00bf8e27fb, checked in by casties, 12 years ago

targets and resources of Annotation object are objects now.

File size: 8.5 KB
Line 
1/**
2 *
3 */
4package de.mpiwg.itgroup.annotations;
5
6import java.util.Set;
7
8import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
9
10/**
11 * @author casties
12 *
13 */
14public 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 annotation target.
32     */
33    protected Target target;
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 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 Resource resource;
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 target
192     */
193    public Target getTarget() {
194        return target;
195    }
196
197    /**
198     * @param target the target to set
199     */
200    public void setTarget(Target target) {
201        this.target = target;
202    }
203
204    /**
205     * @return the targetBaseUri
206     */
207    public String getTargetBaseUri() {
208        if (target == null) return null;
209        return target.getUri();
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    /**
241     * @return the resource
242     */
243    public Resource getResource() {
244        return resource;
245    }
246
247    /**
248     * @param resource the resource to set
249     */
250    public void setResource(Resource resource) {
251        this.resource = resource;
252    }
253
254    /**
255     * @return the resourceUri
256     */
257    public String getResourceUri() {
258        if (resource == null) return null;
259        return resource.getUri();
260    }
261
262    /**
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    /**
277     * @return the creatorUri
278     */
279    public String getCreatorUri() {
280        if (creator != null) {
281            return creator.getUri();
282        }
283        return null;
284    }
285
286    /**
287     * @return the creatorName
288     */
289    public String getCreatorName() {
290        if (creator != null) {
291            return creator.getName();
292        }
293        return null;
294    }
295
296    /**
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    }
309
310    /**
311     * @return the adminPermission
312     */
313    public Actor getAdminPermission() {
314        if (adminPermission != null) {
315            return adminPermission;
316        } else {
317            // if not specified then only creator is allowed
318            return this.creator;
319        }
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() {
333        if (deletePermission != null) {
334            return deletePermission;
335        } else {
336            // if not specified then only creator is allowed
337            return this.creator;
338        }
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    }
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    }
389   
390   
391}
Note: See TracBrowser for help on using the repository browser.