Mercurial > hg > AnnotationManagerN4J
changeset 59:e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
author | casties |
---|---|
date | Tue, 20 Nov 2012 19:16:43 +0100 |
parents | f5c0e6df7e88 |
children | 99d9afcfd04d |
files | src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java src/main/webapp/WEB-INF/serverconfig.property.template |
diffstat | 3 files changed, 47 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- 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<Group> 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<Person> 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<Target> 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<Resource> 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<Annotation> getAnnotationsByTag(String tagUri) { - ArrayList<Annotation> ret = new ArrayList<Annotation>(); Node tag = getTagNodeByUri(tagUri); - - Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.HAS_TAG); - - for (Relationship rel : rels) { - Node node = rel.getStartNode(); - ret.add(createAnnotationFromNode(node)); - + if (tag != null) { + Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.HAS_TAG); + for (Relationship rel : rels) { + Node node = rel.getStartNode(); + ret.add(createAnnotationFromNode(node)); + } } return ret; } public List<Annotation> getAnnotationsByResource(String resourceUri) { ArrayList<Annotation> ret = new ArrayList<Annotation>(); - Node tag = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); - Iterable<Relationship> 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<Relationship> 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; }
--- 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!"); }
--- 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/