Search in sources :

Example 1 with ParameterSet

use of org.locationtech.geogig.web.api.ParameterSet in project GeoGig by boundlessgeo.

the class CommandResource method runCommand.

private Representation runCommand(Variant variant, Request request) {
    final Optional<GeoGIG> geogig = getGeogig(request);
    Preconditions.checkState(geogig.isPresent());
    Representation rep = null;
    WebAPICommand command = null;
    Form options = getRequest().getResourceRef().getQueryAsForm();
    String commandName = (String) getRequest().getAttributes().get("command");
    MediaType format = resolveFormat(options, variant);
    try {
        ParameterSet params = new FormParams(options);
        command = CommandBuilder.build(commandName, params);
        assert command != null;
    } catch (CommandSpecException ex) {
        rep = formatException(ex, format);
    }
    try {
        if (command != null) {
            RestletContext ctx = new RestletContext(geogig.get());
            command.run(ctx);
            rep = ctx.getRepresentation(format, getJSONPCallback());
        }
    } catch (IllegalArgumentException ex) {
        rep = formatException(ex, format);
    } catch (Exception ex) {
        rep = formatUnexpectedException(ex, format);
    }
    return rep;
}
Also used : ParameterSet(org.locationtech.geogig.web.api.ParameterSet) WebAPICommand(org.locationtech.geogig.web.api.WebAPICommand) Form(org.restlet.data.Form) Representation(org.restlet.resource.Representation) WriterRepresentation(org.locationtech.geogig.rest.WriterRepresentation) RestletException(org.locationtech.geogig.rest.RestletException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) MediaType(org.restlet.data.MediaType) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Aggregations

IOException (java.io.IOException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 RestletException (org.locationtech.geogig.rest.RestletException)1 WriterRepresentation (org.locationtech.geogig.rest.WriterRepresentation)1 CommandSpecException (org.locationtech.geogig.web.api.CommandSpecException)1 ParameterSet (org.locationtech.geogig.web.api.ParameterSet)1 WebAPICommand (org.locationtech.geogig.web.api.WebAPICommand)1 Form (org.restlet.data.Form)1 MediaType (org.restlet.data.MediaType)1 Representation (org.restlet.resource.Representation)1