Package org.locationtech.geogig.cli

Examples of org.locationtech.geogig.cli.CommandFailedException


     * Executes the diff-tree command with the specified options.
     */
    @Override
    protected void runInternal(GeogigCLI cli) throws IOException {
        if (refSpec.size() > 2) {
            throw new CommandFailedException("Tree refspecs list is too long :" + refSpec);
        }

        if (treeStats && describe) {
            throw new CommandFailedException(
                    "Cannot use --describe and --tree-stats simultaneously");
        }

        GeoGIG geogig = cli.getGeogig();

View Full Code Here


        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
View Full Code Here

            ConfigAction action = resolveConfigAction();

            if (action == ConfigAction.CONFIG_NO_ACTION) {
                printUsage(cli);
                throw new CommandFailedException();
            }
            if (global && local) {
                printUsage(cli);
                throw new CommandFailedException();
            }
            ConfigScope scope = ConfigScope.DEFAULT;

            if (global) {
                scope = ConfigScope.GLOBAL;
            } else if (local) {
                scope = ConfigScope.LOCAL;
            }

            final Optional<Map<String, String>> commandResult = geogig.command(ConfigOp.class)
                    .setScope(scope).setAction(action).setName(name).setValue(value).call();

            if (commandResult.isPresent()) {
                switch (action) {
                case CONFIG_GET: {
                    cli.getConsole().println(commandResult.get().get(name));
                    break;
                }
                case CONFIG_LIST: {
                    Iterator<Map.Entry<String, String>> it = commandResult.get().entrySet()
                            .iterator();
                    while (it.hasNext()) {
                        Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next();
                        cli.getConsole().println(pairs.getKey() + "=" + pairs.getValue());
                    }
                    break;
                }
                default:
                    break;
                }
            }
        } catch (ConfigException e) {
            // These mirror 'git config' status codes. Some of these are unused,
            // since we don't have regex support yet.
            switch (e.statusCode) {
            case INVALID_LOCATION:
                // TODO: This could probably be more descriptive.
                throw new CommandFailedException("The config location is invalid", e);
            case CANNOT_WRITE:
                throw new CommandFailedException("Cannot write to the config", e);
            case SECTION_OR_NAME_NOT_PROVIDED:
                throw new InvalidParameterException("No section or name was provided", e);
            case SECTION_OR_KEY_INVALID:
                throw new InvalidParameterException("The section or key is invalid", e);
            case OPTION_DOES_NOT_EXIST:
View Full Code Here

        } catch (RevertConflictsException e) {
            StringBuilder sb = new StringBuilder();
            sb.append(e.getMessage() + "\n");
            sb.append("When you have fixed these conflicts, run 'geogig revert --continue' to continue the revert operation.\n");
            sb.append("To abort the revert operation, run 'geogig revert --abort'\n");
            throw new CommandFailedException(sb.toString());
        }

        if (abort) {
            cli.getConsole().println("Revert aborted successfully.");
        }
View Full Code Here

                checkParameter(branchRef.isPresent(), "The branch reference could not be resolved.");
                // Checkout <branch> prior to rebase
                try {
                    geogig.command(CheckoutOp.class).setSource(arguments.get(1)).call();
                } catch (CheckoutException e) {
                    throw new CommandFailedException(e.getMessage(), e);
                }

            }

            Optional<Ref> upstreamRef = geogig.command(RefParse.class).setName(arguments.get(0))
                    .call();
            checkParameter(upstreamRef.isPresent(), "The upstream reference could not be resolved.");
            rebase.setUpstream(Suppliers.ofInstance(upstreamRef.get().getObjectId()));
        }

        if (onto != null) {
            Optional<ObjectId> ontoId = geogig.command(RevParse.class).setRefSpec(onto).call();
            checkParameter(ontoId.isPresent(), "The onto reference could not be resolved.");
            rebase.setOnto(Suppliers.ofInstance(ontoId.get()));
        }

        try {
            rebase.call();
        } catch (RebaseConflictsException e) {
            StringBuilder sb = new StringBuilder();
            sb.append(e.getMessage() + "\n");
            sb.append("When you have fixed this conflicts, run 'geogig rebase --continue' to continue rebasing.\n");
            sb.append("If you would prefer to skip this commit, instead run 'geogig rebase --skip.\n");
            sb.append("To check out the original branch and stop rebasing, run 'geogig rebase --abort'\n");
            throw new CommandFailedException(sb.toString());
        }

        if (abort) {
            cli.getConsole().println("Rebase aborted successfully.");
        }
View Full Code Here

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

            cli.setExitOnFinish(false);
        } catch (BindException e) {
            String msg = String.format(
                    "Port %d already in use, use the --port parameter to specify a different port",
                    port);
            throw new CommandFailedException(msg, e);
        } catch (Exception e) {
            throw new CommandFailedException("Unable to start server", e);
        }
    }
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 CommandFailedException(
                        "The selected table already exists. Use -o to overwrite");
            }
        }

        SimpleFeatureSource featureSource = dataStore.getFeatureSource(tableName);
        if (!(featureSource instanceof SimpleFeatureStore)) {
            throw new CommandFailedException("Can't write to the selected table");
        }
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        if (overwrite) {
            try {
                featureStore.removeFeatures(Filter.INCLUDE);
            } catch (IOException e) {
                throw new CommandFailedException("Error accessing table: " + e.getMessage(), 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);
View Full Code Here

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

        } finally {
            executor.shutdownNow();
            try {
                executor.awaitTermination(30, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                throw new CommandFailedException(e);
            }
        }
    }
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.