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