changeset 40:03e0f7574224

saving and loading resource targets should work now (no searching yet)
author casties
date Wed, 26 Sep 2012 14:56:42 +0200
parents 0fdb05f35139
children 5d4260344db5
files src/main/java/de/mpiwg/itgroup/annotations/Annotation.java src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java
diffstat 4 files changed, 48 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotations/Annotation.java	Wed Sep 26 11:47:38 2012 +0200
+++ b/src/main/java/de/mpiwg/itgroup/annotations/Annotation.java	Wed Sep 26 14:56:42 2012 +0200
@@ -38,7 +38,7 @@
     protected String targetFragment;
     
     /**
-     * The types of annotation targets.
+     * The types of annotation target fragments.
      *
      */
     public static enum FragmentTypes {
@@ -50,6 +50,13 @@
      */
     protected FragmentTypes fragmentType;
     
+    
+    /**
+     * The uri of the resource that is annotated e.g. a book. 
+     * The target is part of this resource e.g. a page of a book.
+     */
+    protected String resourceUri;
+    
     /**
      * The creator of this annotation.
      */
@@ -223,6 +230,20 @@
     }
 
     /**
+     * @return the resourceUri
+     */
+    public String getResourceUri() {
+        return resourceUri;
+    }
+
+    /**
+     * @param resourceUri the resourceUri to set
+     */
+    public void setResourceUri(String resourceUri) {
+        this.resourceUri = resourceUri;
+    }
+
+    /**
      * @return the creator
      */
     public Actor getCreator() {
--- a/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java	Wed Sep 26 11:47:38 2012 +0200
+++ b/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java	Wed Sep 26 14:56:42 2012 +0200
@@ -527,9 +527,10 @@
              * the annotation target
              */
             String targetBaseUri = annot.getTargetBaseUri();
+            Node targetNode = null;
             if (targetBaseUri != null) {
-                Node target = getOrCreateTargetNode(targetBaseUri);
-                getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, target);
+                targetNode = getOrCreateTargetNode(targetBaseUri, NodeTypes.TARGET);
+                getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, targetNode);
             }
 
             /*
@@ -543,6 +544,16 @@
             }
 
             /*
+             * the annotation resource
+             */
+            String resourceUri = annot.getResourceUri();
+            if (resourceUri != null) {
+                Node resource = getOrCreateTargetNode(resourceUri, NodeTypes.RESOURCE);
+                getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, resource);
+                getOrCreateRelation(targetNode, RelationTypes.PART_OF, resource);
+            }
+
+            /*
              * The creator of this annotation.
              */
             Actor creator = annot.getCreator();
@@ -711,6 +722,7 @@
      * @return
      */
     protected Relationship getOrCreateRelation(Node start, RelationshipType type, Node end) {
+        if (start == null || end == null) return null;
         if (start.hasRelationship()) {
             // there are relations
             Iterable<Relationship> rels = start.getRelationships(type, Direction.OUTGOING);
@@ -753,8 +765,8 @@
         return annotation;
     }
 
-    protected Node getOrCreateTargetNode(String uri) {
-        Index<Node> idx = getNodeIndex(NodeTypes.TARGET);
+    protected Node getOrCreateTargetNode(String uri, NodeTypes type) {
+        Index<Node> idx = getNodeIndex(type);
         IndexHits<Node> targets = idx.get("uri", uri);
         Node target = targets.getSingle();
         if (target == null) {
@@ -762,7 +774,7 @@
             Transaction tx = graphDb.beginTx();
             try {
                 target = graphDb.createNode();
-                target.setProperty("TYPE", NodeTypes.TARGET.name());
+                target.setProperty("TYPE", type.name());
                 target.setProperty("uri", uri);
                 idx.add(target, "uri", uri);
                 tx.success();
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java	Wed Sep 26 11:47:38 2012 +0200
+++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java	Wed Sep 26 14:56:42 2012 +0200
@@ -23,7 +23,6 @@
 
 import de.mpiwg.itgroup.annotations.Annotation;
 import de.mpiwg.itgroup.annotations.Person;
-import de.mpiwg.itgroup.annotations.Tag;
 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
 import de.mpiwg.itgroup.annotations.restlet.utils.JSONObjectComparator;
 
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java	Wed Sep 26 11:47:38 2012 +0200
+++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java	Wed Sep 26 14:56:42 2012 +0200
@@ -187,6 +187,9 @@
         try {
             jo.put("text", annot.getBodyText());
             jo.put("uri", annot.getTargetBaseUri());
+            if (annot.getResourceUri() != null) {
+                jo.put("resource", annot.getResourceUri());
+            }
 
             /*
              * user
@@ -441,6 +444,12 @@
             annot.setTargetBaseUri(jo.getString("uri"));
         }
         /*
+         * resource uri
+         */
+        if (jo.has("resource")) {
+            annot.setResourceUri(jo.getString("resource"));
+        }
+        /*
          * annotation text
          */
         if (jo.has("text")) {