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.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.