Search in sources :

Example 11 with CommandFailedException

use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.

the class RemoteList method runInternal.

/**
     * Executes the remote list command.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    final ImmutableList<Remote> remoteList;
    try {
        remoteList = cli.getGeogig().command(RemoteListOp.class).call();
    } catch (ConfigException e) {
        throw new CommandFailedException("Could not access the config database.", e);
    }
    for (Remote remote : remoteList) {
        if (verbose) {
            cli.getConsole().println(remote.getName() + " " + remote.getFetchURL() + " (fetch)");
            cli.getConsole().println(remote.getName() + " " + remote.getPushURL() + " (push)");
        } else {
            cli.getConsole().println(remote.getName());
        }
    }
}
Also used : Remote(org.locationtech.geogig.api.Remote) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 12 with CommandFailedException

use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.

the class Remove method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    ConsoleReader console = cli.getConsole();
    // check that there is something to remove
    if (pathsToRemove.isEmpty()) {
        printUsage(cli);
        throw new CommandFailedException();
    }
    /*
         * Separate trees and features, and check that, if there are trees to remove, the -r
         * modifier is used
         */
    ArrayList<String> trees = new ArrayList<String>();
    Repository repository = cli.getGeogig().getRepository();
    for (String pathToRemove : pathsToRemove) {
        NodeRef.checkValidPath(pathToRemove);
        Optional<NodeRef> node = repository.command(FindTreeChild.class).setParent(repository.workingTree().getTree()).setIndex(true).setChildPath(pathToRemove).call();
        checkParameter(node.isPresent(), "pathspec '%s' did not match any feature or tree", pathToRemove);
        NodeRef nodeRef = node.get();
        if (nodeRef.getType() == TYPE.TREE) {
            checkParameter(recursive, "Cannot remove tree %s if -r is not specified", nodeRef.path());
            trees.add(pathToRemove);
        }
    }
    int featuresCount = pathsToRemove.size() - trees.size();
    /* Perform the remove operation */
    RemoveOp op = cli.getGeogig().command(RemoveOp.class);
    for (String pathToRemove : pathsToRemove) {
        op.addPathToRemove(pathToRemove);
    }
    op.setProgressListener(cli.getProgressListener()).call();
    /* And inform about it */
    if (featuresCount > 0) {
        console.print(String.format("Deleted %d feature(s)", featuresCount));
    }
    for (String tree : trees) {
        console.print(String.format("Deleted %s tree", tree));
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Repository(org.locationtech.geogig.repository.Repository) ConsoleReader(jline.console.ConsoleReader) ArrayList(java.util.ArrayList) RemoveOp(org.locationtech.geogig.api.porcelain.RemoveOp) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 13 with CommandFailedException

use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.

the class Fetch method runInternal.

/**
     * Executes the fetch command using the provided options.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(depth > 0 ? !fulldepth : true, "Cannot specify a depth and full depth.  Use --depth <depth> or --fulldepth.");
    if (depth > 0 || fulldepth) {
        checkParameter(cli.getGeogig().getRepository().getDepth().isPresent(), "Depth operations can only be used on a shallow clone.");
    }
    TransferSummary result;
    try {
        FetchOp fetch = cli.getGeogig().command(FetchOp.class);
        fetch.setProgressListener(cli.getProgressListener());
        fetch.setAll(all).setPrune(prune).setFullDepth(fulldepth);
        fetch.setDepth(depth);
        if (args != null) {
            for (String repo : args) {
                fetch.addRemote(repo);
            }
        }
        result = fetch.call();
    } catch (SynchronizationException e) {
        switch(e.statusCode) {
            case HISTORY_TOO_SHALLOW:
            default:
                throw new CommandFailedException("Unable to fetch, the remote history is shallow.", e);
        }
    } catch (IllegalArgumentException iae) {
        throw new CommandFailedException(iae.getMessage(), iae);
    } catch (IllegalStateException ise) {
        throw new CommandFailedException(ise.getMessage(), ise);
    }
    ConsoleReader console = cli.getConsole();
    if (result.getChangedRefs().isEmpty()) {
        console.println("Already up to date.");
    } else {
        FetchResultPrinter.print(result, console);
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) FetchOp(org.locationtech.geogig.api.porcelain.FetchOp) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException)

Example 14 with CommandFailedException

use of org.locationtech.geogig.cli.CommandFailedException 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 15 with CommandFailedException

use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.

the class OSMExport method runInternal.

/**
     * Executes the export command using the provided options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    if (args.size() < 1 || args.size() > 2) {
        printUsage(cli);
        throw new CommandFailedException();
    }
    checkParameter(bbox == null || bbox.size() == 4, "The specified bounding box is not correct");
    geogig = cli.getGeogig();
    String osmfile = args.get(0);
    String ref = "WORK_HEAD";
    if (args.size() == 2) {
        ref = args.get(1);
        Optional<ObjectId> tree = geogig.command(ResolveTreeish.class).setTreeish(ref).call();
        checkParameter(tree.isPresent(), "Invalid commit or reference: %s", ref);
    }
    File file = new File(osmfile);
    checkParameter(!file.exists() || overwrite, "The selected file already exists. Use -o to overwrite");
    Iterator<EntityContainer> nodes = getFeatures(ref + ":node");
    Iterator<EntityContainer> ways = getFeatures(ref + ":way");
    Iterator<EntityContainer> iterator = Iterators.concat(nodes, ways);
    if (file.getName().endsWith(".pbf")) {
        BlockOutputStream output = new BlockOutputStream(new FileOutputStream(file));
        OsmosisSerializer serializer = new OsmosisSerializer(output);
        while (iterator.hasNext()) {
            EntityContainer entity = iterator.next();
            serializer.process(entity);
        }
        serializer.complete();
    } else {
        XmlWriter writer = new XmlWriter(file, CompressionMethod.None);
        while (iterator.hasNext()) {
            EntityContainer entity = iterator.next();
            writer.process(entity);
        }
        writer.complete();
    }
}
Also used : OsmosisSerializer(crosby.binary.osmosis.OsmosisSerializer) ObjectId(org.locationtech.geogig.api.ObjectId) FileOutputStream(java.io.FileOutputStream) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) BlockOutputStream(org.openstreetmap.osmosis.osmbinary.file.BlockOutputStream) File(java.io.File) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) XmlWriter(org.openstreetmap.osmosis.xml.v0_6.XmlWriter)

Aggregations

CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)58 DataStore (org.geotools.data.DataStore)28 GeoToolsOpException (org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)24 File (java.io.File)16 GeoGIG (org.locationtech.geogig.api.GeoGIG)16 ObjectId (org.locationtech.geogig.api.ObjectId)15 IOException (java.io.IOException)14 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)12 ConsoleReader (jline.console.ConsoleReader)10 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)10 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)10 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)10 ExportOp (org.locationtech.geogig.geotools.plumbing.ExportOp)9 Serializable (java.io.Serializable)8 Optional (com.google.common.base.Optional)7 TYPE (org.locationtech.geogig.api.RevObject.TYPE)7 Map (java.util.Map)6 ProgressListener (org.locationtech.geogig.api.ProgressListener)6 Connection (java.sql.Connection)4 Feature (org.opengis.feature.Feature)4