# HG changeset patch # User casties # Date 1348675847 -7200 # Node ID 0e00bf8e27fbae5e48b6f4a6fa3b8a67971a8f8f # Parent 54a4a96ad0c3b533d6daa7cb30fb32b821f3cad6 targets and resources of Annotation object are objects now. diff -r 54a4a96ad0c3 -r 0e00bf8e27fb src/main/java/de/mpiwg/itgroup/annotations/Annotation.java --- a/src/main/java/de/mpiwg/itgroup/annotations/Annotation.java Wed Sep 26 17:30:52 2012 +0200 +++ b/src/main/java/de/mpiwg/itgroup/annotations/Annotation.java Wed Sep 26 18:10:47 2012 +0200 @@ -28,9 +28,9 @@ protected String bodyUri; /** - * The base URI of the annotation target. + * The annotation target. */ - protected String targetBaseUri; + protected Target target; /** * The fragment part of the annotation target. @@ -52,10 +52,10 @@ /** - * The uri of the resource that is annotated e.g. a book. + * 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; + protected Resource resource; /** * The creator of this annotation. @@ -188,17 +188,25 @@ } /** + * @return the target + */ + public Target getTarget() { + return target; + } + + /** + * @param target the target to set + */ + public void setTarget(Target target) { + this.target = target; + } + + /** * @return the targetBaseUri */ public String getTargetBaseUri() { - return targetBaseUri; - } - - /** - * @param targetBaseUri the targetBaseUri to set - */ - public void setTargetBaseUri(String targetBaseUri) { - this.targetBaseUri = targetBaseUri; + if (target == null) return null; + return target.getUri(); } /** @@ -230,17 +238,25 @@ } /** + * @return the resource + */ + public Resource getResource() { + return resource; + } + + /** + * @param resource the resource to set + */ + public void setResource(Resource resource) { + this.resource = resource; + } + + /** * @return the resourceUri */ public String getResourceUri() { - return resourceUri; - } - - /** - * @param resourceUri the resourceUri to set - */ - public void setResourceUri(String resourceUri) { - this.resourceUri = resourceUri; + if (resource == null) return null; + return resource.getUri(); } /** diff -r 54a4a96ad0c3 -r 0e00bf8e27fb src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java --- a/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java Wed Sep 26 17:30:52 2012 +0200 +++ b/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java Wed Sep 26 18:10:47 2012 +0200 @@ -487,12 +487,12 @@ Node target = rel.getEndNode(); String type = (String) target.getProperty("TYPE"); if (type.equals("TARGET")) { - annot.setTargetBaseUri((String) target.getProperty("uri", null)); + annot.setTarget(new Target((String) target.getProperty("uri", null))); } else if (type.equals("RESOURCE")) { - annot.setResourceUri((String) target.getProperty("uri", null)); + annot.setResource(new Resource((String) target.getProperty("uri", null))); } } - if (annot.getTargetBaseUri() == null) { + if (annot.getTarget() == null) { logger.error("annotation " + annotNode + " has no target node!"); } // get fragment from attribute @@ -652,10 +652,10 @@ /* * the annotation target */ - String targetBaseUri = annot.getTargetBaseUri(); + Target target = annot.getTarget(); Node targetNode = null; - if (targetBaseUri != null) { - targetNode = getOrCreateTargetNode(targetBaseUri, NodeTypes.TARGET); + if (target != null) { + targetNode = getOrCreateUriNode(target.getUri(), NodeTypes.TARGET); getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, targetNode); } @@ -672,11 +672,11 @@ /* * 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); + Resource resource = annot.getResource(); + if (resource != null) { + Node resourceNode = getOrCreateUriNode(resource.getUri(), NodeTypes.RESOURCE); + getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, resourceNode); + getOrCreateRelation(targetNode, RelationTypes.PART_OF, resourceNode); } /* @@ -891,7 +891,7 @@ return annotation; } - protected Node getOrCreateTargetNode(String uri, NodeTypes type) { + protected Node getOrCreateUriNode(String uri, NodeTypes type) { Index idx = getNodeIndex(type); IndexHits targets = idx.get("uri", uri); Node target = targets.getSingle(); diff -r 54a4a96ad0c3 -r 0e00bf8e27fb src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java --- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java Wed Sep 26 17:30:52 2012 +0200 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java Wed Sep 26 18:10:47 2012 +0200 @@ -39,6 +39,8 @@ import de.mpiwg.itgroup.annotations.Group; import de.mpiwg.itgroup.annotations.NS; import de.mpiwg.itgroup.annotations.Person; +import de.mpiwg.itgroup.annotations.Resource; +import de.mpiwg.itgroup.annotations.Target; import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; /** @@ -441,13 +443,13 @@ * target uri */ if (jo.has("uri")) { - annot.setTargetBaseUri(jo.getString("uri")); + annot.setTarget(new Target(jo.getString("uri"))); } /* * resource uri */ if (jo.has("resource")) { - annot.setResourceUri(jo.getString("resource")); + annot.setResource(new Resource(jo.getString("resource"))); } /* * annotation text