source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/Annotation.java @ 14:629e15b345aa

Last change on this file since 14:629e15b345aa was 14:629e15b345aa, checked in by casties, 12 years ago

permissions mostly work. need more server-side checking.

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