Ignore:
Timestamp:
Sep 25, 2012, 7:59:21 PM (12 years ago)
Author:
casties
Branch:
default
Message:

UI for editing groups and persons works now. (still no authorisation!)

File:
1 edited

Legend:

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

    r23 r32  
    1515import org.restlet.resource.Get;
    1616import org.restlet.resource.Post;
     17import org.restlet.resource.ResourceException;
    1718import org.restlet.resource.ServerResource;
    1819
     
    3435    private AnnotationStore store;
    3536
     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
    3646    /**
    3747     * GET with HTML content type. Lists all groups.
     
    4353    public Representation doGetHTML(Representation entity) {
    4454        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>";
    5585        }
    56         result += "</table>\n</body>\n</html>";
    57         logger.debug("sending:");
    58         logger.debug(result);
    5986        return new StringRepresentation(result, MediaType.TEXT_HTML);
    6087    }
     
    79106        String gid = makeGroupId(id);
    80107        Group newGroup = new Group(gid, null, name);
    81         store = getAnnotationStore();
    82108        Actor storedGroup = store.storeActor(newGroup);
    83109        gid = storedGroup.getId();
Note: See TracChangeset for help on using the changeset viewer.