Changeset 32:0731c4549065 in AnnotationManagerN4J for src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupsResource.java
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupsResource.java
r23 r32 15 15 import org.restlet.resource.Get; 16 16 import org.restlet.resource.Post; 17 import org.restlet.resource.ResourceException; 17 18 import org.restlet.resource.ServerResource; 18 19 … … 34 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 47 * GET with HTML content type. Lists all groups. … … 43 53 public Representation doGetHTML(Representation entity) { 44 54 String result = null; 45 store = getAnnotationStore(); 46 // list all groups 47 result = "<html><body>\n<h1>Groups</h1>\n<table>"; 48 result += "<tr><th>id</th><th>name</th><th>uri</th></tr>"; 49 List<Group> groups = store.getGroups("uri", "*"); 50 for (Group group : groups) { 51 Reference groupUrl = this.getReference(); 52 groupUrl.addSegment(group.getId()); 53 result += String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", groupUrl, group.getId(), 54 group.getName(), group.getUri()); 55 // get form parameter 56 Form f = this.getQuery(); 57 String form = f.getFirstValue("form"); 58 if (form != null && form.equals("new_group")) { 59 // output new group form 60 result = "<html><body>\n"; 61 result += "<h1>New group</h1>\n"; 62 result += String.format("<p><a href=\"%s\">All groups</a></p>", this.getReference()); 63 result += String.format("<form method=\"post\" action=\"%s\">\n", this.getReference().getHierarchicalPart()); 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 86 return new StringRepresentation(result, MediaType.TEXT_HTML); 60 87 } … … 79 106 String gid = makeGroupId(id); 80 107 Group newGroup = new Group(gid, null, name); 81 store = getAnnotationStore();82 108 Actor storedGroup = store.storeActor(newGroup); 83 109 gid = storedGroup.getId();
Note: See TracChangeset
for help on using the changeset viewer.