source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/Annotation.java @ 20:715aa11d138b

Last change on this file since 20:715aa11d138b was 20:715aa11d138b, checked in by casties, 12 years ago

fixes in permission handling: admin and delete default to creator.

File size: 7.8 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 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 targets.
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     * The creator of this annotation.
55     */
56    protected Actor creator;
57   
58    /**
59     * The creation date of this annotation.
60     */
61    protected String created;
62
63    /**
64     * The user or group that has admin permissions.
65     * null means any user.
66     */
67    protected Actor adminPermission;
68   
69    /**
70     * The user or group that has delete permissions.
71     * null means any user.
72     */
73    protected Actor deletePermission;
74   
75    /**
76     * The user or group that has update permissions.
77     * null means any user.
78     */
79    protected Actor updatePermission;
80   
81    /**
82     * The user or group that has read permissions.
83     * null means any user.
84     */
85    protected Actor readPermission;
86       
87    /**
88     * List of tags on this Annotation.
89     */
90    protected Set<String> tags;
91   
92    /**
93     * Returns if the requested action is allowed for the given user on this annotation.
94     *
95     * @param action
96     * @param user
97     * @param store AnnotationStore to check group membership
98     * @return
99     */
100    public boolean isActionAllowed(String action, Person user, AnnotationStore store) {
101        if (action.equals("read")) {
102            Actor reader = getReadPermission();
103            if (reader == null) {
104                // if not specified then everybody is allowed
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                // if not specified then everybody is allowed
115                return true;
116            } else {
117                return updater.isEquivalentWith(user, store);
118            }
119        } else if (action.equals("delete")) {
120            // require at least an authenticated user
121            if (user == null) return false;
122            Actor deleter = getDeletePermission();
123            if (deleter == null) {
124                // if not specified then only creator is allowed
125                deleter = creator;
126            }
127            return deleter.isEquivalentWith(user, store);
128        } else if (action.equals("admin")) {
129            // require at least an authenticated user
130            if (user == null) return false;
131            Actor admin = getAdminPermission();
132            if (admin == null) {
133                // if not specified then only creator is allowed
134                admin = creator;
135            }
136            return admin.isEquivalentWith(user, store);
137        }
138        return false;
139    }
140   
141    /**
142     * @return the uri
143     */
144    public String getUri() {
145        return uri;
146    }
147
148    /**
149     * @param uri the uri to set
150     */
151    public void setUri(String uri) {
152        this.uri = uri;
153    }
154
155    /**
156     * @return the bodyText
157     */
158    public String getBodyText() {
159        return bodyText;
160    }
161
162    /**
163     * @param bodyText the bodyText to set
164     */
165    public void setBodyText(String bodyText) {
166        this.bodyText = bodyText;
167    }
168
169    /**
170     * @return the bodyUri
171     */
172    public String getBodyUri() {
173        return bodyUri;
174    }
175
176    /**
177     * @param bodyUri the bodyUri to set
178     */
179    public void setBodyUri(String bodyUri) {
180        this.bodyUri = bodyUri;
181    }
182
183    /**
184     * @return the targetBaseUri
185     */
186    public String getTargetBaseUri() {
187        return targetBaseUri;
188    }
189
190    /**
191     * @param targetBaseUri the targetBaseUri to set
192     */
193    public void setTargetBaseUri(String targetBaseUri) {
194        this.targetBaseUri = targetBaseUri;
195    }
196
197    /**
198     * @return the targetFragment
199     */
200    public String getTargetFragment() {
201        return targetFragment;
202    }
203
204    /**
205     * @param targetFragment the targetFragment to set
206     */
207    public void setTargetFragment(String targetFragment) {
208        this.targetFragment = targetFragment;
209    }
210
211    /**
212     * @return the targetType
213     */
214    public FragmentTypes getFragmentType() {
215        return fragmentType;
216    }
217
218    /**
219     * @param fragmentType the fragmentType to set
220     */
221    public void setFragmentType(FragmentTypes fragmentType) {
222        this.fragmentType = fragmentType;
223    }
224
225    /**
226     * @return the creator
227     */
228    public Actor getCreator() {
229        return creator;
230    }
231
232    /**
233     * @param creator the creator to set
234     */
235    public void setCreator(Actor creator) {
236        this.creator = creator;
237    }
238
239    /**
240     * @return the creatorUri
241     */
242    public String getCreatorUri() {
243        if (creator != null) {
244            return creator.getUri();
245        }
246        return null;
247    }
248
249    /**
250     * @return the creatorName
251     */
252    public String getCreatorName() {
253        if (creator != null) {
254            return creator.getName();
255        }
256        return null;
257    }
258
259    /**
260     * @return the created
261     */
262    public String getCreated() {
263        return created;
264    }
265
266    /**
267     * @param created the created to set
268     */
269    public void setCreated(String created) {
270        this.created = created;
271    }
272
273    /**
274     * @return the adminPermission
275     */
276    public Actor getAdminPermission() {
277        if (adminPermission != null) {
278            return adminPermission;
279        } else {
280            // if not specified then only creator is allowed
281            return this.creator;
282        }
283    }
284
285    /**
286     * @param adminPermission the adminPermission to set
287     */
288    public void setAdminPermission(Actor adminPermission) {
289        this.adminPermission = adminPermission;
290    }
291
292    /**
293     * @return the deletePermission
294     */
295    public Actor getDeletePermission() {
296        if (deletePermission != null) {
297            return deletePermission;
298        } else {
299            // if not specified then only creator is allowed
300            return this.creator;
301        }
302    }
303
304    /**
305     * @param deletePermission the deletePermission to set
306     */
307    public void setDeletePermission(Actor deletePermission) {
308        this.deletePermission = deletePermission;
309    }
310
311    /**
312     * @return the updatePermission
313     */
314    public Actor getUpdatePermission() {
315        return updatePermission;
316    }
317
318    /**
319     * @param updatePermission the updatePermission to set
320     */
321    public void setUpdatePermission(Actor updatePermission) {
322        this.updatePermission = updatePermission;
323    }
324
325    /**
326     * @return the readPermission
327     */
328    public Actor getReadPermission() {
329        return readPermission;
330    }
331
332    /**
333     * @param readPermission the readPermission to set
334     */
335    public void setReadPermission(Actor readPermission) {
336        this.readPermission = readPermission;
337    }
338
339    /**
340     * @return the tags
341     */
342    public Set<String> getTags() {
343        return tags;
344    }
345
346    /**
347     * @param tags the tags to set
348     */
349    public void setTags(Set<String> tags) {
350        this.tags = tags;
351    }
352   
353   
354}
Note: See TracBrowser for help on using the repository browser.