Changeset 68:39bc52f9b102 in AnnotationManagerN4J
- Timestamp:
- Feb 22, 2014, 3:12:37 PM (11 years ago)
- Branch:
- default
- Location:
- src/main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java
r67 r68 63 63 nodeIndexes = new ArrayList<Index<Node>>(5); 64 64 // List.set(enum.ordinal(), val) seems not to work. 65 try ( Transaction tx = graphDb.beginTx()) {65 try (Transaction tx = graphDb.beginTx()) { 66 66 nodeIndexes.add(NodeTypes.ANNOTATION.ordinal(), graphDb.index().forNodes("annotations")); 67 67 nodeIndexes.add(NodeTypes.PERSON.ordinal(), graphDb.index().forNodes("persons")); … … 119 119 */ 120 120 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; 122 123 Node node = null; 123 124 try (Transaction tx = graphDb.beginTx()) { … … 151 152 actors.add((T) actor); 152 153 } 153 tx.success(); 154 tx.success(); 154 155 } 155 156 return actors; … … 313 314 public boolean isPersonInGroup(Person person, Group group) { 314 315 Node pn = getPersonNodeByUri(person.getUriString()); 315 if (pn == null) return false; 316 if (pn == null) 317 return false; 316 318 // optimized version of getGroupsForPersonNode 317 319 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(); 327 330 } 328 331 return false; … … 382 385 Node mn = rel.getStartNode(); 383 386 if (mn.equals(pn)) { 384 Transaction tx = graphDb.beginTx(); 385 try { 387 try (Transaction tx = graphDb.beginTx()) { 386 388 rel.delete(); 387 389 tx.success(); 388 } finally {389 tx.finish();390 390 } 391 391 // there should be only one … … 416 416 public Actor storeActor(Actor actor) { 417 417 Node actorNode = getOrCreateActorNode(actor); 418 Transaction tx = graphDb.beginTx(); 419 try { 418 try (Transaction tx = graphDb.beginTx()) { 420 419 // id 421 420 String id = actor.getId(); … … 434 433 } 435 434 tx.success(); 436 } finally {437 tx.finish();438 435 } 439 436 Actor storedActor = createActorFromNode(actorNode); … … 457 454 if (actorNode != null) { 458 455 // delete relations 459 Transaction tx = graphDb.beginTx(); 460 try { 456 try (Transaction tx = graphDb.beginTx()) { 461 457 for (Relationship rel : actorNode.getRelationships()) { 462 458 rel.delete(); … … 469 465 } 470 466 tx.success(); 471 } finally {472 tx.finish();473 467 } 474 468 } … … 483 477 public Annotation getAnnotationById(String id) { 484 478 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(); 489 483 } 490 484 return annot; … … 499 493 public Annotation createAnnotationFromNode(Node annotNode) { 500 494 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 relation507 */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 attribute521 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 relation528 */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 date539 */540 annot.setCreated((String) annotNode.getProperty("created", null));541 /*542 * get permissions543 */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 tags570 */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(); 581 575 } 582 576 return annot; … … 590 584 */ 591 585 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 } 601 599 } 602 600 return null; … … 604 602 605 603 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 } 611 615 return new Tag(id, uri, name); 612 616 … … 630 634 631 635 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 } 639 647 } 640 648 return null; … … 650 658 public Annotation storeAnnotation(Annotation annot) { 651 659 Node annotNode = null; 652 Transaction tx = graphDb.beginTx(); 653 try { 660 try (Transaction tx = graphDb.beginTx()) { 654 661 /* 655 662 * create or get the annotation … … 672 679 annotNode.setProperty("bodyUri", bodyUri); 673 680 } 674 681 675 682 /* 676 683 * the annotation target … … 774 781 } 775 782 tx.success(); 776 } finally {777 tx.finish();778 783 } 779 784 … … 789 794 */ 790 795 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 796 800 for (Relationship rel : annotNode.getRelationships()) { 797 801 // delete relation and the related node if it has no other … … 808 812 logger.error("deleteById: unable to delete: Node still has relations."); 809 813 } 810 tx.success(); 811 } finally { 812 tx.finish(); 813 } 814 } 815 tx.success(); 814 816 } 815 817 } … … 826 828 if (targetUri != null) { 827 829 // there should be only one 828 Node target = getNodeFromIndex("uri", targetUri, NodeTypes.TARGET); 830 Node target = getNodeFromIndex("uri", targetUri, NodeTypes.TARGET); 829 831 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 } 839 842 } 840 } 841 tx.success(); 843 tx.success(); 842 844 } 843 845 } … … 847 849 Node person = getPersonNodeByUri(userUri); 848 850 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 } 857 861 } 862 tx.success(); 858 863 } 859 864 } 860 865 } 861 866 // TODO: if both uri and user are given we should intersect 862 867 863 868 return annotations; 864 869 } … … 874 879 */ 875 880 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; 877 883 if (start.hasRelationship()) { 878 884 // 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(); 885 895 } 886 896 } 887 897 // create new one 888 898 Relationship rel; 889 Transaction tx = graphDb.beginTx(); 890 try { 899 try (Transaction tx = graphDb.beginTx()) { 891 900 rel = start.createRelationshipTo(end, type); 892 901 tx.success(); 893 } finally {894 tx.finish();895 902 } 896 903 return rel; … … 899 906 protected Node getOrCreateAnnotationNode(String id) { 900 907 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 yet905 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 907 914 annotation = graphDb.createNode(); 908 915 annotation.setProperty("TYPE", NodeTypes.ANNOTATION.name()); 909 916 annotation.setProperty("id", id); 910 917 idx.add(annotation, "id", id); 911 tx.success(); 912 } finally { 913 tx.finish(); 914 } 918 } 919 tx.success(); 915 920 } 916 921 return annotation; … … 919 924 protected Node getOrCreateUriNode(String uri, NodeTypes type) { 920 925 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 yet925 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 927 932 target = graphDb.createNode(); 928 933 target.setProperty("TYPE", type.name()); 929 934 target.setProperty("uri", uri); 930 935 idx.add(target, "uri", uri); 931 tx.success(); 932 } finally { 933 tx.finish(); 934 } 936 } 937 tx.success(); 935 938 } 936 939 return target; … … 941 944 String uri = actor.getUriString(); 942 945 Index<Node> idx; 946 Node person; 943 947 if (actor.isGroup()) { 944 948 idx = getNodeIndex(NodeTypes.GROUP); … … 946 950 idx = getNodeIndex(NodeTypes.PERSON); 947 951 } 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 } 950 957 return person; 951 958 } … … 956 963 String name = actor.getName(); 957 964 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 yet968 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 970 977 person = graphDb.createNode(); 971 978 if (actor.isGroup()) { … … 982 989 person.setProperty("id", id); 983 990 } 984 tx.success(); 985 } finally { 986 tx.finish(); 987 } 991 } 992 tx.success(); 988 993 } 989 994 return person; … … 993 998 Index<Node> idx = getNodeIndex(NodeTypes.TAG); 994 999 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 yet999 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 1001 1006 tag = graphDb.createNode(); 1002 1007 tag.setProperty("TYPE", NodeTypes.TAG.name()); … … 1007 1012 tag.setProperty("uri", inTag.getUri()); 1008 1013 idx.add(tag, "uri", inTag.getUri()); 1009 1010 tx.success(); 1011 } finally { 1012 tx.finish(); 1013 } 1014 } 1015 tx.success(); 1014 1016 } 1015 1017 return tag; … … 1031 1033 if (rel != null) { 1032 1034 // 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 1038 1039 rel.delete(); 1039 1040 tx.success(); 1040 } finally {1041 tx.finish();1042 1041 } 1043 1042 if (newActorNode != null) { 1044 1043 rel = getOrCreateRelation(annotNode, type, newActorNode); 1045 1044 } 1045 tx.success(); 1046 1046 } 1047 1047 } else { … … 1059 1059 */ 1060 1060 protected void deleteNode(Node node) { 1061 Transaction tx = graphDb.beginTx(); 1062 try { 1061 try (Transaction tx = graphDb.beginTx()) { 1063 1062 if (node.hasRelationship()) { 1064 1063 logger.error("deleteNode: unable to delete: Node still has relations."); … … 1074 1073 } 1075 1074 tx.success(); 1076 } finally {1077 tx.finish();1078 1075 } 1079 1076 } … … 1089 1086 protected Relationship getRelation(Node start, RelationTypes type, Direction direction) { 1090 1087 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 } 1100 1100 } 1101 1101 return null; … … 1117 1117 Node tag = getTagNodeByUri(tagUri); 1118 1118 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(); 1123 1126 } 1124 1127 } … … 1130 1133 Node res = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); 1131 1134 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(); 1140 1146 } 1141 1147 } -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java
r63 r68 15 15 public class AnnotatorRestlet extends BaseRestlet { 16 16 17 public final String version = "AnnotationManagerN4J/Annotator 0.3. 1";17 public final String version = "AnnotationManagerN4J/Annotator 0.3.2"; 18 18 19 19 public static Logger logger = Logger.getLogger(AnnotatorRestlet.class); -
src/main/webapp/annotationBrowser/js/annotation.js
r37 r68 20 20 for (var i=0;i<rows.length;i++){ 21 21 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'; 23 23 var docUri=createLinkFromURI(rows[i]['uri']); 24 24
Note: See TracChangeset
for help on using the changeset viewer.