Mercurial > hg > AnnotationManagerN4J
comparison src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java @ 9:b2bfc3bc9ba8
new internal actor class for creator.
author | casties |
---|---|
date | Thu, 12 Jul 2012 12:54:46 +0200 |
parents | bbf0cc5bee29 |
children | 90911b2da322 |
comparison
equal
deleted
inserted
replaced
8:c3cc6a41dd1c | 9:b2bfc3bc9ba8 |
---|---|
2 * Base class for Annotator resource classes. | 2 * Base class for Annotator resource classes. |
3 */ | 3 */ |
4 package de.mpiwg.itgroup.annotations.restlet; | 4 package de.mpiwg.itgroup.annotations.restlet; |
5 | 5 |
6 import java.io.UnsupportedEncodingException; | 6 import java.io.UnsupportedEncodingException; |
7 import java.net.URLDecoder; | |
8 import java.net.URLEncoder; | |
9 import java.security.InvalidKeyException; | 7 import java.security.InvalidKeyException; |
10 import java.security.SignatureException; | 8 import java.security.SignatureException; |
11 import java.text.SimpleDateFormat; | 9 import java.text.SimpleDateFormat; |
12 import java.util.ArrayList; | 10 import java.util.ArrayList; |
13 import java.util.Calendar; | 11 import java.util.Calendar; |
33 import org.restlet.data.Status; | 31 import org.restlet.data.Status; |
34 import org.restlet.representation.Representation; | 32 import org.restlet.representation.Representation; |
35 import org.restlet.resource.Options; | 33 import org.restlet.resource.Options; |
36 import org.restlet.resource.ServerResource; | 34 import org.restlet.resource.ServerResource; |
37 | 35 |
36 import de.mpiwg.itgroup.annotations.Actor; | |
38 import de.mpiwg.itgroup.annotations.Annotation; | 37 import de.mpiwg.itgroup.annotations.Annotation; |
39 import de.mpiwg.itgroup.annotations.Annotation.FragmentTypes; | 38 import de.mpiwg.itgroup.annotations.Annotation.FragmentTypes; |
40 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; | 39 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; |
41 import de.mpiwg.itgroup.annotations.old.NS; | 40 import de.mpiwg.itgroup.annotations.old.NS; |
42 | 41 |
191 JSONObject userObject = new JSONObject(); | 190 JSONObject userObject = new JSONObject(); |
192 // save creator as uri | 191 // save creator as uri |
193 userObject.put("uri", annot.getCreatorUri()); | 192 userObject.put("uri", annot.getCreatorUri()); |
194 // make short user id | 193 // make short user id |
195 String userId = annot.getCreatorUri(); | 194 String userId = annot.getCreatorUri(); |
195 // remove namespace from user uri to get id | |
196 if (userId != null && userId.startsWith(NS.MPIWG_PERSONS_URL)) { | 196 if (userId != null && userId.startsWith(NS.MPIWG_PERSONS_URL)) { |
197 userId = userId.replace(NS.MPIWG_PERSONS_URL, ""); // entferne | 197 userId = userId.replace(NS.MPIWG_PERSONS_URL, ""); |
198 // NAMESPACE | 198 } |
199 } | 199 // set as id |
200 // save as id | |
201 userObject.put("id", userId); | 200 userObject.put("id", userId); |
202 // get full name | 201 // get full name |
203 String userName = annot.getCreatorName(); | 202 String userName = annot.getCreatorName(); |
204 if (userName == null) { | 203 if (userName == null) { |
205 RestServer restServer = (RestServer) getApplication(); | 204 RestServer restServer = (RestServer) getApplication(); |
387 setStatus(Status.CLIENT_ERROR_FORBIDDEN); | 386 setStatus(Status.CLIENT_ERROR_FORBIDDEN); |
388 return null; | 387 return null; |
389 /* | 388 /* |
390 * } authUser = httpUser.getIdentifier(); | 389 * } authUser = httpUser.getIdentifier(); |
391 */ | 390 */ |
391 } | |
392 // get or create creator object | |
393 Actor creator = annot.getCreator(); | |
394 if (creator == null) { | |
395 creator = new Actor(false, null, null); | |
396 annot.setCreator(creator); | |
392 } | 397 } |
393 // username not required, if no username given authuser will be used | 398 // username not required, if no username given authuser will be used |
394 String username = null; | 399 String username = null; |
395 String userUri = annot.getCreatorUri(); | 400 String userUri = annot.getCreatorUri(); |
396 if (jo.has("user")) { | 401 if (jo.has("user")) { |
411 } | 416 } |
412 if (username == null) { | 417 if (username == null) { |
413 username = authUser; | 418 username = authUser; |
414 } | 419 } |
415 // try to get full name | 420 // try to get full name |
416 if (username != null) { | 421 if (creator.getName() == null && username != null) { |
417 RestServer restServer = (RestServer) getApplication(); | 422 RestServer restServer = (RestServer) getApplication(); |
418 String fullName = restServer.getFullNameFromLdap(username); | 423 String fullName = restServer.getFullNameFromLdap(username); |
419 annot.setCreatorName(fullName); | 424 creator.setName(fullName); |
420 } | 425 } |
421 // userUri should be a URI, if not it will set to the MPIWG namespace | 426 // userUri should be a URI, if not it will set to the MPIWG namespace |
422 if (userUri == null) { | 427 if (userUri == null) { |
423 if (username.startsWith("http")) { | 428 if (username.startsWith("http")) { |
424 userUri = username; | 429 userUri = username; |
425 } else { | 430 } else { |
426 userUri = NS.MPIWG_PERSONS_URL + username; | 431 userUri = NS.MPIWG_PERSONS_URL + username; |
427 } | 432 } |
428 } | 433 } |
429 // TODO: should we overwrite the creator? | 434 // TODO: should we overwrite the creator? |
430 if (annot.getCreatorUri() == null) { | 435 if (creator.getUri() == null) { |
431 annot.setCreatorUri(userUri); | 436 creator.setUri(userUri); |
432 } | 437 } |
433 | 438 |
434 if (annot.getCreated() == null) { | 439 if (annot.getCreated() == null) { |
435 // set creation date | 440 // set creation date |
436 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); | 441 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); |