use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.
the class PGList method runInternal.
/**
* Executes the list command using the provided options.
*/
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
DataStore dataStore = getDataStore();
try {
cli.getConsole().println("Fetching feature types...");
Optional<List<String>> features = cli.getGeogig().command(ListOp.class).setDataStore(dataStore).call();
if (features.isPresent()) {
for (String featureType : features.get()) {
cli.getConsole().println(" - " + featureType);
}
} else {
cli.getConsole().println("No features types were found in the specified database.");
}
} catch (GeoToolsOpException e) {
throw new CommandFailedException("Unable to get feature types from the database.", e);
} finally {
dataStore.dispose();
cli.getConsole().flush();
}
}
use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.
the class AbstractOracleCommand method getDataStore.
/**
* Constructs a new Oracle data store using connection parameters from {@link OracleCommonArgs}.
*
* @return the constructed data store
* @throws Exception
* @see DataStore
*/
protected DataStore getDataStore() {
Map<String, Serializable> params = Maps.newHashMap();
params.put(OracleNGDataStoreFactory.DBTYPE.key, "oracle");
params.put(OracleNGDataStoreFactory.HOST.key, commonArgs.host);
params.put(OracleNGDataStoreFactory.PORT.key, commonArgs.port.toString());
params.put(OracleNGDataStoreFactory.SCHEMA.key, commonArgs.schema);
params.put(OracleNGDataStoreFactory.DATABASE.key, commonArgs.database);
params.put(OracleNGDataStoreFactory.USER.key, commonArgs.username);
params.put(OracleNGDataStoreFactory.PASSWD.key, commonArgs.password);
// params.put(OracleNGDataStoreFactory.ESTIMATED_EXTENTS.key, commonArgs.estimatedExtent);
// params.put(OracleNGDataStoreFactory.LOOSEBBOX.key, commonArgs.looseBbox);
// if (!commonArgs.geometryMetadataTable.equals(""))
// params.put(OracleNGDataStoreFactory.GEOMETRY_METADATA_TABLE.key,
// commonArgs.geometryMetadataTable);
// params.put(OracleNGDataStoreFactory.FETCHSIZE.key, 1000);
DataStore dataStore;
try {
dataStore = dataStoreFactory.createDataStore(params);
} catch (IOException e) {
throw new CommandFailedException("Unable to connect using the specified database parameters.", e);
}
if (dataStore == null) {
throw new CommandFailedException("No suitable data store found for the provided parameters");
}
if (dataStore instanceof JDBCDataStore) {
Connection con = null;
try {
con = ((JDBCDataStore) dataStore).getDataSource().getConnection();
} catch (Exception e) {
throw new CommandFailedException("Error validating the database connection", e);
}
((JDBCDataStore) dataStore).closeSafe(con);
}
return dataStore;
}
use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.
the class OSMExportShp method exportRule.
private void exportRule(final MappingRule rule, final GeogigCLI cli, final File shapeFile) throws IOException {
if (shapeFile.exists() && !overwrite) {
throw new CommandFailedException("The selected shapefile already exists. Use -o to overwrite");
}
Function<Feature, Optional<Feature>> function = new Function<Feature, Optional<Feature>>() {
@Override
@Nullable
public Optional<Feature> apply(@Nullable Feature feature) {
Optional<Feature> mapped = rule.apply(feature);
return mapped;
}
};
SimpleFeatureType outputFeatureType = rule.getFeatureType();
String path = getOriginTreesFromOutputFeatureType(outputFeatureType);
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put(ShapefileDataStoreFactory.URLP.key, shapeFile.toURI().toURL());
params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.TRUE);
DataStore dataStore = dataStoreFactory.createNewDataStore(params);
try {
dataStore.createSchema(outputFeatureType);
final String typeName = dataStore.getTypeNames()[0];
final SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
checkParameter(source instanceof SimpleFeatureStore, "Could not create feature store. Shapefile may be read only");
final SimpleFeatureStore store = (SimpleFeatureStore) source;
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 " + shapeFile);
} catch (IllegalArgumentException iae) {
shapeFile.delete();
throw new org.locationtech.geogig.cli.InvalidParameterException(iae.getMessage(), iae);
} catch (GeoToolsOpException e) {
shapeFile.delete();
throw new CommandFailedException("Could not export. Error:" + e.statusCode.name(), e);
}
} finally {
dataStore.dispose();
}
}
use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.
the class OSMExportShp method runInternal.
/**
* Executes the export command using the provided options.
*/
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
Preconditions.checkNotNull(mappingFile != null, "A data mapping file must be specified");
if (args == null || args.isEmpty() || args.size() != 1) {
printUsage(cli);
throw new CommandFailedException();
}
String shapefile = args.get(0);
final File file = new File(shapefile);
final Mapping mapping = Mapping.fromFile(mappingFile);
List<MappingRule> rules = mapping.getRules();
checkParameter(!rules.isEmpty(), "No rules are defined in the specified mapping");
for (MappingRule rule : rules) {
File targetFile = file;
if (rules.size() > 1) {
String name = getNameWithoutExtension(file.getName()) + "_" + rule.getName() + ".shp";
targetFile = new File(file.getParentFile(), name);
}
exportRule(rule, cli, targetFile);
}
}
use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.
the class OSMMap method runInternal.
/**
* Executes the map command using the provided options.
*/
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
if (args == null || args.isEmpty() || args.size() != 1) {
printUsage(cli);
throw new CommandFailedException();
}
checkState(cli.getGeogig().getRepository().index().isClean() && cli.getGeogig().getRepository().workingTree().isClean(), "Working tree and index are not clean");
String mappingFilepath = args.get(0);
Mapping mapping = Mapping.fromFile(mappingFilepath);
geogig = cli.getGeogig();
ObjectId oldTreeId = geogig.getRepository().workingTree().getTree().getId();
message = message == null ? "Applied mapping " + new File(mappingFilepath).getName() : message;
ObjectId newTreeId = geogig.command(OSMMapOp.class).setMapping(mapping).setMessage(message).call().getId();
ConsoleReader console = cli.getConsole();
if (newTreeId.equals(oldTreeId)) {
console.println("No features matched the specified filter, or they provided no updated data.\n" + "No changes have been made to the working tree");
} else {
// print something?
}
}
Aggregations