# HG changeset patch # User casties # Date 1348664202 -7200 # Node ID 03e0f7574224f3dc714ff6ff15a664dd34fd22be # Parent 0fdb05f35139f5e769538192fb1fdd7c36d39198 saving and loading resource targets should work now (no searching yet) diff -r 0fdb05f35139 -r 03e0f7574224 src/main/java/de/mpiwg/itgroup/annotations/Annotation.java --- 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() { diff -r 0fdb05f35139 -r 03e0f7574224 src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java --- 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 rels = start.getRelationships(type, Direction.OUTGOING); @@ -753,8 +765,8 @@ return annotation; } - protected Node getOrCreateTargetNode(String uri) { - Index idx = getNodeIndex(NodeTypes.TARGET); + protected Node getOrCreateTargetNode(String uri, NodeTypes type) { + Index idx = getNodeIndex(type); IndexHits 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(); diff -r 0fdb05f35139 -r 03e0f7574224 src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java --- 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; diff -r 0fdb05f35139 -r 03e0f7574224 src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java --- 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")) {