Changeset 23:d22d01ba953a in AnnotationManagerN4J for src


Ignore:
Timestamp:
Sep 22, 2012, 6:12:18 PM (12 years ago)
Author:
casties
Branch:
default
Message:

reorganised code for annotations and groups ui. work in progress.

Location:
src/main
Files:
2 added
1 edited
3 moved

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsUiRestlet.java

    r22 r23  
    22 *
    33 */
    4 package de.mpiwg.itgroup.annotations.restlet;
     4package de.mpiwg.itgroup.annotations.restlet.annotations_ui;
    55
    66import org.apache.log4j.Logger;
     
    99import org.restlet.routing.Router;
    1010
     11import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
     12
    1113/**
    1214 * @author casties
    1315 *
    1416 */
    15 public class AnnotationStoreRestlet extends BaseRestlet {
     17public class AnnotationsUiRestlet extends BaseRestlet {
    1618
    1719    public final String version = "AnnotationManagerN4J/AnnotationStore 0.1";
    1820
    19     public static Logger logger = Logger.getLogger(AnnotationStoreRestlet.class);
     21    public static Logger logger = Logger.getLogger(AnnotationsUiRestlet.class);
    2022
    21     public AnnotationStoreRestlet(Context context) {
     23    public AnnotationsUiRestlet(Context context) {
    2224        super(context);
    2325        logger.debug("StoreRestlet!");
     
    3537        Router router = new Router(getContext());
    3638
    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);
    4044
    41         router.attach("/", AnnotationStoreInfo.class);
     45        router.attach("/", InfoResource.class);
    4246        // authenticator.setNext(router);
    4347        // return authenticator;
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupsResource.java

    r22 r23  
    22 *
    33 */
    4 package de.mpiwg.itgroup.annotations.restlet;
     4package de.mpiwg.itgroup.annotations.restlet.annotations_ui;
    55
    66import java.util.List;
     
    1919import de.mpiwg.itgroup.annotations.Actor;
    2020import de.mpiwg.itgroup.annotations.Group;
    21 import de.mpiwg.itgroup.annotations.Person;
    2221import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
     22import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
    2323
    2424/**
     25 * Resource class for the list of annotation groups.
     26 *
    2527 * @author casties
    2628 *
    2729 */
    28 public class AnnotationStoreGroups extends ServerResource {
     30public class GroupsResource extends ServerResource {
    2931
    30     public static Logger logger = Logger.getLogger(AnnotationStoreGroups.class);
     32    public static Logger logger = Logger.getLogger(GroupsResource.class);
    3133
    3234    private AnnotationStore store;
     
    4042    @Get("html")
    4143    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);
    4544        String result = null;
    4645        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());
    7755        }
    78 
     56        result += "</table>\n</body>\n</html>";
    7957        logger.debug("sending:");
    8058        logger.debug(result);
     
    8361
    8462    /**
    85      * POST with HTML content-type. Creates a new Group.
     63     * POST creates a new Group.
    8664     *
    8765     * @return
    8866     */
    8967    @Post
    90     public Representation doPostHTML(Representation entity) {
    91         logger.debug("AnnotationStoreGroups doPostHTML!");
     68    public Representation doPost(Representation entity) {
     69        logger.debug("AnnotationsUiGroups doPost!");
    9270        // TODO: do authentication
    9371        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;
     1package de.mpiwg.itgroup.annotations.restlet.annotations_ui;
    22
    33import java.io.InputStream;
     
    1010
    1111
    12 public class AnnotationStoreInfo extends ServerResource {
     12public class InfoResource extends ServerResource {
    1313
    1414        @Get("html")
  • src/main/webapp/WEB-INF/web.xml

    r18 r23  
    2525                <init-param>
    2626                        <param-name>org.restlet.application</param-name>
    27                         <param-value>de.mpiwg.itgroup.annotations.restlet.AnnotationStoreRestlet</param-value>
     27                        <param-value>de.mpiwg.itgroup.annotations.restlet.annotations_ui.AnnotationsUiRestlet</param-value>
    2828                </init-param>
    2929        <!-- Load this servlet at server startup time -->
Note: See TracChangeset for help on using the changeset viewer.