# HG changeset patch # User casties # Date 1353435403 -3600 # Node ID e2f86ef9b871577a31891a8bf7324b3883b5b35c # Parent f5c0e6df7e884ed6c0e904748fab9b6cd4ab3b0a make annotation uri in store configurable. fix npe with no tags. diff -r f5c0e6df7e88 -r e2f86ef9b871 src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java --- a/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java Tue Nov 20 18:23:52 2012 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java Tue Nov 20 19:16:43 2012 +0100 @@ -55,7 +55,7 @@ ANNOTATES, CREATED, PERMITS_ADMIN, PERMITS_DELETE, PERMITS_UPDATE, PERMITS_READ, MEMBER_OF, HAS_TAG, PART_OF } - public static String ANNOTATION_URI_BASE = "http://entities.mpiwg-berlin.mpg.de/annotations/"; + public static String ANNOTATION_URI_PREFIX = ""; public AnnotationStore(GraphDatabaseService graphDb) { super(); @@ -79,9 +79,7 @@ * @return */ public Node getPersonNodeByUri(String userUri) { - if (userUri == null) return null; - Node person = getNodeIndex(NodeTypes.PERSON).get("uri", userUri).getSingle(); - return person; + return getNodeFromIndex("uri", userUri, NodeTypes.PERSON); } /** @@ -89,9 +87,7 @@ * @return */ public Node getTagNodeByUri(String tagUri) { - if (tagUri == null) return null; - Node person = getNodeIndex(NodeTypes.TAG).get("uri", tagUri).getSingle(); - return person; + return getNodeFromIndex("uri", tagUri, NodeTypes.TAG); } /** @@ -111,8 +107,7 @@ } /** - * Returns the Node with the given key and value. - * Key has to be indexed. + * Returns the Node with the given key and value. Key has to be indexed. * * @param key * @param value @@ -121,13 +116,13 @@ */ public Node getNodeFromIndex(String key, String value, NodeTypes type) { if (key == null || value == null) return null; - Node person = getNodeIndex(type).get(key, value).getSingle(); - return person; + Node node = getNodeIndex(type).get(key, value).getSingle(); + return node; } /** - * Returns list of Actors of given type (Group or Person). - * Key has to be indexed. + * Returns list of Actors of given type (Group or Person). Key has to be + * indexed. * * @param key * @param query @@ -149,9 +144,10 @@ } return actors; } - + /** * Returns list of groups. Key has to be indexed. + * * @param key * @param query * @return @@ -160,9 +156,10 @@ List groups = getActors(key, query, NodeTypes.GROUP); return groups; } - + /** * Returns list of Persons. Key has to be indexed. + * * @param key * @param query * @return @@ -171,10 +168,10 @@ List persons = getActors(key, query, NodeTypes.PERSON); return persons; } - + /** - * Returns list of uri-like objects of given type (Target or Resource). - * Key has to be indexed. + * Returns list of uri-like objects of given type (Target or Resource). Key + * has to be indexed. * * @param key * @param query @@ -197,9 +194,9 @@ return uris; } - /** * Returns list of Targets. Key has to be indexed. + * * @param key * @param query * @return @@ -208,9 +205,10 @@ List targets = getUris(key, query, NodeTypes.TARGET); return targets; } - + /** * Returns list of Resources. Key has to be indexed. + * * @param key * @param query * @return @@ -219,10 +217,9 @@ List targets = getUris(key, query, NodeTypes.RESOURCE); return targets; } - + /** - * Returns List of Annotations. - * Key has to be indexed. + * Returns List of Annotations. Key has to be indexed. * * @param key * @param query @@ -243,11 +240,8 @@ return annotations; } - - /** - * Returns List of Tags. - * Key has to be indexed. + * Returns List of Tags. Key has to be indexed. * * @param key * @param query @@ -595,7 +589,7 @@ public Resource createResourceFromNode(Node resourceNode) { return (Resource) createUriFromNode(resourceNode); } - + /** * @param targetNode * @return @@ -603,8 +597,7 @@ public Target createTargetFromNode(Node targetNode) { return (Target) createUriFromNode(targetNode); } - - + protected Uri createUriFromNode(Node uriNode) { if (uriNode == null) return null; String uri = (String) uriNode.getProperty("uri", null); @@ -1082,41 +1075,37 @@ * @return */ private String createRessourceURI(String prefix) { - Calendar cal = Calendar.getInstance(); - long time = cal.getTimeInMillis(); - - return String.format("%s%s%s", ANNOTATION_URI_BASE, prefix, time); - + return String.format("%s%s%s", ANNOTATION_URI_PREFIX, prefix, time); } public List getAnnotationsByTag(String tagUri) { - ArrayList ret = new ArrayList(); Node tag = getTagNodeByUri(tagUri); - - Iterable rels = tag.getRelationships(Direction.INCOMING, RelationTypes.HAS_TAG); - - for (Relationship rel : rels) { - Node node = rel.getStartNode(); - ret.add(createAnnotationFromNode(node)); - + if (tag != null) { + Iterable rels = tag.getRelationships(Direction.INCOMING, RelationTypes.HAS_TAG); + for (Relationship rel : rels) { + Node node = rel.getStartNode(); + ret.add(createAnnotationFromNode(node)); + } } return ret; } public List getAnnotationsByResource(String resourceUri) { ArrayList ret = new ArrayList(); - Node tag = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); - Iterable rels = tag.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES); - for (Relationship rel : rels) { - Node an = rel.getStartNode(); - Node rn = rel.getEndNode(); - if (rn.getProperty("TYPE", "").equals("RESOURCE")) { - logger.error("getAnnotationsByResource got ANNOTATES != RESOURCE"); + Node res = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); + if (res != null) { + Iterable rels = res.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES); + for (Relationship rel : rels) { + Node an = rel.getStartNode(); + Node rn = rel.getEndNode(); + if (rn.getProperty("TYPE", "").equals("RESOURCE")) { + logger.error("getAnnotationsByResource got ANNOTATES != RESOURCE"); + } + ret.add(createAnnotationFromNode(an)); } - ret.add(createAnnotationFromNode(an)); } return ret; } diff -r f5c0e6df7e88 -r e2f86ef9b871 src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java --- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java Tue Nov 20 18:23:52 2012 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java Tue Nov 20 19:16:43 2012 +0100 @@ -99,6 +99,8 @@ public static String GROUPS_URI_PREFIX = ""; public static final String GROUPS_URI_KEY = "annotationmanager.uris.groups"; + public static final String ANNOTATIONS_URI_KEY = "annotationmanager.uris.annotations"; + /** * constructor * @@ -217,6 +219,10 @@ if (tup != null) { BaseRestlet.TAGS_URI_PREFIX = tup; } + String aup = (String) sc.getAttribute(ANNOTATIONS_URI_KEY); + if (aup != null) { + AnnotationStore.ANNOTATION_URI_PREFIX = aup; + } } else { logger.error("Unable to get ServletContext!"); } diff -r f5c0e6df7e88 -r e2f86ef9b871 src/main/webapp/WEB-INF/serverconfig.property.template --- a/src/main/webapp/WEB-INF/serverconfig.property.template Tue Nov 20 18:23:52 2012 +0100 +++ b/src/main/webapp/WEB-INF/serverconfig.property.template Tue Nov 20 19:16:43 2012 +0100 @@ -8,3 +8,4 @@ annotationmanager.uris.tags = http://entities.mpiwg-berlin.mpg.de/tags/ annotationmanager.uris.persons = http://entities.mpiwg-berlin.mpg.de/persons/ annotationmanager.uris.groups = http://entities.mpiwg-berlin.mpg.de/groups/ +annotationmanager.uris.annotations = http://entities.mpiwg-berlin.mpg.de/annotations/