diff 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
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java	Thu Jul 12 11:14:39 2012 +0200
+++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java	Thu Jul 12 12:54:46 2012 +0200
@@ -4,8 +4,6 @@
 package de.mpiwg.itgroup.annotations.restlet;
 
 import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
 import java.security.InvalidKeyException;
 import java.security.SignatureException;
 import java.text.SimpleDateFormat;
@@ -35,6 +33,7 @@
 import org.restlet.resource.Options;
 import org.restlet.resource.ServerResource;
 
+import de.mpiwg.itgroup.annotations.Actor;
 import de.mpiwg.itgroup.annotations.Annotation;
 import de.mpiwg.itgroup.annotations.Annotation.FragmentTypes;
 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
@@ -193,11 +192,11 @@
                 userObject.put("uri", annot.getCreatorUri());
                 // make short user id
                 String userId = annot.getCreatorUri();
+                // remove namespace from user uri to get id
                 if (userId != null && userId.startsWith(NS.MPIWG_PERSONS_URL)) {
-                    userId = userId.replace(NS.MPIWG_PERSONS_URL, ""); // entferne
-                                                                       // NAMESPACE
+                    userId = userId.replace(NS.MPIWG_PERSONS_URL, "");
                 }
-                // save as id
+                // set as id
                 userObject.put("id", userId);
                 // get full name
                 String userName = annot.getCreatorName();
@@ -390,6 +389,12 @@
              * } authUser = httpUser.getIdentifier();
              */
         }
+        // get or create creator object
+        Actor creator = annot.getCreator();
+        if (creator == null) {
+            creator = new Actor(false, null, null);
+            annot.setCreator(creator);
+        }
         // username not required, if no username given authuser will be used
         String username = null;
         String userUri = annot.getCreatorUri();
@@ -413,10 +418,10 @@
             username = authUser;
         }
         // try to get full name
-        if (username != null) {
+        if (creator.getName() == null && username != null) {
             RestServer restServer = (RestServer) getApplication();
             String fullName = restServer.getFullNameFromLdap(username);
-            annot.setCreatorName(fullName);
+            creator.setName(fullName);
         }
         // userUri should be a URI, if not it will set to the MPIWG namespace
         if (userUri == null) {
@@ -427,8 +432,8 @@
             }
         }
         // TODO: should we overwrite the creator?
-        if (annot.getCreatorUri() == null) {
-            annot.setCreatorUri(userUri);
+        if (creator.getUri() == null) {
+            creator.setUri(userUri);
         }
         
         if (annot.getCreated() == null) {