Search in sources :

Example 1 with OSMReport

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

the class OSMReportRepresentation method writeResultBody.

@Override
protected void writeResultBody(XMLStreamWriter w, Optional<OSMReport> result) throws XMLStreamException {
    if (result.isPresent()) {
        OSMReport report = result.get();
        long latestChangeset = report.getLatestChangeset();
        long latestTimestamp = report.getLatestTimestamp();
        long processedEntities = report.getCount();
        long nodeCount = report.getNodeCount();
        long wayCount = report.getWayCount();
        long unpprocessedCount = report.getUnpprocessedCount();
        w.writeStartElement("OSMReport");
        element(w, "latestChangeset", latestChangeset);
        element(w, "latestTimestamp", latestTimestamp);
        element(w, "processedEntities", processedEntities);
        element(w, "nodeCount", nodeCount);
        element(w, "wayCount", wayCount);
        element(w, "unpprocessedCount", unpprocessedCount);
        w.writeEndElement();
    }
}
Also used : OSMReport(org.locationtech.geogig.osm.internal.OSMReport)

Example 2 with OSMReport

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

the class OSMApplyDiff method runInternal.

@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(diffFilepath != null && diffFilepath.size() == 1, "One file must be specified");
    File diffFile = new File(diffFilepath.get(0));
    checkParameter(diffFile.exists(), "The specified OSM diff file does not exist");
    try {
        Optional<OSMReport> report = cli.getGeogig().command(OSMApplyDiffOp.class).setDiffFile(diffFile).setProgressListener(cli.getProgressListener()).call();
        if (report.isPresent()) {
            OSMReport rep = report.get();
            String msg;
            if (rep.getUnpprocessedCount() > 0) {
                msg = String.format("\nSome diffs from the specified file were not applied.\n" + "Processed entities: %,d.\n %,d.\nNodes: %,d.\nWays: %,d.\n Elements not applied:", 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 (RuntimeException e) {
        throw new CommandFailedException("Error importing OSM data: " + e.getMessage(), e);
    }
}
Also used : OSMApplyDiffOp(org.locationtech.geogig.osm.internal.OSMApplyDiffOp) File(java.io.File) OSMReport(org.locationtech.geogig.osm.internal.OSMReport) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 3 with OSMReport

use of org.locationtech.geogig.osm.internal.OSMReport 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)

Example 4 with OSMReport

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

the class OSMDownload method runInternal.

@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(filterFile != null ^ bbox != null || update, "You must specify a filter file or a bounding box");
    checkParameter((filterFile != null || bbox != null) ^ update, "Filters cannot be used when updating");
    GeoGIG geogig = cli.getGeogig();
    checkState(geogig.getRepository().index().isClean() && geogig.getRepository().workingTree().isClean(), "Working tree and index are not clean");
    checkParameter(!rebase || update, "--rebase switch can only be used when updating");
    checkParameter(filterFile == null || filterFile.exists(), "The specified filter file does not exist");
    checkParameter(bbox == null || bbox.size() == 4, "The specified bounding box is not correct");
    osmAPIUrl = resolveAPIURL();
    Optional<OSMReport> report;
    GeogigTransaction tx = geogig.command(TransactionBegin.class).call();
    try {
        AbstractGeoGigOp<Optional<OSMReport>> cmd;
        if (update) {
            cmd = tx.command(OSMUpdateOp.class).setAPIUrl(osmAPIUrl).setRebase(rebase).setMessage(message).setProgressListener(cli.getProgressListener());
        } else {
            cmd = tx.command(OSMDownloadOp.class).setBbox(bbox).setFilterFile(filterFile).setKeepFiles(keepFiles).setMessage(message).setMappingFile(mappingFile).setOsmAPIUrl(osmAPIUrl).setSaveFile(saveFile).setProgressListener(cli.getProgressListener());
        }
        report = cmd.call();
        tx.commit();
    } catch (RuntimeException e) {
        tx.abort();
        if (e instanceof NothingToCommitException) {
            throw new CommandFailedException(e.getMessage(), e);
        }
        throw e;
    }
    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);
    }
}
Also used : GeogigTransaction(org.locationtech.geogig.api.GeogigTransaction) Optional(com.google.common.base.Optional) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) OSMReport(org.locationtech.geogig.osm.internal.OSMReport) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) OSMUpdateOp(org.locationtech.geogig.osm.internal.OSMUpdateOp) TransactionBegin(org.locationtech.geogig.api.plumbing.TransactionBegin) OSMDownloadOp(org.locationtech.geogig.osm.internal.OSMDownloadOp) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Aggregations

OSMReport (org.locationtech.geogig.osm.internal.OSMReport)4 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)3 File (java.io.File)2 Optional (com.google.common.base.Optional)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 GeogigTransaction (org.locationtech.geogig.api.GeogigTransaction)1 TransactionBegin (org.locationtech.geogig.api.plumbing.TransactionBegin)1 NothingToCommitException (org.locationtech.geogig.api.porcelain.NothingToCommitException)1 EmptyOSMDownloadException (org.locationtech.geogig.osm.internal.EmptyOSMDownloadException)1 Mapping (org.locationtech.geogig.osm.internal.Mapping)1 OSMApplyDiffOp (org.locationtech.geogig.osm.internal.OSMApplyDiffOp)1 OSMDownloadOp (org.locationtech.geogig.osm.internal.OSMDownloadOp)1 OSMImportOp (org.locationtech.geogig.osm.internal.OSMImportOp)1 OSMUpdateOp (org.locationtech.geogig.osm.internal.OSMUpdateOp)1