Mercurial > hg > AnnotationManagerN4J
comparison src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java @ 48:0e00bf8e27fb
targets and resources of Annotation object are objects now.
author | casties |
---|---|
date | Wed, 26 Sep 2012 18:10:47 +0200 |
parents | 707902d468f6 |
children | e2f86ef9b871 |
comparison
equal
deleted
inserted
replaced
47:54a4a96ad0c3 | 48:0e00bf8e27fb |
---|---|
485 */ | 485 */ |
486 for (Relationship rel : annotNode.getRelationships(RelationTypes.ANNOTATES)) { | 486 for (Relationship rel : annotNode.getRelationships(RelationTypes.ANNOTATES)) { |
487 Node target = rel.getEndNode(); | 487 Node target = rel.getEndNode(); |
488 String type = (String) target.getProperty("TYPE"); | 488 String type = (String) target.getProperty("TYPE"); |
489 if (type.equals("TARGET")) { | 489 if (type.equals("TARGET")) { |
490 annot.setTargetBaseUri((String) target.getProperty("uri", null)); | 490 annot.setTarget(new Target((String) target.getProperty("uri", null))); |
491 } else if (type.equals("RESOURCE")) { | 491 } else if (type.equals("RESOURCE")) { |
492 annot.setResourceUri((String) target.getProperty("uri", null)); | 492 annot.setResource(new Resource((String) target.getProperty("uri", null))); |
493 } | 493 } |
494 } | 494 } |
495 if (annot.getTargetBaseUri() == null) { | 495 if (annot.getTarget() == null) { |
496 logger.error("annotation " + annotNode + " has no target node!"); | 496 logger.error("annotation " + annotNode + " has no target node!"); |
497 } | 497 } |
498 // get fragment from attribute | 498 // get fragment from attribute |
499 annot.setTargetFragment((String) annotNode.getProperty("targetFragment", null)); | 499 annot.setTargetFragment((String) annotNode.getProperty("targetFragment", null)); |
500 String ft = (String) annotNode.getProperty("fragmentType", null); | 500 String ft = (String) annotNode.getProperty("fragmentType", null); |
650 } | 650 } |
651 | 651 |
652 /* | 652 /* |
653 * the annotation target | 653 * the annotation target |
654 */ | 654 */ |
655 String targetBaseUri = annot.getTargetBaseUri(); | 655 Target target = annot.getTarget(); |
656 Node targetNode = null; | 656 Node targetNode = null; |
657 if (targetBaseUri != null) { | 657 if (target != null) { |
658 targetNode = getOrCreateTargetNode(targetBaseUri, NodeTypes.TARGET); | 658 targetNode = getOrCreateUriNode(target.getUri(), NodeTypes.TARGET); |
659 getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, targetNode); | 659 getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, targetNode); |
660 } | 660 } |
661 | 661 |
662 /* | 662 /* |
663 * The fragment part of the annotation target. | 663 * The fragment part of the annotation target. |
670 } | 670 } |
671 | 671 |
672 /* | 672 /* |
673 * the annotation resource | 673 * the annotation resource |
674 */ | 674 */ |
675 String resourceUri = annot.getResourceUri(); | 675 Resource resource = annot.getResource(); |
676 if (resourceUri != null) { | 676 if (resource != null) { |
677 Node resource = getOrCreateTargetNode(resourceUri, NodeTypes.RESOURCE); | 677 Node resourceNode = getOrCreateUriNode(resource.getUri(), NodeTypes.RESOURCE); |
678 getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, resource); | 678 getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, resourceNode); |
679 getOrCreateRelation(targetNode, RelationTypes.PART_OF, resource); | 679 getOrCreateRelation(targetNode, RelationTypes.PART_OF, resourceNode); |
680 } | 680 } |
681 | 681 |
682 /* | 682 /* |
683 * The creator of this annotation. | 683 * The creator of this annotation. |
684 */ | 684 */ |
889 } | 889 } |
890 } | 890 } |
891 return annotation; | 891 return annotation; |
892 } | 892 } |
893 | 893 |
894 protected Node getOrCreateTargetNode(String uri, NodeTypes type) { | 894 protected Node getOrCreateUriNode(String uri, NodeTypes type) { |
895 Index<Node> idx = getNodeIndex(type); | 895 Index<Node> idx = getNodeIndex(type); |
896 IndexHits<Node> targets = idx.get("uri", uri); | 896 IndexHits<Node> targets = idx.get("uri", uri); |
897 Node target = targets.getSingle(); | 897 Node target = targets.getSingle(); |
898 if (target == null) { | 898 if (target == null) { |
899 // does not exist yet | 899 // does not exist yet |