use of org.locationtech.geogig.web.api.CommandSpecException in project GeoGig by boundlessgeo.
the class RefParseWeb method run.
/**
* Runs the command and builds the appropriate response
*
* @param context - the context to use for this command
*
* @throws CommandSpecException
*/
@Override
public void run(CommandContext context) {
if (refSpec == null) {
throw new CommandSpecException("No name was given.");
}
final Context geogig = this.getCommandLocator(context);
Optional<Ref> ref;
try {
ref = geogig.command(RefParse.class).setName(refSpec).call();
} catch (Exception e) {
context.setResponseContent(CommandResponse.error("Aborting UpdateRef: " + e.getMessage()));
return;
}
if (ref.isPresent()) {
final Ref newRef = ref.get();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeRefParseResponse(newRef);
out.finish();
}
});
} else {
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeEmptyRefResponse();
out.finish();
}
});
}
}
use of org.locationtech.geogig.web.api.CommandSpecException in project GeoGig by boundlessgeo.
the class RemoteWebOp method remoteAdd.
private void remoteAdd(CommandContext context, final Context geogig) {
if (remoteName == null || remoteName.trim().isEmpty()) {
throw new CommandSpecException("No remote was specified.");
} else if (remoteURL == null || remoteURL.trim().isEmpty()) {
throw new CommandSpecException("No URL was specified.");
}
final Remote remote;
try {
remote = geogig.command(RemoteAddOp.class).setName(remoteName).setURL(remoteURL).setUserName(username).setPassword(password).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeElement("name", remote.getName());
out.finish();
}
});
} catch (RemoteException e) {
context.setResponseContent(CommandResponse.error(e.statusCode.toString()));
} catch (Exception e) {
context.setResponseContent(CommandResponse.error("Aborting Remote Add"));
}
}
use of org.locationtech.geogig.web.api.CommandSpecException 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;
}
use of org.locationtech.geogig.web.api.CommandSpecException in project GeoGig by boundlessgeo.
the class MergeFeatureResource method parseID.
private Optional<NodeRef> parseID(ObjectId commitId, String path, GeoGIG geogig) {
Optional<RevObject> object = geogig.command(RevObjectParse.class).setObjectId(commitId).call();
RevCommit commit = null;
if (object.isPresent() && object.get() instanceof RevCommit) {
commit = (RevCommit) object.get();
} else {
throw new CommandSpecException("Couldn't resolve id: " + commitId.toString() + " to a commit");
}
object = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()).call();
if (object.isPresent()) {
RevTree tree = (RevTree) object.get();
return geogig.command(FindTreeChild.class).setParent(tree).setChildPath(path).call();
} else {
throw new CommandSpecException("Couldn't resolve commit's treeId");
}
}
use of org.locationtech.geogig.web.api.CommandSpecException in project GeoGig by boundlessgeo.
the class OsmImportWebOp method getRepresentation.
@Override
public Representation getRepresentation(final Variant variant) {
final Request request = getRequest();
final Context context = super.getContext(request);
Form options = getRequest().getResourceRef().getQueryAsForm();
final String urlOrFilepath = options.getFirstValue("uri");
final boolean add = Boolean.valueOf(options.getFirstValue("add"));
final String mappingFile = options.getFirstValue("mapping");
Mapping mapping = null;
if (mappingFile != null) {
mapping = Mapping.fromFile(mappingFile);
}
final boolean noRaw = Boolean.valueOf(options.getFirstValue("noRaw"));
final String message = options.getFirstValue("message");
if (urlOrFilepath == null) {
String msg = "Missing parameter: uri\n" + "Usage: GET <repo context>/osm/import?uri=<osm file URI>[&<arg>=<value>]+\n" + "Arguments:\n" + " * uri: Mandatory. URL or path to OSM data file in the server filesystem\n" + " * add: Optional. true|false. Default: false. If true, do not remove previous data before importing.\n" + " * mapping: Optional. Location of mapping file in the server filesystem\n" + " * noRaw: Optional. true|false. Default: false. If true, do not import raw data when using a mapping\n" + " * message: Optional. Message for the commit to create.";
throw new CommandSpecException(msg);
}
OSMImportOp command = context.command(OSMImportOp.class);
command.setAdd(add);
command.setDataSource(urlOrFilepath);
command.setMapping(mapping);
command.setMessage(message);
command.setNoRaw(noRaw);
AsyncCommand<Optional<OSMReport>> asyncCommand;
URL repo = context.repository().getLocation();
String description = String.format("osm import %s, repository: %s", urlOrFilepath, repo);
asyncCommand = AsyncContext.get().run(command, description);
final String rootPath = request.getRootRef().toString();
MediaType mediaType = variant.getMediaType();
Representation rep = new OSMReportRepresentation(mediaType, asyncCommand, rootPath);
return rep;
}
Aggregations