}
@Override
public Representation getRepresentation(final Variant variant) {
final Request request = getRequest();
Context context = getContext(request);
Form options = getRequest().getResourceRef().getQueryAsForm();
final String filterFileArg = options.getFirstValue("filter");
final String bboxArg = options.getFirstValue("bbox");
final String messageArg = options.getFirstValue("message");
final boolean update = Boolean.valueOf(options.getFirstValue("update"));
final boolean rebase = Boolean.valueOf(options.getFirstValue("rebase"));
final String mappingFileArg = options.getFirstValue("mapping");
checkArgSpec(filterFileArg != null ^ bboxArg != null || update,
"You must specify a filter file or a bounding box");
checkArgSpec((filterFileArg != null || bboxArg != null) ^ update,
"Filters cannot be used when updating");
checkArgSpec(context.index().isClean() && context.workingTree().isClean(),
"Working tree and index are not clean");
checkArgSpec(!rebase || update, "rebase switch can only be used when updating");
final File filterFile = parseFile(filterFileArg);
final File mappingFile = parseFile(mappingFileArg);
final List<String> bbox = parseBbox(bboxArg);
checkArgSpec(filterFile == null || filterFile.exists(),
"The specified filter file does not exist");
checkArgSpec(mappingFile == null || mappingFile.exists(),
"The specified mapping file does not exist");
AbstractGeoGigOp<Optional<OSMReport>> command;
if (update) {
command = context.command(OSMUpdateOp.class).setRebase(rebase).setMessage(messageArg)
.setAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT);
} else {
command = context.command(OSMDownloadOp.class).setBbox(bbox).setFilterFile(filterFile)
.setMessage(messageArg).setMappingFile(mappingFile)
.setOsmAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT);
}
AsyncCommand<Optional<OSMReport>> asyncCommand;
URL repo = context.repository().getLocation();
String description = String
.format("osm download filter: %s, bbox: %s, mapping: %s, update: %s, rebase: %s, repository: %s",
filterFileArg, bboxArg, mappingFileArg, update, rebase, repo);
asyncCommand = AsyncContext.get().run(command, description);