Search in sources :

Example 56 with CommandFailedException

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();
    }
}
Also used : DataStore(org.geotools.data.DataStore) List(java.util.List) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) GeoToolsOpException(org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)

Example 57 with CommandFailedException

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

the class GeoJsonExportTest method testExportToFileThatAlreadyExists.

@Test
public void testExportToFileThatAlreadyExists() throws Exception {
    GeoJsonExport exportCommand = new GeoJsonExport();
    String geoJsonFileName = new File(geogig.getPlatform().pwd(), "TestPoints.geojson").getAbsolutePath();
    exportCommand.args = Arrays.asList("WORK_HEAD:Points", geoJsonFileName);
    exportCommand.run(cli);
    exportCommand.args = Arrays.asList("Lines", geoJsonFileName);
    try {
        exportCommand.run(cli);
        fail();
    } catch (CommandFailedException e) {
    } finally {
        deleteGeoJson(geoJsonFileName);
    }
}
Also used : File(java.io.File) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) Test(org.junit.Test)

Example 58 with CommandFailedException

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

the class ShpExportTest method testExportToFileThatAlreadyExists.

@Test
public void testExportToFileThatAlreadyExists() throws Exception {
    ShpExport exportCommand = new ShpExport();
    String shapeFileName = new File(geogig.getPlatform().pwd(), "TestPoints.shp").getAbsolutePath();
    ;
    exportCommand.args = Arrays.asList("WORK_HEAD:Points", shapeFileName);
    exportCommand.dataStoreFactory = TestHelper.createTestFactory();
    exportCommand.run(cli);
    exportCommand.args = Arrays.asList("Lines", shapeFileName);
    try {
        exportCommand.run(cli);
        fail();
    } catch (CommandFailedException e) {
    } finally {
        deleteShapeFile(shapeFileName);
    }
}
Also used : File(java.io.File) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) Test(org.junit.Test)

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