Package org.locationtech.geogig.cli

Examples of org.locationtech.geogig.cli.CommandFailedException


                }
                cli.getConsole().println(msg);
            }

        } catch (RuntimeException e) {
            throw new CommandFailedException("Error importing OSM data: " + e.getMessage(), e);
        }

    }
View Full Code Here


            FeatureCollection fc = fjson.readFeatureCollection(in);
            @SuppressWarnings("unchecked")
            DataStore dataStore = new MemoryDataStore(fc);
            return dataStore;
        } catch (IOException ioe) {
            throw new CommandFailedException("Error opening GeoJSON: " + ioe.getMessage(), ioe);
        }
    }
View Full Code Here

     */
    @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");

View Full Code Here

    @Override
    protected void runInternal(GeogigCLI cli) throws IOException {

        if (args.isEmpty()) {
            printUsage(cli);
            throw new CommandFailedException();
        }

        String path = args.get(0);
        String tableName = args.get(1);

        checkParameter(tableName != null && !tableName.isEmpty(), "No table name specified");

        DataStore dataStore = getDataStore();

        ObjectId featureTypeId = null;
        if (!Arrays.asList(dataStore.getTypeNames()).contains(tableName)) {
            SimpleFeatureType outputFeatureType;
            if (sFeatureTypeId != null) {
                // Check the feature type id string is a correct id
                Optional<ObjectId> id = cli.getGeogig().command(RevParse.class)
                        .setRefSpec(sFeatureTypeId).call();
                checkParameter(id.isPresent(), "Invalid feature type reference", sFeatureTypeId);
                TYPE type = cli.getGeogig().command(ResolveObjectType.class).setObjectId(id.get())
                        .call();
                checkParameter(type.equals(TYPE.FEATURETYPE),
                        "Provided reference does not resolve to a feature type: ", sFeatureTypeId);
                outputFeatureType = (SimpleFeatureType) cli.getGeogig()
                        .command(RevObjectParse.class).setObjectId(id.get())
                        .call(RevFeatureType.class).get().type();
                featureTypeId = id.get();
            } else {
                try {
                    SimpleFeatureType sft = getFeatureType(path, cli);
                    outputFeatureType = new SimpleFeatureTypeImpl(new NameImpl(tableName),
                            sft.getAttributeDescriptors(), sft.getGeometryDescriptor(),
                            sft.isAbstract(), sft.getRestrictions(), sft.getSuper(),
                            sft.getDescription());
                } catch (GeoToolsOpException e) {
                    throw new CommandFailedException("No features to export.", e);
                }
            }
            try {
                dataStore.createSchema(outputFeatureType);
            } catch (IOException e) {
                throw new CommandFailedException("Cannot create new table in database", e);
            }
        } else {
            if (!overwrite) {
                throw new InvalidParameterException(
                        "The selected table already exists. Use -o to overwrite");
            }
        }

        SimpleFeatureSource featureSource;
        try {
            featureSource = dataStore.getFeatureSource(tableName);
        } catch (IOException e) {
            throw new CommandFailedException("Can't aquire the feature source", e);
        }
        if (featureSource instanceof SimpleFeatureStore) {
            SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
            if (overwrite) {
                try {
                    featureStore.removeFeatures(Filter.INCLUDE);
                } catch (IOException e) {
                    throw new CommandFailedException("Error trying to remove features", e);
                }
            }
            ExportOp op = cli.getGeogig().command(ExportOp.class).setFeatureStore(featureStore)
                    .setPath(path).setFilterFeatureTypeId(featureTypeId).setAlter(alter);
            if (defaultType) {
                op.exportDefaultFeatureType();
            }
            try {
                op.setProgressListener(cli.getProgressListener()).call();
            } catch (IllegalArgumentException iae) {
                throw new org.locationtech.geogig.cli.InvalidParameterException(iae.getMessage(), iae);
            } catch (GeoToolsOpException e) {
                switch (e.statusCode) {
                case MIXED_FEATURE_TYPES:
                    throw new CommandFailedException(
                            "The selected tree contains mixed feature types. Use --defaulttype or --featuretype <feature_type_ref> to export.",
                            e);
                default:
                    throw new CommandFailedException("Could not export. Error:"
                            + e.statusCode.name(), e);
                }
            }

            cli.getConsole().println(path + " exported successfully to " + tableName);
        } else {
            throw new CommandFailedException("Can't write to the selected table");
        }

    }
View Full Code Here

        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();
        }
View Full Code Here

    private String ensureTableExists(SimpleFeatureType outputFeatureType, DataStore dataStore)
            throws IOException {
        final String tableName = outputFeatureType.getName().getLocalPart();
        if (Arrays.asList(dataStore.getTypeNames()).contains(tableName)) {
            if (!overwrite) {
                throw new CommandFailedException(
                        "The selected table already exists. Use -o to overwrite");
            }
        } else {
            try {
                dataStore.createSchema(outputFeatureType);
            } catch (IOException e) {
                throw new CommandFailedException("Cannot create new table " + tableName);
            }
        }
        return tableName;
    }
View Full Code Here

    @Override
    protected void runInternal(GeogigCLI cli) throws InvalidParameterException,
            CommandFailedException, IOException {
        if (args.isEmpty()) {
            printUsage(cli);
            throw new CommandFailedException();
        }

        String path = args.get(0);
        String geojson = args.get(1);

        File file = new File(geojson);
        if (file.exists() && !overwrite) {
            throw new CommandFailedException(
                    "The selected GeoJSON file already exists. Use -o to overwrite");
        }

        SimpleFeatureType outputFeatureType;
        ObjectId featureTypeId;
        if (sFeatureTypeId != null) {
            // Check the feature type id string is a correct id
            Optional<ObjectId> id = cli.getGeogig().command(RevParse.class)
                    .setRefSpec(sFeatureTypeId).call();
            checkParameter(id.isPresent(), "Invalid feature type reference", sFeatureTypeId);
            TYPE type = cli.getGeogig().command(ResolveObjectType.class).setObjectId(id.get())
                    .call();
            checkParameter(type.equals(TYPE.FEATURETYPE),
                    "Provided reference does not resolve to a feature type: ", sFeatureTypeId);
            outputFeatureType = (SimpleFeatureType) cli.getGeogig().command(RevObjectParse.class)
                    .setObjectId(id.get()).call(RevFeatureType.class).get().type();
            featureTypeId = id.get();
        } else {
            try {
                outputFeatureType = getFeatureType(path, cli);
                featureTypeId = null;
            } catch (GeoToolsOpException e) {
                cli.getConsole().println("No features to export.");
                return;
            }
        }
        DataStore dataStore = new MemoryDataStore(outputFeatureType);

        final String typeName = dataStore.getTypeNames()[0];
        final SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
        if (!(featureSource instanceof SimpleFeatureStore)) {
            throw new CommandFailedException("Could not create feature store.");
        }
        final SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        ExportOp op = cli.getGeogig().command(ExportOp.class).setFeatureStore(featureStore)
                .setPath(path).setFilterFeatureTypeId(featureTypeId).setAlter(alter);

        op.setTransactional(false);
        if (defaultType) {
            op.exportDefaultFeatureType();
        }
        FileWriter writer = null;
        try {
            op.setProgressListener(cli.getProgressListener()).call();
            FeatureJSON fjson = new FeatureJSON();
            @SuppressWarnings("rawtypes")
            FeatureCollection fc = featureSource.getFeatures();
            writer = new FileWriter(file);
            fjson.writeFeatureCollection(fc, writer);
        } catch (IllegalArgumentException iae) {
            throw new org.locationtech.geogig.cli.InvalidParameterException(iae.getMessage(), iae);
        } catch (GeoToolsOpException e) {
            file.delete();
            switch (e.statusCode) {
            case MIXED_FEATURE_TYPES:
                throw new CommandFailedException(
                        "Error: The selected tree contains mixed feature types. Use --defaulttype or --featuretype <feature_type_ref> to export.",
                        e);
            default:
                throw new CommandFailedException("Could not export. Error:" + e.statusCode.name(),
                        e);
            }
        } finally {
            writer.flush();
            writer.close();
View Full Code Here

    @Override
    protected void runInternal(GeogigCLI cli) throws IOException {

        if (args == null || args.isEmpty() || args.size() != 1) {
            printUsage(cli);
            throw new CommandFailedException();
        }

        String path = args.get(0);

        geogig = cli.getGeogig();
View Full Code Here

                "Cannot specify a depth and full depth.  Use --depth <depth> or --fulldepth.");

        GeoGIG geogig = cli.getGeogig();
        if (depth > 0 || fulldepth) {
            if (!geogig.getRepository().getDepth().isPresent()) {
                throw new CommandFailedException(
                        "Depth operations can only be used on a shallow clone.");
            }
        }

        PullOp pull = geogig.command(PullOp.class);
        pull.setProgressListener(cli.getProgressListener());
        pull.setAll(all).setRebase(rebase).setFullDepth(fulldepth);
        pull.setDepth(depth);

        if (args != null) {
            if (args.size() > 0) {
                pull.setRemote(args.get(0));
            }
            for (int i = 1; i < args.size(); i++) {
                pull.addRefSpec(args.get(i));
            }
        }

        try {
            final PullResult result = pull.call();

            ConsoleReader console = cli.getConsole();
            TransferSummary fetchResult = result.getFetchResult();
            FetchResultPrinter.print(fetchResult, console);

            final Ref oldRef = result.getOldRef();
            final Ref newRef = result.getNewRef();

            if (oldRef == null && newRef == null) {
                console.println("Nothing to pull.");
            } else if (Objects.equal(oldRef, newRef)) {
                String name = oldRef == null ? newRef.getName() : oldRef.getName();
                name = Ref.localName(name);
                console.println(name + " already up to date.");
            } else {
                String oldTreeish;
                String newTreeish = newRef.getObjectId().toString();
                if (oldRef == null) {
                    console.println("From " + result.getRemoteName());
                    console.println(" * [new branch]     " + newRef.localName() + " -> "
                            + newRef.getName());

                    oldTreeish = ObjectId.NULL.toString();
                } else {
                    oldTreeish = oldRef.getObjectId().toString();
                }

                DiffObjectCount count = geogig.command(DiffCount.class).setOldVersion(oldTreeish)
                        .setNewVersion(newTreeish).call();
                long added = count.getFeaturesAdded();
                long removed = count.getFeaturesRemoved();
                long modified = count.getFeaturesChanged();
                console.println(String.format("Features Added: %,d Removed: %,d Modified: %,d",
                        added, removed, modified));
            }
        } catch (SynchronizationException e) {
            switch (e.statusCode) {
            case HISTORY_TOO_SHALLOW:
            default:
                throw new CommandFailedException("Unable to pull, the remote history is shallow.",
                        e);
            }
        }

    }
View Full Code Here

            reset.setMode(mode);

            reset.call();
        } catch (IllegalArgumentException iae) {
            throw new CommandFailedException(iae.getMessage(), iae);
        } catch (IllegalStateException ise) {
            throw new CommandFailedException(ise.getMessage(), ise);
        }

        if (!geogig.getRepository().workingTree().isClean()) {
            try {
                Iterator<DiffEntry> unstaged = geogig.command(DiffWorkTree.class).setFilter(null)
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.cli.CommandFailedException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.