Changeset 23:d22d01ba953a 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
r22 r23 2 2 * 3 3 */ 4 package de.mpiwg.itgroup.annotations.restlet ;4 package de.mpiwg.itgroup.annotations.restlet.annotations_ui; 5 5 6 6 import java.util.List; … … 19 19 import de.mpiwg.itgroup.annotations.Actor; 20 20 import de.mpiwg.itgroup.annotations.Group; 21 import de.mpiwg.itgroup.annotations.Person;22 21 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; 22 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; 23 23 24 24 /** 25 * Resource class for the list of annotation groups. 26 * 25 27 * @author casties 26 28 * 27 29 */ 28 public class AnnotationStoreGroupsextends ServerResource {30 public class GroupsResource extends ServerResource { 29 31 30 public static Logger logger = Logger.getLogger( AnnotationStoreGroups.class);32 public static Logger logger = Logger.getLogger(GroupsResource.class); 31 33 32 34 private AnnotationStore store; … … 40 42 @Get("html") 41 43 public Representation doGetHTML(Representation entity) { 42 // id from URI /annotations/groups/{id}43 String id = (String) getRequest().getAttributes().get("id");44 logger.debug("group-id=" + id);45 44 String result = null; 46 45 store = getAnnotationStore(); 47 if (id == null) { 48 // list all groups 49 result = "<html><body>\n<h1>Groups</h1>\n<table>"; 50 result += "<tr><th>id</th><th>name</th><th>uri</th></tr>"; 51 List<Group> groups = store.getGroups("uri", "*"); 52 for (Group group : groups) { 53 Reference groupUrl = this.getReference(); 54 groupUrl.addSegment(group.getId()); 55 result += String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", groupUrl, 56 group.getId(), group.getName(), group.getUri()); 57 } 58 result += "</table>\n</body>\n</html>"; 59 } else { 60 // just one group 61 Reference groupsUrl = this.getReference().getParentRef(); 62 result = "<html><body>\n<h1>Group</h1>\n"; 63 result += String.format("<p><a href=\"%s\">All groups</a></p>", groupsUrl); 64 Group group = new Group(id); 65 group = (Group) store.getActor(group); 66 result += "<table>"; 67 result += String.format("<tr><td><b>id</b></td><td>%s</td></tr>\n", group.getId()); 68 result += String.format("<tr><td><b>name</b></td><td>%s</td></tr>\n", group.getName()); 69 result += String.format("<tr><td><b>uri</b></td><td>%s</td></tr>\n", group.getUri()); 70 result += "<tr><td><b>members</b></td><td>"; 71 List<Person> members = store.getMembersOfGroup(group); 72 for (Person p : members) { 73 result += String.format("%s (%s)\n", p.getName(), p.getIdString()); 74 } 75 result += "</td></tr>\n"; 76 result += "</table>\n</body>\n</html>"; 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()); 77 55 } 78 56 result += "</table>\n</body>\n</html>"; 79 57 logger.debug("sending:"); 80 58 logger.debug(result); … … 83 61 84 62 /** 85 * POST with HTML content-type. Creates a new Group.63 * POST creates a new Group. 86 64 * 87 65 * @return 88 66 */ 89 67 @Post 90 public Representation doPost HTML(Representation entity) {91 logger.debug("Annotation StoreGroups doPostHTML!");68 public Representation doPost(Representation entity) { 69 logger.debug("AnnotationsUiGroups doPost!"); 92 70 // TODO: do authentication 93 71 Form form = new Form(entity);
Note: See TracChangeset
for help on using the changeset viewer.