changeset 67:875a97f8b8da

more quick fixes for neo4j 2.0.
author casties
date Fri, 21 Feb 2014 22:19:23 +0100
parents 5b568de5ee0d
children 39bc52f9b102
files src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java src/main/webapp/annotationBrowser/js/annotation-core.js
diffstat 2 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java	Wed Feb 19 14:38:31 2014 +0100
+++ b/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java	Fri Feb 21 22:19:23 2014 +0100
@@ -62,8 +62,7 @@
         this.graphDb = graphDb;
         nodeIndexes = new ArrayList<Index<Node>>(5);
         // List.set(enum.ordinal(), val) seems not to work.
-        try ( Transaction tx = graphDb.beginTx() )
-        {
+        try ( Transaction tx = graphDb.beginTx() ) {
             nodeIndexes.add(NodeTypes.ANNOTATION.ordinal(), graphDb.index().forNodes("annotations"));
             nodeIndexes.add(NodeTypes.PERSON.ordinal(), graphDb.index().forNodes("persons"));
             nodeIndexes.add(NodeTypes.TARGET.ordinal(), graphDb.index().forNodes("targets"));
@@ -120,7 +119,11 @@
      */
     public Node getNodeFromIndex(String key, String value, NodeTypes type) {
         if (key == null || value == null) return null;
-        Node node = getNodeIndex(type).get(key, value).getSingle();
+        Node node = null;
+        try (Transaction tx = graphDb.beginTx()) {
+            node = getNodeIndex(type).get(key, value).getSingle();
+            tx.success();
+        }
         return node;
     }
 
@@ -311,13 +314,17 @@
         Node pn = getPersonNodeByUri(person.getUriString());
         if (pn == null) return false;
         // optimized version of getGroupsForPersonNode
+        try (Transaction tx = graphDb.beginTx()) {
         Iterable<Relationship> rels = pn.getRelationships(RelationTypes.MEMBER_OF);
         for (Relationship rel : rels) {
             Node gn = rel.getEndNode();
             if (gn.getProperty("uri", "").equals(group.getUriString()) || gn.getProperty("id", "").equals(group.getId())) {
+                tx.success();
                 return true;
             }
         }
+        tx.success();
+        }
         return false;
     }
 
@@ -474,8 +481,12 @@
      * @return
      */
     public Annotation getAnnotationById(String id) {
+        Annotation annot = null;
+        try ( Transaction tx = graphDb.beginTx() ) {
         Node annotNode = getNodeIndex(NodeTypes.ANNOTATION).get("id", id).getSingle();
-        Annotation annot = createAnnotationFromNode(annotNode);
+        annot = createAnnotationFromNode(annotNode);
+        tx.success();
+        }
         return annot;
     }
 
@@ -487,6 +498,7 @@
      */
     public Annotation createAnnotationFromNode(Node annotNode) {
         Annotation annot = new Annotation();
+        try ( Transaction tx = graphDb.beginTx() ) {        
         annot.setUri((String) annotNode.getProperty("id", null));
         annot.setBodyText((String) annotNode.getProperty("bodyText", null));
         annot.setBodyUri((String) annotNode.getProperty("bodyUri", null));
@@ -564,7 +576,9 @@
             }
         }
         annot.setTags(tags);
-
+        
+        tx.success();
+        }
         return annot;
     }
 
@@ -813,6 +827,7 @@
             // there should be only one
             Node target = getNodeFromIndex("uri", targetUri, NodeTypes.TARGET); 
             if (target != null) {
+                try ( Transaction tx = graphDb.beginTx() ) {
                 Iterable<Relationship> relations = target.getRelationships(RelationTypes.ANNOTATES);
                 for (Relationship relation : relations) {
                     Node ann = relation.getStartNode();
@@ -823,6 +838,8 @@
                         logger.error("ANNOTATES relation does not start with ANNOTATION: " + ann);
                     }
                 }
+                tx.success();
+                }
             }
         }
         if (userUri != null) {
--- a/src/main/webapp/annotationBrowser/js/annotation-core.js	Wed Feb 19 14:38:31 2014 +0100
+++ b/src/main/webapp/annotationBrowser/js/annotation-core.js	Fri Feb 21 22:19:23 2014 +0100
@@ -17,13 +17,14 @@
 }
 
 function createLinkFromURI(uri){
+    if (uri == null) return "";
 	var docUri = uri.replace(docNamespace,viewerAddress);
 	docUri = docUri.replace("?pn","&pn");
 	return docUri;
 }
 
 function getDCdata(path,obj){
-	
+    if (path == null) return;
 	var splitted = path.split("?");
 	var docUri=splitted[0];