annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotationStoreGroups.java @ 21:1ac626309352

more work on HTML UI (doesn't work yet).
author casties
date Fri, 07 Sep 2012 18:10:18 +0200
parents f0f55ab768c9
children b1fb0d117877
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
1 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
2 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
3 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
4 package de.mpiwg.itgroup.annotations.restlet;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
5
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
6 import java.util.List;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
7
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
8 import javax.servlet.ServletContext;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
9
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
10 import org.apache.log4j.Logger;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
11 import org.restlet.data.Form;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
12 import org.restlet.data.MediaType;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
13 import org.restlet.representation.Representation;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
14 import org.restlet.representation.StringRepresentation;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
15 import org.restlet.resource.Get;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
16 import org.restlet.resource.ServerResource;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
17
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
18 import de.mpiwg.itgroup.annotations.Group;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
19 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
20
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
21 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
22 * @author casties
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
23 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
24 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
25 public class AnnotationStoreGroups extends ServerResource {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
26
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
27 public static Logger logger = Logger.getLogger(AnnotationStoreGroups.class);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
28
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
29 private AnnotationStore store;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
30
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
31 @Get("html")
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
32 public Representation doGetHTML(Representation entity){
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
33 Form form = getRequest().getResourceRef().getQueryAsForm();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
34 // id from URI /annotations/groups/{id}
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
35 String id = (String) getRequest().getAttributes().get("id");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
36 logger.debug("group-id=" + id);
19
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
37 String result="<html><body>\n<h1>Groups</h1>\n<table>";
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
38 result += "<tr><th>id</th><th>name</th><th>uri</th></tr>";
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
39 store = getAnnotationStore();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
40 if (id == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
41 // list all groups
19
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
42 List<Group> groups = store.getGroups("uri", "*");
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
43 for (Group group : groups) {
19
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
44 String groupLink = group.getId();
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
45 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());
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
46 }
21
1ac626309352 more work on HTML UI (doesn't work yet).
casties
parents: 19
diff changeset
47 } else {
1ac626309352 more work on HTML UI (doesn't work yet).
casties
parents: 19
diff changeset
48 // just one group
1ac626309352 more work on HTML UI (doesn't work yet).
casties
parents: 19
diff changeset
49 List<Group> groups = store.getGroups("uri", "*");
1ac626309352 more work on HTML UI (doesn't work yet).
casties
parents: 19
diff changeset
50 for (Group group : groups) {
1ac626309352 more work on HTML UI (doesn't work yet).
casties
parents: 19
diff changeset
51 String groupLink = group.getId();
1ac626309352 more work on HTML UI (doesn't work yet).
casties
parents: 19
diff changeset
52 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());
1ac626309352 more work on HTML UI (doesn't work yet).
casties
parents: 19
diff changeset
53 }
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
54 }
19
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
55 result += "</table>\n</body>\n</html>";
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
56
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
57 logger.debug("sending:");
19
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
58 logger.debug(result);
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
59 return new StringRepresentation(result,MediaType.TEXT_HTML);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
60 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
61
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
62 protected AnnotationStore getAnnotationStore() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
63 if (store == null) {
19
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
64 store = ((BaseRestlet) getApplication()).getAnnotationStore();
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
65 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
66 return store;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
67 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
68 }