Mercurial > hg > AnnotationManagerN4J
comparison src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupsResource.java @ 32:0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
author | casties |
---|---|
date | Tue, 25 Sep 2012 21:59:21 +0200 |
parents | d22d01ba953a |
children | 2b1e6df5e21a |
comparison
equal
deleted
inserted
replaced
30:05b631a084d0 | 32:0731c4549065 |
---|---|
12 import org.restlet.data.Status; | 12 import org.restlet.data.Status; |
13 import org.restlet.representation.Representation; | 13 import org.restlet.representation.Representation; |
14 import org.restlet.representation.StringRepresentation; | 14 import org.restlet.representation.StringRepresentation; |
15 import org.restlet.resource.Get; | 15 import org.restlet.resource.Get; |
16 import org.restlet.resource.Post; | 16 import org.restlet.resource.Post; |
17 import org.restlet.resource.ResourceException; | |
17 import org.restlet.resource.ServerResource; | 18 import org.restlet.resource.ServerResource; |
18 | 19 |
19 import de.mpiwg.itgroup.annotations.Actor; | 20 import de.mpiwg.itgroup.annotations.Actor; |
20 import de.mpiwg.itgroup.annotations.Group; | 21 import de.mpiwg.itgroup.annotations.Group; |
21 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; | 22 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; |
31 | 32 |
32 public static Logger logger = Logger.getLogger(GroupsResource.class); | 33 public static Logger logger = Logger.getLogger(GroupsResource.class); |
33 | 34 |
34 private AnnotationStore store; | 35 private AnnotationStore store; |
35 | 36 |
37 @Override | |
38 protected void doInit() throws ResourceException { | |
39 super.doInit(); | |
40 // get store instance | |
41 if (store == null) { | |
42 store = ((BaseRestlet) getApplication()).getAnnotationStore(); | |
43 } | |
44 } | |
45 | |
36 /** | 46 /** |
37 * GET with HTML content type. Lists all groups. | 47 * GET with HTML content type. Lists all groups. |
38 * | 48 * |
39 * @param entity | 49 * @param entity |
40 * @return | 50 * @return |
41 */ | 51 */ |
42 @Get("html") | 52 @Get("html") |
43 public Representation doGetHTML(Representation entity) { | 53 public Representation doGetHTML(Representation entity) { |
44 String result = null; | 54 String result = null; |
45 store = getAnnotationStore(); | 55 // get form parameter |
46 // list all groups | 56 Form f = this.getQuery(); |
47 result = "<html><body>\n<h1>Groups</h1>\n<table>"; | 57 String form = f.getFirstValue("form"); |
48 result += "<tr><th>id</th><th>name</th><th>uri</th></tr>"; | 58 if (form != null && form.equals("new_group")) { |
49 List<Group> groups = store.getGroups("uri", "*"); | 59 // output new group form |
50 for (Group group : groups) { | 60 result = "<html><body>\n"; |
51 Reference groupUrl = this.getReference(); | 61 result += "<h1>New group</h1>\n"; |
52 groupUrl.addSegment(group.getId()); | 62 result += String.format("<p><a href=\"%s\">All groups</a></p>", this.getReference()); |
53 result += String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", groupUrl, group.getId(), | 63 result += String.format("<form method=\"post\" action=\"%s\">\n", this.getReference().getHierarchicalPart()); |
54 group.getName(), group.getUri()); | 64 result += "<table>"; |
65 result += "<tr><td><b>id</b></td><td><input type=\"text\" name=\"id\"/></td></tr>\n"; | |
66 result += "<tr><td><b>name</b></td><td><input type=\"text\" name=\"name\"/></td></tr>\n"; | |
67 result += "</table>\n"; | |
68 result += "<p><input type=\"submit\"/></p>\n"; | |
69 result += "</form>\n</body>\n</html>"; | |
70 } else { | |
71 // list all groups | |
72 result = "<html><body>\n<h1>Groups</h1>\n"; | |
73 result += "<table>\n"; | |
74 result += "<tr><th>id</th><th>name</th><th>uri</th></tr>"; | |
75 List<Group> groups = store.getGroups("uri", "*"); | |
76 for (Group group : groups) { | |
77 Reference groupUrl = this.getReference().clone(); | |
78 groupUrl.addSegment(group.getId()); | |
79 result += String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", groupUrl, group.getId(), | |
80 group.getName(), group.getUri()); | |
81 } | |
82 result += "</table>\n"; | |
83 result += "<p><a href=\"?form=new_group\">Add new group</a></p>\n"; | |
84 result += "</body>\n</html>"; | |
55 } | 85 } |
56 result += "</table>\n</body>\n</html>"; | |
57 logger.debug("sending:"); | |
58 logger.debug(result); | |
59 return new StringRepresentation(result, MediaType.TEXT_HTML); | 86 return new StringRepresentation(result, MediaType.TEXT_HTML); |
60 } | 87 } |
61 | 88 |
62 /** | 89 /** |
63 * POST creates a new Group. | 90 * POST creates a new Group. |
76 setStatus(Status.CLIENT_ERROR_BAD_REQUEST); | 103 setStatus(Status.CLIENT_ERROR_BAD_REQUEST); |
77 return null; | 104 return null; |
78 } | 105 } |
79 String gid = makeGroupId(id); | 106 String gid = makeGroupId(id); |
80 Group newGroup = new Group(gid, null, name); | 107 Group newGroup = new Group(gid, null, name); |
81 store = getAnnotationStore(); | |
82 Actor storedGroup = store.storeActor(newGroup); | 108 Actor storedGroup = store.storeActor(newGroup); |
83 gid = storedGroup.getId(); | 109 gid = storedGroup.getId(); |
84 // return 303: see other | 110 // return 303: see other |
85 setStatus(Status.REDIRECTION_SEE_OTHER); | 111 setStatus(Status.REDIRECTION_SEE_OTHER); |
86 // go GET URL for this group | 112 // go GET URL for this group |