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());
}
}
}
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));
}
}
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);
}
}
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);
}
}
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();
}
}
Aggregations