comparison src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java @ 8:c3cc6a41dd1c

under construction
author casties
date Thu, 12 Jul 2012 11:14:39 +0200
parents 6dfbe2400f64
children b2bfc3bc9ba8
comparison
equal deleted inserted replaced
7:798a65338565 8:c3cc6a41dd1c
35 } 35 }
36 36
37 protected List<Index<Node>> nodeIndexes; 37 protected List<Index<Node>> nodeIndexes;
38 38
39 public static enum RelationTypes implements RelationshipType { 39 public static enum RelationTypes implements RelationshipType {
40 ANNOTATES, CREATED 40 ANNOTATES, CREATED, PERMITS
41 } 41 }
42 42
43 public static String ANNOTATION_URI_BASE = "http://entities.mpiwg-berlin.mpg.de/annotations/"; 43 public static String ANNOTATION_URI_BASE = "http://entities.mpiwg-berlin.mpg.de/annotations/";
44 44
45 public AnnotationStore(GraphDatabaseService graphDb) { 45 public AnnotationStore(GraphDatabaseService graphDb) {
62 * @param id 62 * @param id
63 * @return 63 * @return
64 */ 64 */
65 public Annotation getAnnotationById(String id) { 65 public Annotation getAnnotationById(String id) {
66 Node annotNode = getNodeIndex(NodeTypes.ANNOTATION).get("id", id).getSingle(); 66 Node annotNode = getNodeIndex(NodeTypes.ANNOTATION).get("id", id).getSingle();
67 Annotation annot = createAnnotation(annotNode); 67 Annotation annot = createAnnotationFromNode(annotNode);
68 return annot; 68 return annot;
69 } 69 }
70 70
71 /** 71 /**
72 * Returns an Annotation object from an annotation-Node. 72 * Returns an Annotation object from an annotation-Node.
73 * 73 *
74 * @param annotNode 74 * @param annotNode
75 * @return 75 * @return
76 */ 76 */
77 public Annotation createAnnotation(Node annotNode) { 77 public Annotation createAnnotationFromNode(Node annotNode) {
78 Annotation annot = new Annotation(); 78 Annotation annot = new Annotation();
79 annot.setUri((String) annotNode.getProperty("id", null)); 79 annot.setUri((String) annotNode.getProperty("id", null));
80 annot.setBodyText((String) annotNode.getProperty("bodyText", null)); 80 annot.setBodyText((String) annotNode.getProperty("bodyText", null));
81 annot.setBodyUri((String) annotNode.getProperty("bodyUri", null)); 81 annot.setBodyUri((String) annotNode.getProperty("bodyUri", null));
82 // get annotation target from relation 82 // get annotation target from relation
185 } finally { 185 } finally {
186 tx.finish(); 186 tx.finish();
187 } 187 }
188 188
189 // re-read and return annotation 189 // re-read and return annotation
190 Annotation storedAnnot = createAnnotation(annotNode); 190 Annotation storedAnnot = createAnnotationFromNode(annotNode);
191 return storedAnnot; 191 return storedAnnot;
192 } 192 }
193 193
194 /** 194 /**
195 * Deletes the annotation with the given id. 195 * Deletes the annotation with the given id.
218 tx.success(); 218 tx.success();
219 } finally { 219 } finally {
220 tx.finish(); 220 tx.finish();
221 } 221 }
222 } 222 }
223
224 } 223 }
225 224
226 /** 225 /**
227 * Returns all annotations with the given uri and/or user. 226 * Returns all annotations with the given uri and/or user.
228 * 227 *
242 Iterable<Relationship> relations = target 241 Iterable<Relationship> relations = target
243 .getRelationships(RelationTypes.ANNOTATES); 242 .getRelationships(RelationTypes.ANNOTATES);
244 for (Relationship relation : relations) { 243 for (Relationship relation : relations) {
245 Node ann = relation.getStartNode(); 244 Node ann = relation.getStartNode();
246 if (ann.getProperty("TYPE", "").equals("ANNOTATION")) { 245 if (ann.getProperty("TYPE", "").equals("ANNOTATION")) {
247 Annotation annot = createAnnotation(ann); 246 Annotation annot = createAnnotationFromNode(ann);
248 annotations.add(annot); 247 annotations.add(annot);
249 } else { 248 } else {
250 logger.error("ANNOTATES relation does not start with ANNOTATION: " 249 logger.error("ANNOTATES relation does not start with ANNOTATION: "
251 + ann); 250 + ann);
252 } 251 }
260 Iterable<Relationship> relations = person 259 Iterable<Relationship> relations = person
261 .getRelationships(RelationTypes.CREATED); 260 .getRelationships(RelationTypes.CREATED);
262 for (Relationship relation : relations) { 261 for (Relationship relation : relations) {
263 Node ann = relation.getEndNode(); 262 Node ann = relation.getEndNode();
264 if (ann.getProperty("TYPE", "").equals("ANNOTATION")) { 263 if (ann.getProperty("TYPE", "").equals("ANNOTATION")) {
265 Annotation annot = createAnnotation(ann); 264 Annotation annot = createAnnotationFromNode(ann);
266 annotations.add(annot); 265 annotations.add(annot);
267 } else { 266 } else {
268 logger.error("CREATED relation does not end with ANNOTATION: " 267 logger.error("CREATED relation does not end with ANNOTATION: "
269 + ann); 268 + ann);
270 } 269 }