use of org.restlet.resource.Representation in project GeoGig by boundlessgeo.
the class FixedEncoder method encode.
@Override
public Representation encode(ClientInfo client, Representation representation) {
Representation result = representation;
Encoding bestEncoding = getBestEncoding(client);
if (bestEncoding != null && !Encoding.IDENTITY.equals(bestEncoding)) {
result = new FixedEncoderRepresentation(bestEncoding, representation);
}
return result;
}
use of org.restlet.resource.Representation in project GeoGig by boundlessgeo.
the class SendObjectResource method post.
@Override
public void post(Representation entity) {
InputStream input = null;
Request request = getRequest();
try {
LOGGER.info("Receiving objects from {}", request.getClientInfo().getAddress());
Representation representation = request.getEntity();
input = representation.getStream();
final GeoGIG ggit = getGeogig(request).get();
final BinaryPackedObjects unpacker = new BinaryPackedObjects(ggit.getRepository().objectDatabase());
CountingInputStream countingStream = new CountingInputStream(input);
Stopwatch sw = Stopwatch.createStarted();
IngestResults ingestResults = unpacker.ingest(countingStream);
sw.stop();
LOGGER.info(String.format("SendObjectResource: Processed %,d objects.\nInserted: %,d.\nExisting: %,d.\nTime to process: %s.\nStream size: %,d bytes.\n", ingestResults.total(), ingestResults.getInserted(), ingestResults.getExisting(), sw, countingStream.getCount()));
} catch (IOException e) {
LOGGER.warn("Error processing incoming objects from {}", request.getClientInfo().getAddress(), e);
throw new RestletException(e.getMessage(), Status.SERVER_ERROR_INTERNAL, e);
} finally {
if (input != null)
Closeables.closeQuietly(input);
}
}
use of org.restlet.resource.Representation 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.restlet.resource.Representation in project GeoGig by boundlessgeo.
the class OsmDownloadWebOp method getRepresentation.
@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);
final String rootPath = request.getRootRef().toString();
MediaType mediaType = variant.getMediaType();
Representation rep = new OSMReportRepresentation(mediaType, asyncCommand, rootPath);
return rep;
}
use of org.restlet.resource.Representation 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