Changeset 28:f4ed2ed33e5b in AnnotationManagerN4J for src


Ignore:
Timestamp:
Sep 25, 2012, 7:32:56 AM (12 years ago)
Author:
dwinter
Branch:
default
Message:

Restinterface zur Anzeige von Tags hinzugefuegt-

Location:
src/main/java/de/mpiwg/itgroup/annotations
Files:
4 added
3 edited

Legend:

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

    r18 r28  
    33public class NS {
    44    public static final String MPIWG_PERSONS_URL = "http://entities.mpiwg-berlin.mpg.de/persons/";
     5    public static final String MPIWG_TAGS_URL = "http://entities.mpiwg-berlin.mpg.de/tags/";
    56    public static final String MPIWG_GROUPS_URL = "http://entities.mpiwg-berlin.mpg.de/groups/";
    67    public static final String OAC_NS = "http://www.openannotation.org/ns/";
  • src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java

    r24 r28  
    2525import de.mpiwg.itgroup.annotations.Group;
    2626import de.mpiwg.itgroup.annotations.Person;
     27import de.mpiwg.itgroup.annotations.Tag;
    2728
    2829/**
     
    7475    }
    7576
     77    /**
     78     * @param tagUri
     79     * @return
     80     */
     81    public Node getTagNodeByUri(String tagUri) {
     82        if (tagUri == null) return null;
     83        Node person = getNodeIndex(NodeTypes.TAG).get("uri", tagUri).getSingle();
     84        return person;
     85    }
     86
    7687    public List<Actor> getActors(String key, String query, NodeTypes type) {
    7788        ArrayList<Actor> actors = new ArrayList<Actor>();
     
    111122        return groups;
    112123    }
    113 
    114     /**
     124   
     125   
     126    /**
     127     * Returns List of Tags.
     128     * Key has to be indexed.
     129     *
     130     * @param key
     131     * @param query
     132     * @return
     133     */
     134    public List<Tag> getTags(String key, String query) {
     135        ArrayList<Tag> tags = new ArrayList<Tag>();
     136        Index<Node> idx = getNodeIndex(NodeTypes.TAG);
     137        if (key == null) {
     138            key = "uri";
     139            query = "*";
     140        }
     141        IndexHits<Node> groupNodes = idx.query(key, query);
     142        for (Node groupNode : groupNodes) {
     143            Tag tag = createTagFromNode(groupNode);
     144            tags.add(tag);
     145        }
     146        return tags;
     147    }
     148
     149 
     150   /**
    115151     * Returns List of Groups the person is member of.
    116152     *
     
    315351        return null;
    316352    }
     353   
     354    public Tag createTagFromNode(Node tagNode) {
     355        String name = (String) tagNode.getProperty("name", null);
     356        String uri = (String) tagNode.getProperty("uri", null);
     357        String id = (String) tagNode.getProperty("id", null);
     358       
     359        return new Tag(id, uri, name);
     360               
     361        }
     362
    317363
    318364    /**
     
    430476                        for (String tag : newTags) {
    431477                            // create new tag
    432                             Node tagNode = getOrCreateTagNode(tag);
     478                            Node tagNode = getOrCreateTagNode(new Tag(null,null,tag));
    433479                            getOrCreateRelation(annotNode, RelationTypes.HAS_TAG, tagNode);
    434480                        }
     
    651697    }
    652698
    653     protected Node getOrCreateTagNode(String tagname) {
     699    protected Node getOrCreateTagNode(Tag inTag) {
    654700        Index<Node> idx = getNodeIndex(NodeTypes.TAG);
     701        String tagname = inTag.getName();
    655702        IndexHits<Node> tags = idx.get("name", tagname);
    656703        Node tag = tags.getSingle();
     
    663710                tag.setProperty("name", tagname);
    664711                idx.add(tag, "name", tagname);
     712               
     713                tag.setProperty("id", inTag.getId());
     714                tag.setProperty("uri", inTag.getUri());
     715                idx.add(tag, "uri", inTag.getUri());
     716               
    665717                tx.success();
    666718            } finally {
     
    766818    }
    767819
     820        public List<Annotation> getAnnotationsByTag(String tagUri) {
     821               
     822                ArrayList<Annotation> ret = new  ArrayList<Annotation>();
     823                Node tag = getTagNodeByUri(tagUri);
     824               
     825               
     826                Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING,RelationTypes.HAS_TAG);
     827               
     828                for (Relationship rel:rels){
     829                        Node node = rel.getStartNode();
     830                        ret.add(createAnnotationFromNode(node));
     831                       
     832                }
     833                return ret;
     834        }
     835
    768836}
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java

    r18 r28  
    4242        router.attach("/search", AnnotatorSearch.class);
    4343        router.attach("/groups", AnnotatorGroups.class);
    44 
     44        router.attach("/tags", AnnotatorTags.class);
     45        router.attach("/tags/{id}", AnnotatorTags.class);
     46        router.attach("/tags/{id}", AnnotatorTags.class);
     47        router.attach("/tags/{id}/annotations", AnnotatorAnnotationsByTags.class);
    4548        router.attach("/", AnnotatorInfo.class);
    4649        // authenticator.setNext(router);
Note: See TracChangeset for help on using the changeset viewer.