Changeset 23:d22d01ba953a in AnnotationManagerN4J for src/main/java/de/mpiwg/itgroup/annotations/restlet
- Timestamp:
- Sep 22, 2012, 6:12:18 PM (13 years ago)
- Branch:
- default
- Location:
- src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui
- Files:
-
- 2 added
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsUiRestlet.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 org.apache.log4j.Logger; … … 9 9 import org.restlet.routing.Router; 10 10 11 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; 12 11 13 /** 12 14 * @author casties 13 15 * 14 16 */ 15 public class Annotation StoreRestlet extends BaseRestlet {17 public class AnnotationsUiRestlet extends BaseRestlet { 16 18 17 19 public final String version = "AnnotationManagerN4J/AnnotationStore 0.1"; 18 20 19 public static Logger logger = Logger.getLogger(Annotation StoreRestlet.class);21 public static Logger logger = Logger.getLogger(AnnotationsUiRestlet.class); 20 22 21 public Annotation StoreRestlet(Context context) {23 public AnnotationsUiRestlet(Context context) { 22 24 super(context); 23 25 logger.debug("StoreRestlet!"); … … 35 37 Router router = new Router(getContext()); 36 38 37 router.attach("/groups", AnnotationStoreGroups.class); 38 router.attach("/groups/", AnnotationStoreGroups.class); 39 router.attach("/groups/{id}", AnnotationStoreGroups.class); 39 router.attach("/groups", GroupsResource.class); 40 router.attach("/groups/", GroupsResource.class); 41 router.attach("/groups/{id}", GroupResource.class); 42 router.attach("/groups/{id}/", GroupResource.class); 43 router.attach("/groups/{id}/members", GroupMembersResource.class); 40 44 41 router.attach("/", AnnotationStoreInfo.class);45 router.attach("/", InfoResource.class); 42 46 // authenticator.setNext(router); 43 47 // return authenticator; -
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); -
src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/InfoResource.java
r18 r23 1 package de.mpiwg.itgroup.annotations.restlet ;1 package de.mpiwg.itgroup.annotations.restlet.annotations_ui; 2 2 3 3 import java.io.InputStream; … … 10 10 11 11 12 public class AnnotationStoreInfoextends ServerResource {12 public class InfoResource extends ServerResource { 13 13 14 14 @Get("html")
Note: See TracChangeset
for help on using the changeset viewer.