Mercurial > hg > AnnotationManagerN4J
annotate src/main/java/de/mpiwg/itgroup/annotations/Annotation.java @ 25:2140ef107551
adding and deleting group members.
| author | casties |
|---|---|
| date | Mon, 24 Sep 2012 11:36:33 +0200 |
| parents | 715aa11d138b |
| children | 03e0f7574224 |
| rev | line source |
|---|---|
| 4 | 1 /** |
| 2 * | |
| 3 */ | |
| 4 package de.mpiwg.itgroup.annotations; | |
| 5 | |
| 16 | 6 import java.util.Set; |
| 7 | |
| 15 | 8 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; |
| 9 | |
| 4 | 10 /** |
| 11 * @author casties | |
| 12 * | |
| 13 */ | |
| 14 public 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 /** | |
| 9 | 54 * The creator of this annotation. |
| 4 | 55 */ |
| 9 | 56 protected Actor creator; |
| 5 | 57 |
| 58 /** | |
| 4 | 59 * The creation date of this annotation. |
| 60 */ | |
| 61 protected String created; | |
| 62 | |
| 10 | 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; | |
| 16 | 86 |
| 87 /** | |
| 88 * List of tags on this Annotation. | |
| 89 */ | |
| 90 protected Set<String> tags; | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
91 |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
92 /** |
|
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
93 * Returns if the requested action is allowed for the given user on this annotation. |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
94 * |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
95 * @param action |
| 15 | 96 * @param user |
| 97 * @param store AnnotationStore to check group membership | |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
98 * @return |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
99 */ |
| 15 | 100 public boolean isActionAllowed(String action, Person user, AnnotationStore store) { |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
101 if (action.equals("read")) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
102 Actor reader = getReadPermission(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
103 if (reader == null) { |
|
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
104 // if not specified then everybody is allowed |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
105 return true; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
106 } else { |
| 15 | 107 return reader.isEquivalentWith(user, store); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
108 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
109 } else if (action.equals("update")) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
110 // require at least an authenticated user |
| 15 | 111 if (user == null) return false; |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
112 Actor updater = getUpdatePermission(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
113 if (updater == null) { |
|
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
114 // if not specified then everybody is allowed |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
115 return true; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
116 } else { |
| 15 | 117 return updater.isEquivalentWith(user, store); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
118 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
119 } else if (action.equals("delete")) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
120 // require at least an authenticated user |
| 15 | 121 if (user == null) return false; |
|
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
122 Actor deleter = getDeletePermission(); |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
123 if (deleter == null) { |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
124 // if not specified then only creator is allowed |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
125 deleter = creator; |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
126 } |
|
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
127 return deleter.isEquivalentWith(user, store); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
128 } else if (action.equals("admin")) { |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
129 // require at least an authenticated user |
| 15 | 130 if (user == null) return false; |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
131 Actor admin = getAdminPermission(); |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
132 if (admin == null) { |
|
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
133 // if not specified then only creator is allowed |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
134 admin = creator; |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
135 } |
|
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
136 return admin.isEquivalentWith(user, store); |
|
14
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
137 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
138 return false; |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
139 } |
|
629e15b345aa
permissions mostly work. need more server-side checking.
casties
parents:
10
diff
changeset
|
140 |
| 4 | 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 /** | |
| 9 | 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 /** | |
| 4 | 240 * @return the creatorUri |
| 241 */ | |
| 242 public String getCreatorUri() { | |
| 9 | 243 if (creator != null) { |
| 244 return creator.getUri(); | |
| 245 } | |
| 246 return null; | |
| 4 | 247 } |
| 248 | |
| 249 /** | |
| 5 | 250 * @return the creatorName |
| 251 */ | |
| 252 public String getCreatorName() { | |
| 9 | 253 if (creator != null) { |
| 254 return creator.getName(); | |
| 255 } | |
| 256 return null; | |
| 5 | 257 } |
| 258 | |
| 259 /** | |
| 4 | 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 } | |
| 10 | 272 |
| 273 /** | |
| 274 * @return the adminPermission | |
| 275 */ | |
| 276 public Actor getAdminPermission() { | |
|
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
277 if (adminPermission != null) { |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
278 return adminPermission; |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
279 } else { |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
280 // if not specified then only creator is allowed |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
281 return this.creator; |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
282 } |
| 10 | 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() { | |
|
20
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
296 if (deletePermission != null) { |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
297 return deletePermission; |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
298 } else { |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
299 // if not specified then only creator is allowed |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
300 return this.creator; |
|
715aa11d138b
fixes in permission handling: admin and delete default to creator.
casties
parents:
16
diff
changeset
|
301 } |
| 10 | 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 } | |
| 16 | 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 } | |
| 4 | 352 |
| 353 | |
| 354 } |
