Changeset 10:90911b2da322 in AnnotationManagerN4J for src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java
Legend:
- Unmodified
- Added
- Removed
-
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.