Changeset 10:90911b2da322 in AnnotationManagerN4J
- Timestamp:
- Jul 12, 2012, 3:01:32 PM (12 years ago)
- Branch:
- default
- Location:
- src/main/java/de/mpiwg/itgroup/annotations
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/Actor.java
r9 r10 4 4 package de.mpiwg.itgroup.annotations; 5 5 6 import de.mpiwg.itgroup.annotations.old.NS; 7 6 8 /** 7 9 * @author casties 8 10 * 9 11 */ 10 public class Actor {12 public abstract class Actor { 11 13 12 public boolean isGroup;13 14 public String uri; 14 15 public String name; 16 public String id; 15 17 16 18 /** 17 * @param isGroup 18 * @param id 19 * @param uri 20 * @param name 19 * @return if this Actor is a Group 21 20 */ 22 public Actor(boolean isGroup, String uri, String name) { 23 super(); 24 this.isGroup = isGroup; 25 this.uri = uri; 26 this.name = name; 27 } 21 public abstract boolean isGroup(); 28 22 29 /**30 * @return the isGroup31 */32 public boolean isGroup() {33 return isGroup;34 }35 /**36 * @param isGroup the isGroup to set37 */38 public void setGroup(boolean isGroup) {39 this.isGroup = isGroup;40 }41 23 /** 42 24 * @return the uri … … 63 45 this.name = name; 64 46 } 47 48 /** 49 * @return the id 50 */ 51 public String getId() { 52 return id; 53 } 54 55 /** 56 * Returns id as a String starting with "group:" for groups. 57 * 58 * @return 59 */ 60 public abstract String getIdString(); 61 62 /** 63 * @param id the id to set 64 */ 65 public void setId(String id) { 66 this.id = id; 67 } 68 69 /** 70 * Returns a short id from an uri. 71 * 72 * @param uri 73 * @return 74 */ 75 public static String getIdFromUri(String uri, boolean isGroup) { 76 String id = null; 77 String prefix = NS.MPIWG_PERSONS_URL; 78 if (isGroup) { 79 prefix = NS.MPIWG_GROUPS_URL; 80 } 81 if (uri != null && uri.startsWith(prefix)) { 82 id = uri.replace(prefix, ""); 83 } 84 return id; 85 } 86 87 /** 88 * Returns an uri from a short id. 89 * 90 * @param id 91 * @return 92 */ 93 public static String getUriFromId(String id, boolean isGroup) { 94 String uri = null; 95 String prefix = NS.MPIWG_PERSONS_URL; 96 if (isGroup) { 97 prefix = NS.MPIWG_GROUPS_URL; 98 } 99 if (id != null && ! id.startsWith("http://")) { 100 uri = prefix + id; 101 } 102 return uri; 103 } 104 65 105 } -
src/main/java/de/mpiwg/itgroup/annotations/Annotation.java
r9 r10 57 57 protected String created; 58 58 59 protected String adminPermission; 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; 60 82 61 83 /** … … 190 212 this.created = created; 191 213 } 214 215 /** 216 * @return the adminPermission 217 */ 218 public Actor getAdminPermission() { 219 return adminPermission; 220 } 221 222 /** 223 * @param adminPermission the adminPermission to set 224 */ 225 public void setAdminPermission(Actor adminPermission) { 226 this.adminPermission = adminPermission; 227 } 228 229 /** 230 * @return the deletePermission 231 */ 232 public Actor getDeletePermission() { 233 return deletePermission; 234 } 235 236 /** 237 * @param deletePermission the deletePermission to set 238 */ 239 public void setDeletePermission(Actor deletePermission) { 240 this.deletePermission = deletePermission; 241 } 242 243 /** 244 * @return the updatePermission 245 */ 246 public Actor getUpdatePermission() { 247 return updatePermission; 248 } 249 250 /** 251 * @param updatePermission the updatePermission to set 252 */ 253 public void setUpdatePermission(Actor updatePermission) { 254 this.updatePermission = updatePermission; 255 } 256 257 /** 258 * @return the readPermission 259 */ 260 public Actor getReadPermission() { 261 return readPermission; 262 } 263 264 /** 265 * @param readPermission the readPermission to set 266 */ 267 public void setReadPermission(Actor readPermission) { 268 this.readPermission = readPermission; 269 } 192 270 193 271 -
src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java
r9 r10 21 21 import de.mpiwg.itgroup.annotations.Annotation; 22 22 import de.mpiwg.itgroup.annotations.Annotation.FragmentTypes; 23 import de.mpiwg.itgroup.annotations.Person; 23 24 24 25 /** … … 103 104 String uri = (String) creatorNode.getProperty("uri", null); 104 105 String name = (String) creatorNode.getProperty("name", null); 105 Actor creator = new Actor(false,uri, name);106 Actor creator = new Person(uri, name); 106 107 annot.setCreator(creator); 107 108 // just the first one … … 164 165 165 166 /* 166 * The name of the creator of this annotation. 167 */ 168 String creatorName = annot.getCreatorName(); 169 170 /* 171 * The URI of the creator of this annotation. 172 */ 173 String creatorUri = annot.getCreatorUri(); 174 if (creatorUri != null) { 175 Node creator = getOrCreatePersonNode(creatorUri, creatorName); 176 getOrCreateRelation(creator, RelationTypes.CREATED, annotNode); 167 * The creator of this annotation. 168 */ 169 Actor creator = annot.getCreator(); 170 if (creator != null) { 171 Node creatorNode = getOrCreatePersonNode(creator); 172 getOrCreateRelation(creatorNode, RelationTypes.CREATED, annotNode); 177 173 } 178 174 … … 342 338 } 343 339 344 protected Node getOrCreatePersonNode(String uri, String name) { 340 protected Node getOrCreatePersonNode(Actor actor) { 341 /* 345 342 // Person is identified by URI 346 343 Index<Node> idx = getNodeIndex(NodeTypes.PERSON); … … 364 361 } 365 362 return person; 363 */ 364 return null; 366 365 } 367 366 -
src/main/java/de/mpiwg/itgroup/annotations/old/NS.java
r4 r10 3 3 public class NS { 4 4 public static final String MPIWG_PERSONS_URL = "http://entities.mpiwg-berlin.mpg.de/persons/"; 5 // public static String 6 // ANNOTATION_TYPE="http://www.w3.org/2000/10/annotationType#"; 5 public static final String MPIWG_GROUPS_URL = "http://entities.mpiwg-berlin.mpg.de/groups/"; 7 6 public static final String OAC_NS = "http://www.openannotation.org/ns/"; 8 7 public static final String CNT_NS = "http://www.w3.org/2011/content#"; -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java
r9 r10 37 37 import de.mpiwg.itgroup.annotations.Annotation; 38 38 import de.mpiwg.itgroup.annotations.Annotation.FragmentTypes; 39 import de.mpiwg.itgroup.annotations.Group; 40 import de.mpiwg.itgroup.annotations.Person; 39 41 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; 40 42 import de.mpiwg.itgroup.annotations.old.NS; … … 189 191 // create user object 190 192 JSONObject userObject = new JSONObject(); 193 Actor creator = annot.getCreator(); 191 194 // save creator as uri 192 userObject.put("uri", annot.getCreatorUri());195 userObject.put("uri", creator.getUri()); 193 196 // make short user id 194 String userId = annot.getCreatorUri(); 195 // remove namespace from user uri to get id 196 if (userId != null && userId.startsWith(NS.MPIWG_PERSONS_URL)) { 197 userId = userId.replace(NS.MPIWG_PERSONS_URL, ""); 198 } 197 String userId = creator.getIdString(); 199 198 // set as id 200 199 userObject.put("id", userId); 201 200 // get full name 202 String userName = annot.getCreatorName();201 String userName = creator.getName(); 203 202 if (userName == null) { 204 203 RestServer restServer = (RestServer) getApplication(); … … 224 223 } 225 224 } 225 226 // permissions 227 JSONObject perms = new JSONObject(); 228 jo.put("permissions", perms); 229 // admin 230 JSONArray adminPerms = new JSONArray(); 231 perms.put("admin", adminPerms); 232 Actor adminPerm = annot.getAdminPermission(); 233 if (adminPerm != null) { 234 adminPerms.put(adminPerm.getIdString()); 235 } 236 // delete 237 JSONArray deletePerms = new JSONArray(); 238 perms.put("delete", deletePerms); 239 Actor deletePerm = annot.getDeletePermission(); 240 if (deletePerm != null) { 241 deletePerms.put(deletePerm.getIdString()); 242 } 243 // update 244 JSONArray updatePerms = new JSONArray(); 245 perms.put("update", updatePerms); 246 Actor updatePerm = annot.getUpdatePermission(); 247 if (updatePerm != null) { 248 updatePerms.put(updatePerm.getIdString()); 249 } 250 // read 251 JSONArray readPerms = new JSONArray(); 252 perms.put("read", readPerms); 253 Actor readPerm = annot.getReadPermission(); 254 if (readPerm != null) { 255 readPerms.put(readPerm.getIdString()); 256 } 257 226 258 // encode Annotation URL (=id) in base64 227 259 String annotUrl = annot.getUri(); … … 246 278 try { 247 279 for (String xpointer : xpointers) { 248 // String decoded = URLDecoder.decode(xpointer, "utf-8");280 // String decoded = URLDecoder.decode(xpointer, "utf-8"); 249 281 String decoded = xpointer; 250 282 Matcher m = rg.matcher(decoded); … … 284 316 try { 285 317 for (String xpointer : xpointers) { 286 // String decoded = URLDecoder.decode(xpointer, "utf-8");318 // String decoded = URLDecoder.decode(xpointer, "utf-8"); 287 319 String decoded = xpointer; 288 320 Matcher m = rg.matcher(decoded); … … 291 323 { 292 324 JSONObject jo = new JSONObject(); 325 @SuppressWarnings("unused") 293 326 String unit = m.group(1); 294 327 jo.put("x", m.group(2)); … … 393 426 Actor creator = annot.getCreator(); 394 427 if (creator == null) { 395 creator = new Actor(false, null, null);428 creator = new Person(); 396 429 annot.setCreator(creator); 397 430 } 398 431 // username not required, if no username given authuser will be used 399 432 String username = null; 400 String userUri = annot.getCreatorUri();433 String userUri = creator.getUri(); 401 434 if (jo.has("user")) { 402 435 if (jo.get("user") instanceof String) { 403 436 // user is just a String 404 437 username = jo.getString("user"); 438 creator.setId(username); 405 439 // TODO: what if username and authUser are different? 406 440 } else { … … 408 442 JSONObject user = jo.getJSONObject("user"); 409 443 if (user.has("id")) { 410 username = user.getString("id"); 444 String id = user.getString("id"); 445 creator.setId(id); 446 username = id; 411 447 } 412 448 if (user.has("uri")) { … … 436 472 creator.setUri(userUri); 437 473 } 438 474 439 475 if (annot.getCreated() == null) { 440 476 // set creation date … … 457 493 annot.setTargetFragment(fragment); 458 494 } 495 496 // permissions 497 if (jo.has("permissions")) { 498 JSONObject permissions = jo.getJSONObject("permissions"); 499 if (permissions.has("admin")) { 500 JSONArray perms = permissions.getJSONArray("admin"); 501 Actor actor = getActorFromPermissions(perms); 502 annot.setAdminPermission(actor); 503 } 504 if (permissions.has("delete")) { 505 JSONArray perms = permissions.getJSONArray("delete"); 506 Actor actor = getActorFromPermissions(perms); 507 annot.setDeletePermission(actor); 508 } 509 if (permissions.has("update")) { 510 JSONArray perms = permissions.getJSONArray("update"); 511 Actor actor = getActorFromPermissions(perms); 512 annot.setUpdatePermission(actor); 513 } 514 if (permissions.has("read")) { 515 JSONArray perms = permissions.getJSONArray("read"); 516 Actor actor = getActorFromPermissions(perms); 517 annot.setReadPermission(actor); 518 } 519 } 520 459 521 return annot; 460 522 } 461 523 524 @SuppressWarnings("unused") 525 protected Actor getActorFromPermissions(JSONArray perms) throws JSONException { 526 Actor actor = null; 527 for (int i = 0; i < perms.length(); ++i) { 528 String perm = perms.getString(i); 529 if (perm.toLowerCase().startsWith("group:")) { 530 String groupId = perm.substring(6); 531 actor = new Group(groupId); 532 } else { 533 actor = new Person(perm); 534 } 535 // we just take the first one 536 break; 537 } 538 return actor; 539 } 540 462 541 }
Note: See TracChangeset
for help on using the changeset viewer.