Changeset 68:39bc52f9b102 in AnnotationManagerN4J for src


Ignore:
Timestamp:
Feb 22, 2014, 3:12:37 PM (10 years ago)
Author:
casties
Branch:
default
Message:

(hopefully) fixed issues with neo4j 2.0 transactions.

Location:
src/main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java

    r67 r68  
    6363        nodeIndexes = new ArrayList<Index<Node>>(5);
    6464        // List.set(enum.ordinal(), val) seems not to work.
    65         try ( Transaction tx = graphDb.beginTx() ) {
     65        try (Transaction tx = graphDb.beginTx()) {
    6666            nodeIndexes.add(NodeTypes.ANNOTATION.ordinal(), graphDb.index().forNodes("annotations"));
    6767            nodeIndexes.add(NodeTypes.PERSON.ordinal(), graphDb.index().forNodes("persons"));
     
    119119     */
    120120    public Node getNodeFromIndex(String key, String value, NodeTypes type) {
    121         if (key == null || value == null) return null;
     121        if (key == null || value == null)
     122            return null;
    122123        Node node = null;
    123124        try (Transaction tx = graphDb.beginTx()) {
     
    151152                actors.add((T) actor);
    152153            }
    153             tx.success();
     154            tx.success();           
    154155        }
    155156        return actors;
     
    313314    public boolean isPersonInGroup(Person person, Group group) {
    314315        Node pn = getPersonNodeByUri(person.getUriString());
    315         if (pn == null) return false;
     316        if (pn == null)
     317            return false;
    316318        // optimized version of getGroupsForPersonNode
    317319        try (Transaction tx = graphDb.beginTx()) {
    318         Iterable<Relationship> rels = pn.getRelationships(RelationTypes.MEMBER_OF);
    319         for (Relationship rel : rels) {
    320             Node gn = rel.getEndNode();
    321             if (gn.getProperty("uri", "").equals(group.getUriString()) || gn.getProperty("id", "").equals(group.getId())) {
    322                 tx.success();
    323                 return true;
    324             }
    325         }
    326         tx.success();
     320            Iterable<Relationship> rels = pn.getRelationships(RelationTypes.MEMBER_OF);
     321            for (Relationship rel : rels) {
     322                Node gn = rel.getEndNode();
     323                if (gn.getProperty("uri", "").equals(group.getUriString())
     324                        || gn.getProperty("id", "").equals(group.getId())) {
     325                    tx.success();
     326                    return true;
     327                }
     328            }
     329            tx.success();
    327330        }
    328331        return false;
     
    382385            Node mn = rel.getStartNode();
    383386            if (mn.equals(pn)) {
    384                 Transaction tx = graphDb.beginTx();
    385                 try {
     387                try (Transaction tx = graphDb.beginTx()) {
    386388                    rel.delete();
    387389                    tx.success();
    388                 } finally {
    389                     tx.finish();
    390390                }
    391391                // there should be only one
     
    416416    public Actor storeActor(Actor actor) {
    417417        Node actorNode = getOrCreateActorNode(actor);
    418         Transaction tx = graphDb.beginTx();
    419         try {
     418        try (Transaction tx = graphDb.beginTx()) {
    420419            // id
    421420            String id = actor.getId();
     
    434433            }
    435434            tx.success();
    436         } finally {
    437             tx.finish();
    438435        }
    439436        Actor storedActor = createActorFromNode(actorNode);
     
    457454        if (actorNode != null) {
    458455            // delete relations
    459             Transaction tx = graphDb.beginTx();
    460             try {
     456            try (Transaction tx = graphDb.beginTx()) {
    461457                for (Relationship rel : actorNode.getRelationships()) {
    462458                    rel.delete();
     
    469465                }
    470466                tx.success();
    471             } finally {
    472                 tx.finish();
    473467            }
    474468        }
     
    483477    public Annotation getAnnotationById(String id) {
    484478        Annotation annot = null;
    485         try ( Transaction tx = graphDb.beginTx() ) {
    486         Node annotNode = getNodeIndex(NodeTypes.ANNOTATION).get("id", id).getSingle();
    487         annot = createAnnotationFromNode(annotNode);
    488         tx.success();
     479        try (Transaction tx = graphDb.beginTx()) {
     480            Node annotNode = getNodeIndex(NodeTypes.ANNOTATION).get("id", id).getSingle();
     481            annot = createAnnotationFromNode(annotNode);
     482            tx.success();
    489483        }
    490484        return annot;
     
    499493    public Annotation createAnnotationFromNode(Node annotNode) {
    500494        Annotation annot = new Annotation();
    501         try ( Transaction tx = graphDb.beginTx() ) {       
    502         annot.setUri((String) annotNode.getProperty("id", null));
    503         annot.setBodyText((String) annotNode.getProperty("bodyText", null));
    504         annot.setBodyUri((String) annotNode.getProperty("bodyUri", null));
    505         /*
    506          * get annotation target and resource from relation
    507          */
    508         for (Relationship rel : annotNode.getRelationships(RelationTypes.ANNOTATES)) {
    509             Node target = rel.getEndNode();
    510             String type = (String) target.getProperty("TYPE");
    511             if (type.equals("TARGET")) {
    512                 annot.setTarget(new Target((String) target.getProperty("uri", null)));
    513             } else if (type.equals("RESOURCE")) {
    514                 annot.setResource(new Resource((String) target.getProperty("uri", null)));
    515             }
    516         }
    517         if (annot.getTarget() == null) {
    518             logger.error("annotation " + annotNode + " has no target node!");
    519         }
    520         // get fragment from attribute
    521         annot.setTargetFragment((String) annotNode.getProperty("targetFragment", null));
    522         String ft = (String) annotNode.getProperty("fragmentType", null);
    523         if (ft != null) {
    524             annot.setFragmentType(FragmentTypes.valueOf(ft));
    525         }
    526         /*
    527          * get creator from relation
    528          */
    529         Relationship creatorRel = getRelation(annotNode, RelationTypes.CREATED, null);
    530         if (creatorRel != null) {
    531             Node creatorNode = creatorRel.getStartNode();
    532             Actor creator = createActorFromNode(creatorNode);
    533             annot.setCreator(creator);
    534         } else {
    535             logger.error("annotation " + annotNode + " has no creator node!");
    536         }
    537         /*
    538          * get creation date
    539          */
    540         annot.setCreated((String) annotNode.getProperty("created", null));
    541         /*
    542          * get permissions
    543          */
    544         Relationship adminRel = getRelation(annotNode, RelationTypes.PERMITS_ADMIN, null);
    545         if (adminRel != null) {
    546             Node adminNode = adminRel.getEndNode();
    547             Actor admin = createActorFromNode(adminNode);
    548             annot.setAdminPermission(admin);
    549         }
    550         Relationship deleteRel = getRelation(annotNode, RelationTypes.PERMITS_DELETE, null);
    551         if (deleteRel != null) {
    552             Node deleteNode = deleteRel.getEndNode();
    553             Actor delete = createActorFromNode(deleteNode);
    554             annot.setDeletePermission(delete);
    555         }
    556         Relationship updateRel = getRelation(annotNode, RelationTypes.PERMITS_UPDATE, null);
    557         if (updateRel != null) {
    558             Node updateNode = updateRel.getEndNode();
    559             Actor update = createActorFromNode(updateNode);
    560             annot.setUpdatePermission(update);
    561         }
    562         Relationship readRel = getRelation(annotNode, RelationTypes.PERMITS_READ, null);
    563         if (readRel != null) {
    564             Node readNode = readRel.getEndNode();
    565             Actor read = createActorFromNode(readNode);
    566             annot.setReadPermission(read);
    567         }
    568         /*
    569          * get tags
    570          */
    571         Set<String> tags = new HashSet<String>();
    572         for (Relationship rel : annotNode.getRelationships(RelationTypes.HAS_TAG)) {
    573             String tag = (String) rel.getEndNode().getProperty("name", null);
    574             if (tag != null) {
    575                 tags.add(tag);
    576             }
    577         }
    578         annot.setTags(tags);
    579        
    580         tx.success();
     495        try (Transaction tx = graphDb.beginTx()) {
     496            annot.setUri((String) annotNode.getProperty("id", null));
     497            annot.setBodyText((String) annotNode.getProperty("bodyText", null));
     498            annot.setBodyUri((String) annotNode.getProperty("bodyUri", null));
     499            /*
     500             * get annotation target and resource from relation
     501             */
     502            for (Relationship rel : annotNode.getRelationships(RelationTypes.ANNOTATES)) {
     503                Node target = rel.getEndNode();
     504                String type = (String) target.getProperty("TYPE");
     505                if (type.equals("TARGET")) {
     506                    annot.setTarget(new Target((String) target.getProperty("uri", null)));
     507                } else if (type.equals("RESOURCE")) {
     508                    annot.setResource(new Resource((String) target.getProperty("uri", null)));
     509                }
     510            }
     511            if (annot.getTarget() == null) {
     512                logger.warn("annotation " + annotNode + " has no target node!");
     513            }
     514            // get fragment from attribute
     515            annot.setTargetFragment((String) annotNode.getProperty("targetFragment", null));
     516            String ft = (String) annotNode.getProperty("fragmentType", null);
     517            if (ft != null) {
     518                annot.setFragmentType(FragmentTypes.valueOf(ft));
     519            }
     520            /*
     521             * get creator from relation
     522             */
     523            Relationship creatorRel = getRelation(annotNode, RelationTypes.CREATED, null);
     524            if (creatorRel != null) {
     525                Node creatorNode = creatorRel.getStartNode();
     526                Actor creator = createActorFromNode(creatorNode);
     527                annot.setCreator(creator);
     528            } else {
     529                logger.warn("annotation " + annotNode + " has no creator node!");
     530            }
     531            /*
     532             * get creation date
     533             */
     534            annot.setCreated((String) annotNode.getProperty("created", null));
     535            /*
     536             * get permissions
     537             */
     538            Relationship adminRel = getRelation(annotNode, RelationTypes.PERMITS_ADMIN, null);
     539            if (adminRel != null) {
     540                Node adminNode = adminRel.getEndNode();
     541                Actor admin = createActorFromNode(adminNode);
     542                annot.setAdminPermission(admin);
     543            }
     544            Relationship deleteRel = getRelation(annotNode, RelationTypes.PERMITS_DELETE, null);
     545            if (deleteRel != null) {
     546                Node deleteNode = deleteRel.getEndNode();
     547                Actor delete = createActorFromNode(deleteNode);
     548                annot.setDeletePermission(delete);
     549            }
     550            Relationship updateRel = getRelation(annotNode, RelationTypes.PERMITS_UPDATE, null);
     551            if (updateRel != null) {
     552                Node updateNode = updateRel.getEndNode();
     553                Actor update = createActorFromNode(updateNode);
     554                annot.setUpdatePermission(update);
     555            }
     556            Relationship readRel = getRelation(annotNode, RelationTypes.PERMITS_READ, null);
     557            if (readRel != null) {
     558                Node readNode = readRel.getEndNode();
     559                Actor read = createActorFromNode(readNode);
     560                annot.setReadPermission(read);
     561            }
     562            /*
     563             * get tags
     564             */
     565            Set<String> tags = new HashSet<String>();
     566            for (Relationship rel : annotNode.getRelationships(RelationTypes.HAS_TAG)) {
     567                String tag = (String) rel.getEndNode().getProperty("name", null);
     568                if (tag != null) {
     569                    tags.add(tag);
     570                }
     571            }
     572            annot.setTags(tags);
     573
     574            tx.success();
    581575        }
    582576        return annot;
     
    590584     */
    591585    protected Actor createActorFromNode(Node actorNode) {
    592         if (actorNode == null) return null;
    593         String id = (String) actorNode.getProperty("id", null);
    594         String uri = (String) actorNode.getProperty("uri", null);
    595         String name = (String) actorNode.getProperty("name", null);
    596         String type = (String) actorNode.getProperty("TYPE", null);
    597         if (type != null && type.equals("PERSON")) {
    598             return new Person(id, uri, name);
    599         } else if (type != null && type.equals("GROUP")) {
    600             return new Group(id, uri, name);
     586        if (actorNode == null)
     587            return null;
     588        try (Transaction tx = graphDb.beginTx()) {
     589            String id = (String) actorNode.getProperty("id", null);
     590            String uri = (String) actorNode.getProperty("uri", null);
     591            String name = (String) actorNode.getProperty("name", null);
     592            String type = (String) actorNode.getProperty("TYPE", null);
     593            tx.success();
     594            if (type != null && type.equals("PERSON")) {
     595                return new Person(id, uri, name);
     596            } else if (type != null && type.equals("GROUP")) {
     597                return new Group(id, uri, name);
     598            }
    601599        }
    602600        return null;
     
    604602
    605603    public Tag createTagFromNode(Node tagNode) {
    606         if (tagNode == null) return null;
    607         String name = (String) tagNode.getProperty("name", null);
    608         String uri = (String) tagNode.getProperty("uri", null);
    609         String id = (String) tagNode.getProperty("id", null);
    610 
     604        if (tagNode == null)
     605            return null;
     606        String id;
     607        String uri;
     608        String name;
     609        try (Transaction tx = graphDb.beginTx()) {
     610            name = (String) tagNode.getProperty("name", null);
     611            uri = (String) tagNode.getProperty("uri", null);
     612            id = (String) tagNode.getProperty("id", null);
     613            tx.success();
     614        }
    611615        return new Tag(id, uri, name);
    612616
     
    630634
    631635    protected Uri createUriFromNode(Node uriNode) {
    632         if (uriNode == null) return null;
    633         String uri = (String) uriNode.getProperty("uri", null);
    634         String type = (String) uriNode.getProperty("TYPE", null);
    635         if (type != null && type.equals("TARGET")) {
    636             return new Target(uri);
    637         } else if (type != null && type.equals("RESOURCE")) {
    638             return new Resource(uri);
     636        if (uriNode == null)
     637            return null;
     638        try (Transaction tx = graphDb.beginTx()) {
     639            String uri = (String) uriNode.getProperty("uri", null);
     640            String type = (String) uriNode.getProperty("TYPE", null);
     641            tx.success();
     642            if (type != null && type.equals("TARGET")) {
     643                return new Target(uri);
     644            } else if (type != null && type.equals("RESOURCE")) {
     645                return new Resource(uri);
     646            }
    639647        }
    640648        return null;
     
    650658    public Annotation storeAnnotation(Annotation annot) {
    651659        Node annotNode = null;
    652         Transaction tx = graphDb.beginTx();
    653         try {
     660        try (Transaction tx = graphDb.beginTx()) {
    654661            /*
    655662             * create or get the annotation
     
    672679                annotNode.setProperty("bodyUri", bodyUri);
    673680            }
    674 
     681               
    675682            /*
    676683             * the annotation target
     
    774781            }
    775782            tx.success();
    776         } finally {
    777             tx.finish();
    778783        }
    779784
     
    789794     */
    790795    public void deleteAnnotationById(String id) {
    791         Node annotNode = getNodeIndex(NodeTypes.ANNOTATION).get("id", id).getSingle();
    792         if (annotNode != null) {
    793             // delete related objects
    794             Transaction tx = graphDb.beginTx();
    795             try {
     796        try (Transaction tx = graphDb.beginTx()) {
     797            Node annotNode = getNodeIndex(NodeTypes.ANNOTATION).get("id", id).getSingle();
     798            if (annotNode != null) {
     799                // delete related objects
    796800                for (Relationship rel : annotNode.getRelationships()) {
    797801                    // delete relation and the related node if it has no other
     
    808812                    logger.error("deleteById: unable to delete: Node still has relations.");
    809813                }
    810                 tx.success();
    811             } finally {
    812                 tx.finish();
    813             }
     814            }
     815            tx.success();
    814816        }
    815817    }
     
    826828        if (targetUri != null) {
    827829            // there should be only one
    828             Node target = getNodeFromIndex("uri", targetUri, NodeTypes.TARGET); 
     830            Node target = getNodeFromIndex("uri", targetUri, NodeTypes.TARGET);
    829831            if (target != null) {
    830                 try ( Transaction tx = graphDb.beginTx() ) {
    831                 Iterable<Relationship> relations = target.getRelationships(RelationTypes.ANNOTATES);
    832                 for (Relationship relation : relations) {
    833                     Node ann = relation.getStartNode();
    834                     if (ann.getProperty("TYPE", "").equals("ANNOTATION")) {
    835                         Annotation annot = createAnnotationFromNode(ann);
    836                         annotations.add(annot);
    837                     } else {
    838                         logger.error("ANNOTATES relation does not start with ANNOTATION: " + ann);
     832                try (Transaction tx = graphDb.beginTx()) {
     833                    Iterable<Relationship> relations = target.getRelationships(RelationTypes.ANNOTATES);
     834                    for (Relationship relation : relations) {
     835                        Node ann = relation.getStartNode();
     836                        if (ann.getProperty("TYPE", "").equals("ANNOTATION")) {
     837                            Annotation annot = createAnnotationFromNode(ann);
     838                            annotations.add(annot);
     839                        } else {
     840                            logger.error("ANNOTATES relation does not start with ANNOTATION: " + ann);
     841                        }
    839842                    }
    840                 }
    841                 tx.success();
     843                    tx.success();
    842844                }
    843845            }
     
    847849            Node person = getPersonNodeByUri(userUri);
    848850            if (person != null) {
    849                 Iterable<Relationship> relations = person.getRelationships(RelationTypes.CREATED);
    850                 for (Relationship relation : relations) {
    851                     Node ann = relation.getEndNode();
    852                     if (ann.getProperty("TYPE", "").equals("ANNOTATION")) {
    853                         Annotation annot = createAnnotationFromNode(ann);
    854                         annotations.add(annot);
    855                     } else {
    856                         logger.error("CREATED relation does not end with ANNOTATION: " + ann);
     851                try (Transaction tx = graphDb.beginTx()) {
     852                    Iterable<Relationship> relations = person.getRelationships(RelationTypes.CREATED);
     853                    for (Relationship relation : relations) {
     854                        Node ann = relation.getEndNode();
     855                        if (ann.getProperty("TYPE", "").equals("ANNOTATION")) {
     856                            Annotation annot = createAnnotationFromNode(ann);
     857                            annotations.add(annot);
     858                        } else {
     859                            logger.error("CREATED relation does not end with ANNOTATION: " + ann);
     860                        }
    857861                    }
     862                    tx.success();
    858863                }
    859864            }
    860865        }
    861866        // TODO: if both uri and user are given we should intersect
    862        
     867
    863868        return annotations;
    864869    }
     
    874879     */
    875880    protected Relationship getOrCreateRelation(Node start, RelationshipType type, Node end) {
    876         if (start == null || end == null) return null;
     881        if (start == null || end == null)
     882            return null;
    877883        if (start.hasRelationship()) {
    878884            // there are relations
    879             Iterable<Relationship> rels = start.getRelationships(type, Direction.OUTGOING);
    880             for (Relationship rel : rels) {
    881                 if (rel.getEndNode().equals(end)) {
    882                     // relation exists
    883                     return rel;
    884                 }
     885            try (Transaction tx = graphDb.beginTx()) {
     886                Iterable<Relationship> rels = start.getRelationships(type, Direction.OUTGOING);
     887                for (Relationship rel : rels) {
     888                    if (rel.getEndNode().equals(end)) {
     889                        // relation exists
     890                        tx.success();
     891                        return rel;
     892                    }
     893                }
     894                tx.success();
    885895            }
    886896        }
    887897        // create new one
    888898        Relationship rel;
    889         Transaction tx = graphDb.beginTx();
    890         try {
     899        try (Transaction tx = graphDb.beginTx()) {
    891900            rel = start.createRelationshipTo(end, type);
    892901            tx.success();
    893         } finally {
    894             tx.finish();
    895902        }
    896903        return rel;
     
    899906    protected Node getOrCreateAnnotationNode(String id) {
    900907        Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION);
    901         IndexHits<Node> annotations = idx.get("id", id);
    902         Node annotation = annotations.getSingle();
    903         if (annotation == null) {
    904             // does not exist yet
    905             Transaction tx = graphDb.beginTx();
    906             try {
     908        Node annotation;
     909        try (Transaction tx = graphDb.beginTx()) {
     910            IndexHits<Node> annotations = idx.get("id", id);
     911            annotation = annotations.getSingle();
     912            if (annotation == null) {
     913                // does not exist yet
    907914                annotation = graphDb.createNode();
    908915                annotation.setProperty("TYPE", NodeTypes.ANNOTATION.name());
    909916                annotation.setProperty("id", id);
    910917                idx.add(annotation, "id", id);
    911                 tx.success();
    912             } finally {
    913                 tx.finish();
    914             }
     918            }
     919            tx.success();
    915920        }
    916921        return annotation;
     
    919924    protected Node getOrCreateUriNode(String uri, NodeTypes type) {
    920925        Index<Node> idx = getNodeIndex(type);
    921         IndexHits<Node> targets = idx.get("uri", uri);
    922         Node target = targets.getSingle();
    923         if (target == null) {
    924             // does not exist yet
    925             Transaction tx = graphDb.beginTx();
    926             try {
     926        Node target;
     927        try (Transaction tx = graphDb.beginTx()) {
     928            IndexHits<Node> targets = idx.get("uri", uri);
     929            target = targets.getSingle();
     930            if (target == null) {
     931                // does not exist yet
    927932                target = graphDb.createNode();
    928933                target.setProperty("TYPE", type.name());
    929934                target.setProperty("uri", uri);
    930935                idx.add(target, "uri", uri);
    931                 tx.success();
    932             } finally {
    933                 tx.finish();
    934             }
     936            }
     937            tx.success();
    935938        }
    936939        return target;
     
    941944        String uri = actor.getUriString();
    942945        Index<Node> idx;
     946        Node person;
    943947        if (actor.isGroup()) {
    944948            idx = getNodeIndex(NodeTypes.GROUP);
     
    946950            idx = getNodeIndex(NodeTypes.PERSON);
    947951        }
    948         IndexHits<Node> persons = idx.get("uri", uri);
    949         Node person = persons.getSingle();
     952        try (Transaction tx = graphDb.beginTx()) {
     953            IndexHits<Node> persons = idx.get("uri", uri);
     954            person = persons.getSingle();
     955            tx.success();
     956        }
    950957        return person;
    951958    }
     
    956963        String name = actor.getName();
    957964        String id = actor.getId();
    958         Index<Node> idx;
    959         if (actor.isGroup()) {
    960             idx = getNodeIndex(NodeTypes.GROUP);
    961         } else {
    962             idx = getNodeIndex(NodeTypes.PERSON);
    963         }
    964         IndexHits<Node> persons = idx.get("uri", uri);
    965         Node person = persons.getSingle();
    966         if (person == null) {
    967             // does not exist yet
    968             Transaction tx = graphDb.beginTx();
    969             try {
     965        Node person;
     966        try (Transaction tx = graphDb.beginTx()) {
     967            Index<Node> idx;
     968            if (actor.isGroup()) {
     969                idx = getNodeIndex(NodeTypes.GROUP);
     970            } else {
     971                idx = getNodeIndex(NodeTypes.PERSON);
     972            }
     973            IndexHits<Node> persons = idx.get("uri", uri);
     974            person = persons.getSingle();
     975            if (person == null) {
     976                // does not exist yet
    970977                person = graphDb.createNode();
    971978                if (actor.isGroup()) {
     
    982989                    person.setProperty("id", id);
    983990                }
    984                 tx.success();
    985             } finally {
    986                 tx.finish();
    987             }
     991            }
     992            tx.success();
    988993        }
    989994        return person;
     
    993998        Index<Node> idx = getNodeIndex(NodeTypes.TAG);
    994999        String tagname = inTag.getName();
    995         IndexHits<Node> tags = idx.get("name", tagname);
    996         Node tag = tags.getSingle();
    997         if (tag == null) {
    998             // does not exist yet
    999             Transaction tx = graphDb.beginTx();
    1000             try {
     1000        Node tag;
     1001        try (Transaction tx = graphDb.beginTx()) {
     1002            IndexHits<Node> tags = idx.get("name", tagname);
     1003            tag = tags.getSingle();
     1004            if (tag == null) {
     1005                // does not exist yet
    10011006                tag = graphDb.createNode();
    10021007                tag.setProperty("TYPE", NodeTypes.TAG.name());
     
    10071012                tag.setProperty("uri", inTag.getUri());
    10081013                idx.add(tag, "uri", inTag.getUri());
    1009 
    1010                 tx.success();
    1011             } finally {
    1012                 tx.finish();
    1013             }
     1014            }
     1015            tx.success();
    10141016        }
    10151017        return tag;
     
    10311033        if (rel != null) {
    10321034            // relation exists
    1033             Node oldActorNode = rel.getEndNode();
    1034             if (!oldActorNode.equals(newActorNode)) {
    1035                 // new admin is different
    1036                 Transaction tx = graphDb.beginTx();
    1037                 try {
     1035            try (Transaction tx = graphDb.beginTx()) {
     1036                Node oldActorNode = rel.getEndNode();
     1037                if (!oldActorNode.equals(newActorNode)) {
     1038                    // new admin is different
    10381039                    rel.delete();
    10391040                    tx.success();
    1040                 } finally {
    1041                     tx.finish();
    10421041                }
    10431042                if (newActorNode != null) {
    10441043                    rel = getOrCreateRelation(annotNode, type, newActorNode);
    10451044                }
     1045                tx.success();
    10461046            }
    10471047        } else {
     
    10591059     */
    10601060    protected void deleteNode(Node node) {
    1061         Transaction tx = graphDb.beginTx();
    1062         try {
     1061        try (Transaction tx = graphDb.beginTx()) {
    10631062            if (node.hasRelationship()) {
    10641063                logger.error("deleteNode: unable to delete: Node still has relations.");
     
    10741073            }
    10751074            tx.success();
    1076         } finally {
    1077             tx.finish();
    10781075        }
    10791076    }
     
    10891086    protected Relationship getRelation(Node start, RelationTypes type, Direction direction) {
    10901087        Iterable<Relationship> rels;
    1091         if (direction == null) {
    1092             // ignore direction
    1093             rels = start.getRelationships(type);
    1094         } else {
    1095             rels = start.getRelationships(type, direction);
    1096         }
    1097         for (Relationship rel : rels) {
    1098             // just the first one
    1099             return rel;
     1088        try (Transaction tx = graphDb.beginTx()) {
     1089            if (direction == null) {
     1090                // ignore direction
     1091                rels = start.getRelationships(type);
     1092            } else {
     1093                rels = start.getRelationships(type, direction);
     1094            }
     1095            tx.success();
     1096            for (Relationship rel : rels) {
     1097                // just the first one
     1098                return rel;
     1099            }
    11001100        }
    11011101        return null;
     
    11171117        Node tag = getTagNodeByUri(tagUri);
    11181118        if (tag != null) {
    1119             Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.HAS_TAG);
    1120             for (Relationship rel : rels) {
    1121                 Node node = rel.getStartNode();
    1122                 ret.add(createAnnotationFromNode(node));
     1119            try (Transaction tx = graphDb.beginTx()) {
     1120                Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.HAS_TAG);
     1121                for (Relationship rel : rels) {
     1122                    Node node = rel.getStartNode();
     1123                    ret.add(createAnnotationFromNode(node));
     1124                }
     1125                tx.success();
    11231126            }
    11241127        }
     
    11301133        Node res = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE);
    11311134        if (res != null) {
    1132             Iterable<Relationship> rels = res.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES);
    1133             for (Relationship rel : rels) {
    1134                 Node an = rel.getStartNode();
    1135                 Node rn = rel.getEndNode();
    1136                 if (rn.getProperty("TYPE", "").equals("RESOURCE")) {
    1137                     logger.error("getAnnotationsByResource got ANNOTATES != RESOURCE");
    1138                 }
    1139                 ret.add(createAnnotationFromNode(an));
     1135            try (Transaction tx = graphDb.beginTx()) {
     1136                Iterable<Relationship> rels = res.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES);
     1137                for (Relationship rel : rels) {
     1138                    Node an = rel.getStartNode();
     1139                    Node rn = rel.getEndNode();
     1140                    if (rn.getProperty("TYPE", "").equals("RESOURCE")) {
     1141                        logger.error("getAnnotationsByResource got ANNOTATES != RESOURCE");
     1142                    }
     1143                    ret.add(createAnnotationFromNode(an));
     1144                }
     1145                tx.success();
    11401146            }
    11411147        }
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java

    r63 r68  
    1515public class AnnotatorRestlet extends BaseRestlet {
    1616
    17     public final String version = "AnnotationManagerN4J/Annotator 0.3.1";
     17    public final String version = "AnnotationManagerN4J/Annotator 0.3.2";
    1818
    1919    public static Logger logger = Logger.getLogger(AnnotatorRestlet.class);
  • src/main/webapp/annotationBrowser/js/annotation.js

    r37 r68  
    2020                  for (var i=0;i<rows.length;i++){
    2121                          var text=rows[i]['text'];
    22                           var author=rows[i]['user']['name'];
     22                          var author= (rows[i]['user'] != null) ? rows[i]['user']['name'] : 'NO USER';
    2323                          var docUri=createLinkFromURI(rows[i]['uri']);
    2424                         
Note: See TracChangeset for help on using the changeset viewer.