Changeset 59:e2f86ef9b871 in AnnotationManagerN4J for src


Ignore:
Timestamp:
Nov 20, 2012, 6:16:43 PM (11 years ago)
Author:
casties
Branch:
default
Message:

make annotation uri in store configurable. fix npe with no tags.

Location:
src/main
Files:
3 edited

Legend:

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

    r48 r59  
    5656    }
    5757
    58     public static String ANNOTATION_URI_BASE = "http://entities.mpiwg-berlin.mpg.de/annotations/";
     58    public static String ANNOTATION_URI_PREFIX = "";
    5959
    6060    public AnnotationStore(GraphDatabaseService graphDb) {
     
    8080     */
    8181    public Node getPersonNodeByUri(String userUri) {
    82         if (userUri == null) return null;
    83         Node person = getNodeIndex(NodeTypes.PERSON).get("uri", userUri).getSingle();
    84         return person;
     82        return getNodeFromIndex("uri", userUri, NodeTypes.PERSON);
    8583    }
    8684
     
    9088     */
    9189    public Node getTagNodeByUri(String tagUri) {
    92         if (tagUri == null) return null;
    93         Node person = getNodeIndex(NodeTypes.TAG).get("uri", tagUri).getSingle();
    94         return person;
     90        return getNodeFromIndex("uri", tagUri, NodeTypes.TAG);
    9591    }
    9692
     
    112108
    113109    /**
    114      * Returns the Node with the given key and value.
    115      * Key has to be indexed.
     110     * Returns the Node with the given key and value. Key has to be indexed.
    116111     *
    117112     * @param key
     
    122117    public Node getNodeFromIndex(String key, String value, NodeTypes type) {
    123118        if (key == null || value == null) return null;
    124         Node person = getNodeIndex(type).get(key, value).getSingle();
    125         return person;
    126     }
    127 
    128     /**
    129      * Returns list of Actors of given type (Group or Person).
    130      * Key has to be indexed.
     119        Node node = getNodeIndex(type).get(key, value).getSingle();
     120        return node;
     121    }
     122
     123    /**
     124     * Returns list of Actors of given type (Group or Person). Key has to be
     125     * indexed.
    131126     *
    132127     * @param key
     
    150145        return actors;
    151146    }
    152    
     147
    153148    /**
    154149     * Returns list of groups. Key has to be indexed.
     150     *
    155151     * @param key
    156152     * @param query
     
    161157        return groups;
    162158    }
    163    
     159
    164160    /**
    165161     * Returns list of Persons. Key has to be indexed.
     162     *
    166163     * @param key
    167164     * @param query
     
    172169        return persons;
    173170    }
    174    
    175     /**
    176      * Returns list of uri-like objects of given type (Target or Resource).
    177      * Key has to be indexed.
     171
     172    /**
     173     * Returns list of uri-like objects of given type (Target or Resource). Key
     174     * has to be indexed.
    178175     *
    179176     * @param key
     
    198195    }
    199196
    200    
    201197    /**
    202198     * Returns list of Targets. Key has to be indexed.
     199     *
    203200     * @param key
    204201     * @param query
     
    209206        return targets;
    210207    }
    211    
     208
    212209    /**
    213210     * Returns list of Resources. Key has to be indexed.
     211     *
    214212     * @param key
    215213     * @param query
     
    220218        return targets;
    221219    }
    222    
    223     /**
    224      * Returns List of Annotations.
    225      * Key has to be indexed.
     220
     221    /**
     222     * Returns List of Annotations. Key has to be indexed.
    226223     *
    227224     * @param key
     
    244241    }
    245242
    246  
    247    
    248     /**
    249      * Returns List of Tags.
    250      * Key has to be indexed.
     243    /**
     244     * Returns List of Tags. Key has to be indexed.
    251245     *
    252246     * @param key
     
    596590        return (Resource) createUriFromNode(resourceNode);
    597591    }
    598    
     592
    599593    /**
    600594     * @param targetNode
     
    604598        return (Target) createUriFromNode(targetNode);
    605599    }
    606    
    607    
     600
    608601    protected Uri createUriFromNode(Node uriNode) {
    609602        if (uriNode == null) return null;
     
    10831076     */
    10841077    private String createRessourceURI(String prefix) {
    1085 
    10861078        Calendar cal = Calendar.getInstance();
    1087 
    10881079        long time = cal.getTimeInMillis();
    1089 
    1090         return String.format("%s%s%s", ANNOTATION_URI_BASE, prefix, time);
    1091 
     1080        return String.format("%s%s%s", ANNOTATION_URI_PREFIX, prefix, time);
    10921081    }
    10931082
    10941083    public List<Annotation> getAnnotationsByTag(String tagUri) {
    1095 
    10961084        ArrayList<Annotation> ret = new ArrayList<Annotation>();
    10971085        Node tag = getTagNodeByUri(tagUri);
    1098 
    1099         Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.HAS_TAG);
    1100 
    1101         for (Relationship rel : rels) {
    1102             Node node = rel.getStartNode();
    1103             ret.add(createAnnotationFromNode(node));
    1104 
     1086        if (tag != null) {
     1087            Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.HAS_TAG);
     1088            for (Relationship rel : rels) {
     1089                Node node = rel.getStartNode();
     1090                ret.add(createAnnotationFromNode(node));
     1091            }
    11051092        }
    11061093        return ret;
     
    11091096    public List<Annotation> getAnnotationsByResource(String resourceUri) {
    11101097        ArrayList<Annotation> ret = new ArrayList<Annotation>();
    1111         Node tag = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE);
    1112         Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES);
    1113         for (Relationship rel : rels) {
    1114             Node an = rel.getStartNode();
    1115             Node rn = rel.getEndNode();
    1116             if (rn.getProperty("TYPE", "").equals("RESOURCE")) {
    1117                 logger.error("getAnnotationsByResource got ANNOTATES != RESOURCE");
    1118             }
    1119             ret.add(createAnnotationFromNode(an));
     1098        Node res = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE);
     1099        if (res != null) {
     1100            Iterable<Relationship> rels = res.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES);
     1101            for (Relationship rel : rels) {
     1102                Node an = rel.getStartNode();
     1103                Node rn = rel.getEndNode();
     1104                if (rn.getProperty("TYPE", "").equals("RESOURCE")) {
     1105                    logger.error("getAnnotationsByResource got ANNOTATES != RESOURCE");
     1106                }
     1107                ret.add(createAnnotationFromNode(an));
     1108            }
    11201109        }
    11211110        return ret;
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java

    r58 r59  
    9999    public static String GROUPS_URI_PREFIX = "";
    100100    public static final String GROUPS_URI_KEY = "annotationmanager.uris.groups";
     101
     102    public static final String ANNOTATIONS_URI_KEY = "annotationmanager.uris.annotations";
    101103
    102104    /**
     
    218220                BaseRestlet.TAGS_URI_PREFIX = tup;
    219221            }
     222            String aup = (String) sc.getAttribute(ANNOTATIONS_URI_KEY);
     223            if (aup != null) {
     224                AnnotationStore.ANNOTATION_URI_PREFIX = aup;
     225            }
    220226        } else {
    221227            logger.error("Unable to get ServletContext!");
  • src/main/webapp/WEB-INF/serverconfig.property.template

    r58 r59  
    99annotationmanager.uris.persons = http://entities.mpiwg-berlin.mpg.de/persons/
    1010annotationmanager.uris.groups = http://entities.mpiwg-berlin.mpg.de/groups/
     11annotationmanager.uris.annotations = http://entities.mpiwg-berlin.mpg.de/annotations/
Note: See TracChangeset for help on using the changeset viewer.