Mercurial > hg > AnnotationManagerN4J
comparison src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java @ 43:d1bef7952bec
more work on resources and targets.
author | casties |
---|---|
date | Wed, 26 Sep 2012 16:27:52 +0200 |
parents | aa2bb7ac04d9 |
children | 707902d468f6 |
comparison
equal
deleted
inserted
replaced
42:aa2bb7ac04d9 | 43:d1bef7952bec |
---|---|
90 */ | 90 */ |
91 public Node getTagNodeByUri(String tagUri) { | 91 public Node getTagNodeByUri(String tagUri) { |
92 if (tagUri == null) return null; | 92 if (tagUri == null) return null; |
93 Node person = getNodeIndex(NodeTypes.TAG).get("uri", tagUri).getSingle(); | 93 Node person = getNodeIndex(NodeTypes.TAG).get("uri", tagUri).getSingle(); |
94 return person; | 94 return person; |
95 } | |
96 | |
97 /** | |
98 * @param resourceUri | |
99 * @return | |
100 */ | |
101 public Node getResourceNodeByUri(String resourceUri) { | |
102 return getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); | |
103 } | |
104 | |
105 /** | |
106 * @param targetUri | |
107 * @return | |
108 */ | |
109 public Node getTargetNodeByUri(String targetUri) { | |
110 return getNodeFromIndex("uri", targetUri, NodeTypes.RESOURCE); | |
95 } | 111 } |
96 | 112 |
97 /** | 113 /** |
98 * Returns the Node with the given key and value. | 114 * Returns the Node with the given key and value. |
99 * Key has to be indexed. | 115 * Key has to be indexed. |
564 | 580 |
565 return new Tag(id, uri, name); | 581 return new Tag(id, uri, name); |
566 | 582 |
567 } | 583 } |
568 | 584 |
585 /** | |
586 * @param resourceNode | |
587 * @return | |
588 */ | |
589 public Resource createResourceFromNode(Node resourceNode) { | |
590 return (Resource) createUriFromNode(resourceNode); | |
591 } | |
592 | |
593 /** | |
594 * @param targetNode | |
595 * @return | |
596 */ | |
597 public Target createTargetFromNode(Node targetNode) { | |
598 return (Target) createUriFromNode(targetNode); | |
599 } | |
600 | |
601 | |
569 protected Uri createUriFromNode(Node uriNode) { | 602 protected Uri createUriFromNode(Node uriNode) { |
570 if (uriNode == null) return null; | 603 if (uriNode == null) return null; |
571 String uri = (String) uriNode.getProperty("uri", null); | 604 String uri = (String) uriNode.getProperty("uri", null); |
572 String type = (String) uriNode.getProperty("TYPE", null); | 605 String type = (String) uriNode.getProperty("TYPE", null); |
573 if (type != null && type.equals("TARGET")) { | 606 if (type != null && type.equals("TARGET")) { |
1070 public List<Annotation> getAnnotationsByResource(String resourceUri) { | 1103 public List<Annotation> getAnnotationsByResource(String resourceUri) { |
1071 ArrayList<Annotation> ret = new ArrayList<Annotation>(); | 1104 ArrayList<Annotation> ret = new ArrayList<Annotation>(); |
1072 Node tag = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); | 1105 Node tag = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); |
1073 Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES); | 1106 Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES); |
1074 for (Relationship rel : rels) { | 1107 for (Relationship rel : rels) { |
1075 Node node = rel.getStartNode(); | 1108 Node an = rel.getStartNode(); |
1076 ret.add(createAnnotationFromNode(node)); | 1109 Node rn = rel.getEndNode(); |
1110 if (rn.getProperty("TYPE", "").equals("RESOURCE")) { | |
1111 logger.error("getAnnotationsByResource got ANNOTATES != RESOURCE"); | |
1112 } | |
1113 ret.add(createAnnotationFromNode(an)); | |
1077 } | 1114 } |
1078 return ret; | 1115 return ret; |
1079 } | 1116 } |
1080 | 1117 |
1081 } | 1118 } |