use of org.locationtech.geogig.cli.InvalidParameterException in project GeoGig by boundlessgeo.
the class Add method runInternal.
/**
* Executes the add command using the provided options.
*
* @param cli
* @see org.locationtech.geogig.cli.AbstractCommand#runInternal(org.locationtech.geogig.cli.GeogigCLI)
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
final GeoGIG geogig = cli.getGeogig();
final ConsoleReader console = cli.getConsole();
String pathFilter = null;
if (patterns.size() == 1) {
pathFilter = patterns.get(0);
} else if (patterns.size() > 1) {
throw new InvalidParameterException("Only a single path is supported so far");
}
List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
console.print("Counting unstaged elements...");
console.flush();
DiffObjectCount unstaged = geogig.getRepository().workingTree().countUnstaged(pathFilter);
if (0 == unstaged.count() && conflicts.isEmpty()) {
console.println();
console.println("No unstaged elements, exiting.");
return;
} else {
console.println(String.valueOf(unstaged.count()));
}
console.println("Staging changes...");
AddOp op = geogig.command(AddOp.class);
if (patterns.size() == 1) {
op.addPattern(patterns.get(0));
}
WorkingTree workTree = op.setUpdateOnly(updateOnly).setProgressListener(cli.getProgressListener()).call();
DiffObjectCount staged = geogig.getRepository().index().countStaged(null);
unstaged = workTree.countUnstaged(null);
console.println(staged.featureCount() + " features and " + staged.treeCount() + " trees staged for commit");
console.println(unstaged.featureCount() + " features and " + unstaged.treeCount() + " trees not staged for commit");
}
use of org.locationtech.geogig.cli.InvalidParameterException in project GeoGig by boundlessgeo.
the class Blame method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter(paths.size() < 2, "Only one path allowed");
checkParameter(!paths.isEmpty(), "A path must be specified");
ConsoleReader console = cli.getConsole();
GeoGIG geogig = cli.getGeogig();
String path = paths.get(0);
try {
BlameReport report = geogig.command(BlameOp.class).setPath(path).call();
Map<String, ValueAndCommit> changes = report.getChanges();
Iterator<String> iter = changes.keySet().iterator();
while (iter.hasNext()) {
String attrib = iter.next();
ValueAndCommit valueAndCommit = changes.get(attrib);
RevCommit commit = valueAndCommit.commit;
Optional<?> value = valueAndCommit.value;
if (porcelain) {
StringBuilder sb = new StringBuilder();
sb.append(attrib).append(' ');
sb.append(commit.getId().toString()).append(' ');
sb.append(commit.getAuthor().getName().or("")).append(' ');
sb.append(commit.getAuthor().getEmail().or("")).append(' ');
sb.append(Long.toString(commit.getAuthor().getTimestamp())).append(' ');
sb.append(Integer.toString(commit.getAuthor().getTimeZoneOffset()));
if (!noValues) {
sb.append(" ").append(TextValueSerializer.asString(Optional.of((Object) value.orNull())));
}
console.println(sb.toString());
} else {
Ansi ansi = newAnsi(console.getTerminal());
ansi.fg(GREEN).a(attrib + ": ").reset();
if (!noValues) {
String s = value.isPresent() ? value.get().toString() : "NULL";
ansi.fg(YELLOW).a(s).a(" ").reset();
}
ansi.a(commit.getId().toString().substring(0, 7)).a(" ");
ansi.a(commit.getAuthor().getName().or("")).a(" ");
ansi.a(commit.getAuthor().getEmail().or("")).a(" ");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String date = formatter.format(new Date(commit.getAuthor().getTimestamp() + commit.getAuthor().getTimeZoneOffset()));
ansi.a(date);
console.println(ansi.toString());
}
}
} catch (BlameException e) {
switch(e.statusCode) {
case FEATURE_NOT_FOUND:
throw new InvalidParameterException("The supplied path does not exist", e);
case PATH_NOT_FEATURE:
throw new InvalidParameterException("The supplied path does not resolve to a feature", e);
}
}
}
use of org.locationtech.geogig.cli.InvalidParameterException in project GeoGig by boundlessgeo.
the class OSMExportSL method exportRule.
private void exportRule(final MappingRule rule, final GeogigCLI cli) throws IOException {
Function<Feature, Optional<Feature>> function = new Function<Feature, Optional<Feature>>() {
@Override
public Optional<Feature> apply(Feature feature) {
Optional<Feature> mapped = rule.apply(feature);
return mapped;
}
};
SimpleFeatureType outputFeatureType = rule.getFeatureType();
String path = getOriginTreesFromOutputFeatureType(outputFeatureType);
DataStore dataStore = getDataStore();
try {
final String tableName = ensureTableExists(outputFeatureType, dataStore);
final SimpleFeatureSource source = dataStore.getFeatureSource(tableName);
if (!(source instanceof SimpleFeatureStore)) {
throw new CommandFailedException("Could not create feature store.");
}
final SimpleFeatureStore store = (SimpleFeatureStore) source;
if (overwrite) {
try {
store.removeFeatures(Filter.INCLUDE);
} catch (IOException e) {
throw new CommandFailedException("Error truncating table " + tableName, e);
}
}
ExportOp op = cli.getGeogig().command(ExportOp.class).setFeatureStore(store).setPath(path).setFeatureTypeConversionFunction(function);
try {
op.setProgressListener(cli.getProgressListener()).call();
cli.getConsole().println("OSM data exported successfully to " + tableName);
} catch (IllegalArgumentException iae) {
throw new InvalidParameterException(iae.getMessage(), iae);
} catch (GeoToolsOpException e) {
throw new CommandFailedException("Could not export. Error:" + e.statusCode.name(), e);
}
} finally {
dataStore.dispose();
}
}
use of org.locationtech.geogig.cli.InvalidParameterException in project GeoGig by boundlessgeo.
the class ShpExportDiff method getFeatureType.
private SimpleFeatureType getFeatureType(String path, GeogigCLI cli) {
checkParameter(path != null, "No path specified.");
String refspec;
if (path.contains(":")) {
refspec = path;
} else {
refspec = "WORK_HEAD:" + path;
}
checkParameter(!refspec.endsWith(":"), "No path specified.");
final GeoGIG geogig = cli.getGeogig();
Optional<ObjectId> rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(refspec.split(":")[0]).call();
checkParameter(rootTreeId.isPresent(), "Couldn't resolve '" + refspec + "' to a treeish object");
RevTree rootTree = geogig.getRepository().getTree(rootTreeId.get());
Optional<NodeRef> featureTypeTree = geogig.command(FindTreeChild.class).setChildPath(refspec.split(":")[1]).setParent(rootTree).setIndex(true).call();
checkParameter(featureTypeTree.isPresent(), "pathspec '" + refspec.split(":")[1] + "' did not match any valid path");
Optional<RevObject> revObject = cli.getGeogig().command(RevObjectParse.class).setObjectId(featureTypeTree.get().getMetadataId()).call();
if (revObject.isPresent() && revObject.get() instanceof RevFeatureType) {
RevFeatureType revFeatureType = (RevFeatureType) revObject.get();
if (revFeatureType.type() instanceof SimpleFeatureType) {
return (SimpleFeatureType) revFeatureType.type();
} else {
throw new InvalidParameterException("Cannot find feature type for the specified path");
}
} else {
throw new InvalidParameterException("Cannot find feature type for the specified path");
}
}
use of org.locationtech.geogig.cli.InvalidParameterException in project GeoGig by boundlessgeo.
the class ShpImport method runInternal.
/**
* Executes the import command using the provided options.
*/
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
checkParameter(shapeFile != null && !shapeFile.isEmpty(), "No shapefile specified");
for (String shp : shapeFile) {
DataStore dataStore = null;
try {
dataStore = getDataStore(shp);
} catch (InvalidParameterException e) {
cli.getConsole().println("The shapefile '" + shp + "' could not be found, skipping...");
continue;
}
if (fidAttribute != null) {
AttributeDescriptor attrib = dataStore.getSchema(dataStore.getNames().get(0)).getDescriptor(fidAttribute);
if (attrib == null) {
throw new InvalidParameterException("The specified attribute does not exist in the selected shapefile");
}
}
try {
cli.getConsole().println("Importing from shapefile " + shp);
ProgressListener progressListener = cli.getProgressListener();
ImportOp command = cli.getGeogig().command(ImportOp.class).setAll(true).setTable(null).setAlter(alter).setOverwrite(!add).setDestinationPath(destTable).setDataStore(dataStore).setFidAttribute(fidAttribute).setAdaptToDefaultFeatureType(!forceFeatureType);
// force the import not to use paging due to a bug in the shapefile datastore
command.setUsePaging(false);
command.setProgressListener(progressListener).call();
cli.getConsole().println(shp + " imported successfully.");
} catch (GeoToolsOpException e) {
switch(e.statusCode) {
case NO_FEATURES_FOUND:
throw new CommandFailedException("No features were found in the shapefile.", e);
case UNABLE_TO_GET_NAMES:
throw new CommandFailedException("Unable to get feature types from the shapefile.", e);
case UNABLE_TO_GET_FEATURES:
throw new CommandFailedException("Unable to get features from the shapefile.", e);
case UNABLE_TO_INSERT:
throw new CommandFailedException("Unable to insert features into the working tree.", e);
case INCOMPATIBLE_FEATURE_TYPE:
throw new CommandFailedException("The feature type of the data to import does not match the feature type of the destination tree and cannot be imported\n" + "USe the --force-featuretype switch to import using the original featuretype and crete a mixed type tree", e);
default:
throw new CommandFailedException("Import failed with exception: " + e.statusCode.name(), e);
}
} finally {
dataStore.dispose();
cli.getConsole().flush();
}
}
}
Aggregations