Mercurial > hg > AnnotationManagerN4J
changeset 19:f0f55ab768c9
more work on HTML UI.
author | casties |
---|---|
date | Thu, 06 Sep 2012 19:02:59 +0200 |
parents | aafa3884b2c4 |
children | 715aa11d138b |
files | pom.xml src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotationStoreGroups.java src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java |
diffstat | 5 files changed, 32 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/pom.xml Wed Sep 05 18:05:54 2012 +0200 +++ b/pom.xml Thu Sep 06 19:02:59 2012 +0200 @@ -80,6 +80,11 @@ <artifactId>commons-codec</artifactId> <version>1.4</version> </dependency> + <dependency> + <groupId>org.restlet.jee</groupId> + <artifactId>org.restlet.lib.org.json</artifactId> + <version>2.0</version> + </dependency> </dependencies> <build> <finalName>AnnotationManager</finalName>
--- a/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java Wed Sep 05 18:05:54 2012 +0200 +++ b/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java Thu Sep 06 19:02:59 2012 +0200 @@ -75,15 +75,20 @@ /** * Returns List of Groups. + * Key has to be indexed. * - * @param person + * @param key + * @param query * @return */ - public List<Group> getGroups(String uriQuery) { + public List<Group> getGroups(String key, String query) { ArrayList<Group> groups = new ArrayList<Group>(); Index<Node> idx = getNodeIndex(NodeTypes.GROUP); - if (uriQuery == null) uriQuery = "*"; - IndexHits<Node> groupNodes = idx.get("uri", uriQuery); + if (key == null) { + key = "uri"; + query = "*"; + } + IndexHits<Node> groupNodes = idx.query(key, query); for (Node groupNode : groupNodes) { Actor group = createActorFromNode(groupNode); groups.add((Group) group);
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotationStoreGroups.java Wed Sep 05 18:05:54 2012 +0200 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotationStoreGroups.java Thu Sep 06 19:02:59 2012 +0200 @@ -34,29 +34,28 @@ // id from URI /annotations/groups/{id} String id = (String) getRequest().getAttributes().get("id"); logger.debug("group-id=" + id); - String retString="<html><body>\n<h1>Groups</h1>\n<table>"; + String result="<html><body>\n<h1>Groups</h1>\n<table>"; + result += "<tr><th>id</th><th>name</th><th>uri</th></tr>"; store = getAnnotationStore(); if (id == null) { // list all groups - List<Group> groups = store.getGroups("*"); + List<Group> groups = store.getGroups("uri", "*"); for (Group group : groups) { - retString += String.format("<tr><td>uri=%s</td></tr>\n", group.getUri()); + String groupLink = group.getId(); + result += String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", groupLink, group.getId(), group.getName(), group.getUri()); } } - retString += "</table>\n</body>\n</html>"; + result += "</table>\n</body>\n</html>"; logger.debug("sending:"); - logger.debug(retString); - return new StringRepresentation(retString,MediaType.TEXT_HTML); + logger.debug(result); + return new StringRepresentation(result,MediaType.TEXT_HTML); } protected AnnotationStore getAnnotationStore() { if (store == null) { - ServletContext sc = (ServletContext) getContext().getServerDispatcher().getContext().getAttributes() - .get("org.restlet.ext.servlet.ServletContext"); - logger.debug("Getting AnnotationStore from Context"); - store = (AnnotationStore) sc.getAttribute(BaseRestlet.ANNSTORE_KEY); + store = ((BaseRestlet) getApplication()).getAnnotationStore(); } return store; }
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java Wed Sep 05 18:05:54 2012 +0200 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java Thu Sep 06 19:02:59 2012 +0200 @@ -15,8 +15,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.servlet.ServletContext; - import net.oauth.jsontoken.Checker; import net.oauth.jsontoken.JsonToken; import net.oauth.jsontoken.JsonTokenParser; @@ -37,9 +35,9 @@ import de.mpiwg.itgroup.annotations.Actor; import de.mpiwg.itgroup.annotations.Annotation; -import de.mpiwg.itgroup.annotations.NS; import de.mpiwg.itgroup.annotations.Annotation.FragmentTypes; import de.mpiwg.itgroup.annotations.Group; +import de.mpiwg.itgroup.annotations.NS; import de.mpiwg.itgroup.annotations.Person; import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; @@ -61,10 +59,7 @@ protected AnnotationStore getAnnotationStore() { if (store == null) { - ServletContext sc = (ServletContext) getContext().getServerDispatcher().getContext().getAttributes() - .get("org.restlet.ext.servlet.ServletContext"); - logger.debug("Getting AnnotationStore from Context"); - store = (AnnotationStore) sc.getAttribute(BaseRestlet.ANNSTORE_KEY); + store = ((BaseRestlet) getApplication()).getAnnotationStore(); } return store; }
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java Wed Sep 05 18:05:54 2012 +0200 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java Thu Sep 06 19:02:59 2012 +0200 @@ -165,6 +165,13 @@ public abstract String getVersion(); /** + * @return the store + */ + public AnnotationStore getAnnotationStore() { + return store; + } + + /** * returns consumer secret for consumer key. returns null if consumer key * doesn't exist. *