changeset 9:b2bfc3bc9ba8

new internal actor class for creator.
author casties
date Thu, 12 Jul 2012 12:54:46 +0200
parents c3cc6a41dd1c
children 90911b2da322
files src/main/java/de/mpiwg/itgroup/annotations/Actor.java src/main/java/de/mpiwg/itgroup/annotations/Annotation.java src/main/java/de/mpiwg/itgroup/annotations/Person.java src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java
diffstat 5 files changed, 110 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/itgroup/annotations/Actor.java	Thu Jul 12 12:54:46 2012 +0200
@@ -0,0 +1,65 @@
+/**
+ * 
+ */
+package de.mpiwg.itgroup.annotations;
+
+/**
+ * @author casties
+ *
+ */
+public class Actor {
+
+    public boolean isGroup;
+    public String uri;
+    public String name;
+    
+    /**
+     * @param isGroup
+     * @param id
+     * @param uri
+     * @param name
+     */
+    public Actor(boolean isGroup, String uri, String name) {
+        super();
+        this.isGroup = isGroup;
+        this.uri = uri;
+        this.name = name;
+    }
+    
+    /**
+     * @return the isGroup
+     */
+    public boolean isGroup() {
+        return isGroup;
+    }
+    /**
+     * @param isGroup the isGroup to set
+     */
+    public void setGroup(boolean isGroup) {
+        this.isGroup = isGroup;
+    }
+    /**
+     * @return the uri
+     */
+    public String getUri() {
+        return uri;
+    }
+    /**
+     * @param uri the uri to set
+     */
+    public void setUri(String uri) {
+        this.uri = uri;
+    }
+    /**
+     * @return the name
+     */
+    public String getName() {
+        return name;
+    }
+    /**
+     * @param name the name to set
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+}
--- a/src/main/java/de/mpiwg/itgroup/annotations/Annotation.java	Thu Jul 12 11:14:39 2012 +0200
+++ b/src/main/java/de/mpiwg/itgroup/annotations/Annotation.java	Thu Jul 12 12:54:46 2012 +0200
@@ -47,14 +47,9 @@
     protected FragmentTypes fragmentType;
     
     /**
-     * The URI of the creator of this annotation.
+     * The creator of this annotation.
      */
-    protected String creatorUri;
-    
-    /**
-     * The full name of the creator of this annotation.
-     */
-    protected String creatorName;
+    protected Actor creator;
     
     /**
      * The creation date of this annotation.
@@ -148,31 +143,37 @@
     }
 
     /**
+     * @return the creator
+     */
+    public Actor getCreator() {
+        return creator;
+    }
+
+    /**
+     * @param creator the creator to set
+     */
+    public void setCreator(Actor creator) {
+        this.creator = creator;
+    }
+
+    /**
      * @return the creatorUri
      */
     public String getCreatorUri() {
-        return creatorUri;
-    }
-
-    /**
-     * @param creatorUri the creatorUri to set
-     */
-    public void setCreatorUri(String creatorUri) {
-        this.creatorUri = creatorUri;
+        if (creator != null) {
+            return creator.getUri();
+        }
+        return null;
     }
 
     /**
      * @return the creatorName
      */
     public String getCreatorName() {
-        return creatorName;
-    }
-
-    /**
-     * @param creatorName the creatorName to set
-     */
-    public void setCreatorName(String creatorName) {
-        this.creatorName = creatorName;
+        if (creator != null) {
+            return creator.getName();
+        }
+        return null;
     }
 
     /**
--- a/src/main/java/de/mpiwg/itgroup/annotations/Person.java	Thu Jul 12 11:14:39 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-/**
- * 
- */
-package de.mpiwg.itgroup.annotations;
-
-/**
- * @author casties
- *
- */
-public class Person {
-
-}
--- a/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java	Thu Jul 12 11:14:39 2012 +0200
+++ b/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java	Thu Jul 12 12:54:46 2012 +0200
@@ -17,6 +17,7 @@
 import org.neo4j.graphdb.index.Index;
 import org.neo4j.graphdb.index.IndexHits;
 
+import de.mpiwg.itgroup.annotations.Actor;
 import de.mpiwg.itgroup.annotations.Annotation;
 import de.mpiwg.itgroup.annotations.Annotation.FragmentTypes;
 
@@ -94,13 +95,15 @@
 		if (ft != null) {
 			annot.setFragmentType(FragmentTypes.valueOf(ft));
 		}
-		// get creator form relation
+		// get creator from relation
 		Iterable<Relationship> creatorRels = annotNode
 				.getRelationships(RelationTypes.CREATED);
 		for (Relationship creatorRel : creatorRels) {
-			Node creator = creatorRel.getStartNode();
-			annot.setCreatorUri((String) creator.getProperty("uri", null));
-			annot.setCreatorName((String) creator.getProperty("name", null));
+			Node creatorNode = creatorRel.getStartNode();
+			String uri = (String) creatorNode.getProperty("uri", null);
+			String name = (String) creatorNode.getProperty("name", null);
+            Actor creator = new Actor(false, uri, name);
+            annot.setCreator(creator);
 			// just the first one
 			break;
 		}
--- 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) {