Search in sources :

Example 1 with EmptyOSMDownloadException

use of org.locationtech.geogig.osm.internal.EmptyOSMDownloadException in project GeoGig by boundlessgeo.

the class OSMImport method runInternal.

@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(apiUrl != null && apiUrl.size() == 1, "One file must be specified");
    File importFile = new File(apiUrl.get(0));
    checkParameter(importFile.exists(), "The specified OSM data file does not exist");
    checkParameter(!(message != null && noRaw), "cannot use --message if using --no-raw");
    checkParameter(message == null || mappingFile != null, "Cannot use --message if not using --mapping");
    Mapping mapping = null;
    if (mappingFile != null) {
        mapping = Mapping.fromFile(mappingFile);
    }
    try {
        message = message == null ? "Updated OSM data" : message;
        Optional<OSMReport> report = cli.getGeogig().command(OSMImportOp.class).setDataSource(importFile.getAbsolutePath()).setMapping(mapping).setMessage(message).setNoRaw(noRaw).setAdd(add).setProgressListener(cli.getProgressListener()).call();
        if (report.isPresent()) {
            OSMReport rep = report.get();
            String msg;
            if (rep.getUnpprocessedCount() > 0) {
                msg = String.format("\nSome elements returned by the specified filter could not be processed.\n" + "Processed entities: %,d.\nWrong or uncomplete elements: %,d.\nNodes: %,d.\nWays: %,d.\n", rep.getCount(), rep.getUnpprocessedCount(), rep.getNodeCount(), rep.getWayCount());
            } else {
                msg = String.format("\nProcessed entities: %,d.\n Nodes: %,d.\n Ways: %,d\n", rep.getCount(), rep.getNodeCount(), rep.getWayCount());
            }
            cli.getConsole().println(msg);
        }
    } catch (EmptyOSMDownloadException e) {
        throw new IllegalArgumentException("The specified filter did not contain any valid element.\n" + "No changes were made to the repository.\n");
    } catch (RuntimeException e) {
        throw new CommandFailedException("Error importing OSM data: " + e.getMessage(), e);
    }
}
Also used : Mapping(org.locationtech.geogig.osm.internal.Mapping) OSMImportOp(org.locationtech.geogig.osm.internal.OSMImportOp) File(java.io.File) OSMReport(org.locationtech.geogig.osm.internal.OSMReport) EmptyOSMDownloadException(org.locationtech.geogig.osm.internal.EmptyOSMDownloadException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Aggregations

File (java.io.File)1 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)1 EmptyOSMDownloadException (org.locationtech.geogig.osm.internal.EmptyOSMDownloadException)1 Mapping (org.locationtech.geogig.osm.internal.Mapping)1 OSMImportOp (org.locationtech.geogig.osm.internal.OSMImportOp)1 OSMReport (org.locationtech.geogig.osm.internal.OSMReport)1