source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/Annotation.java @ 15:58357a4b86de

Last change on this file since 15:58357a4b86de was 15:58357a4b86de, checked in by casties, 12 years ago

ASSIGNED - # 249: Annotations shared in groups
https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/249

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