Package org.locationtech.geogig.cli

Examples of org.locationtech.geogig.cli.CommandFailedException


        WorkingTree workingTree = geogig.getContext().workingTree();

        while (changesets.hasNext()) {
            Changeset changeset = changesets.next();
            if (changeset.isOpen()) {
                throw new CommandFailedException("Can't import past changeset " + changeset.getId()
                        + " as it is still open.");
            }
            String desc = String.format("obtaining osm changeset %,d...", changeset.getId());
            console.print(desc);
            console.flush();
View Full Code Here


    }

    private SymRef getHead(GeoGIG geogig) {
        final Ref currentHead = geogig.command(RefParse.class).setName(Ref.HEAD).call().get();
        if (!(currentHead instanceof SymRef)) {
            throw new CommandFailedException("Cannot run on a dettached HEAD");
        }
        return (SymRef) currentHead;
    }
View Full Code Here

            if (features.isPresent()) {
                for (String featureType : features.get()) {
                    cli.getConsole().println(" - " + featureType);
                }
            } else {
                throw new CommandFailedException(
                        "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();
        }
    }
View Full Code Here

            if (features.isPresent()) {
                for (String featureType : features.get()) {
                    cli.getConsole().println(" - " + featureType);
                }
            } else {
                throw new CommandFailedException(
                        "No features types were found in the specified database.");
            }
        } catch (GeoToolsOpException e) {
            throw new CommandFailedException("Unable to get feature types from the database.");
        } finally {
            dataStore.dispose();
            cli.getConsole().flush();
        }
    }
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 truncating 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

        checkParameter(patchFile.exists(), "Patch file cannot be found");
        FileInputStream stream;
        try {
            stream = new FileInputStream(patchFile);
        } catch (FileNotFoundException e1) {
            throw new CommandFailedException("Can't open patch file " + patchFile, e1);
        }
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            Closeables.closeQuietly(reader);
            Closeables.closeQuietly(stream);
            throw new CommandFailedException("Error reading patch file " + patchFile, e);
        }
        Patch patch = PatchSerializer.read(reader);
        Closeables.closeQuietly(reader);
        Closeables.closeQuietly(stream);

        if (reverse) {
            patch = patch.reversed();
        }

        if (summary) {
            console.println(patch.toString());
        } else if (check) {
            VerifyPatchResults verify = cli.getGeogig().command(VerifyPatchOp.class)
                    .setPatch(patch).call();
            Patch toReject = verify.getToReject();
            Patch toApply = verify.getToApply();
            if (toReject.isEmpty()) {
                console.println("Patch can be applied.");
            } else {
                console.println("Error: Patch cannot be applied\n");
                console.println("Applicable entries:\n");
                console.println(toApply.toString());
                console.println("\nConflicting entries:\n");
                console.println(toReject.toString());
            }
        } else {
            try {
                Patch rejected = geogig.command(ApplyPatchOp.class).setPatch(patch)
                        .setApplyPartial(reject).call();
                if (reject) {
                    if (rejected.isEmpty()) {
                        console.println("Patch applied succesfully");
                    } else {
                        int accepted = patch.count() - rejected.count();
                        StringBuilder sb = new StringBuilder();
                        File file = new File(patchFile.getAbsolutePath() + ".rej");
                        sb.append("Patch applied only partially.\n");
                        sb.append(Integer.toString(accepted) + " changes were applied.\n");
                        sb.append(Integer.toString(rejected.count()) + " changes were rejected.\n");
                        BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
                        PatchSerializer.write(writer, patch);
                        writer.flush();
                        writer.close();
                        sb.append("Patch file with rejected changes created at "
                                + file.getAbsolutePath() + "\n");
                        throw new CommandFailedException(sb.toString());
                    }
                } else {
                    console.println("Patch applied succesfully");
                }
            } catch (CannotApplyPatchException e) {
                throw new CommandFailedException(e);
            }

        }

    }
View Full Code Here

                break;
            }
        } catch (CheckoutException e) {
            switch (e.statusCode) {
            case LOCAL_CHANGES_NOT_COMMITTED:
                throw new CommandFailedException(
                        "Working tree and index are not clean. To overwrite local changes, use the --force option",
                        e);
            case UNMERGED_PATHS:
                throw new CommandFailedException(e.getMessage(), e);
            }
        }
    }
View Full Code Here

     */
    @Override
    public void runInternal(GeogigCLI cli) {
        if (params == null || params.size() != 1) {
            printUsage(cli);
            throw new CommandFailedException();
        }

        try {
            cli.getGeogig().command(RemoteRemoveOp.class).setName(params.get(0)).call();
        } catch (RemoteException e) {
            switch (e.statusCode) {
            case REMOTE_NOT_FOUND:
                throw new CommandFailedException("Could not find a remote called '" + params.get(0)
                        + "'.", e);
            default:
                throw new CommandFailedException(e.getMessage(), e);
            }
        }
    }
View Full Code Here

     */
    @Override
    protected void runInternal(GeogigCLI cli) throws IOException {
        if (args.size() != 4) {
            printUsage(cli);
            throw new CommandFailedException();
        }

        String commitOld = args.get(0);
        String commitNew = args.get(1);
        String path = args.get(2);
        String shapefile = args.get(3);

        ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();

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

        Map<String, Serializable> params = new HashMap<String, Serializable>();
        params.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL());
        params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.FALSE);
        params.put(ShapefileDataStoreFactory.ENABLE_SPATIAL_INDEX.key, Boolean.FALSE);

        ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory
                .createNewDataStore(params);

        SimpleFeatureType outputFeatureType;
        try {
            outputFeatureType = getFeatureType(path, cli);
        } catch (GeoToolsOpException e) {
            cli.getConsole().println("No features to export.");
            return;
        }

        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.add("geogig_fid", String.class);
        for (AttributeDescriptor descriptor : outputFeatureType.getAttributeDescriptors()) {
            builder.add(descriptor);
        }
        builder.setName(outputFeatureType.getName());
        builder.setCRS(outputFeatureType.getCoordinateReferenceSystem());
        outputFeatureType = builder.buildFeatureType();

        dataStore.createSchema(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;

        Function<Feature, Optional<Feature>> function = getTransformingFunction(dataStore
                .getSchema());

        ExportDiffOp op = cli.getGeogig().command(ExportDiffOp.class).setFeatureStore(featureStore)
                .setPath(path).setOldRef(commitOld).setNewRef(commitNew).setUseOld(old)
                .setTransactional(false).setFeatureTypeConversionFunction(function);
        try {
            op.setProgressListener(cli.getProgressListener()).call();
        } 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.", e);
            default:
                throw new CommandFailedException("Could not export. Error:" + e.statusCode.name(),
                        e);
            }
        }
        cli.getConsole().println(path + " exported successfully to " + shapefile);

View Full Code Here

                dataStore = getDataStore();

                String tableName = outputFeatureType.getName().getLocalPart();
                if (Arrays.asList(dataStore.getTypeNames()).contains(tableName)) {
                    if (!overwrite) {
                        throw new CommandFailedException("A table named '" + tableName
                                + "'already exists. Use -o to overwrite");
                    }
                } else {
                    try {
                        dataStore.createSchema(outputFeatureType);
                    } catch (IOException e) {
                        throw new CommandFailedException("Cannot create new table in database", e);
                    }
                }

                final SimpleFeatureSource featureSource = dataStore.getFeatureSource(tableName);
                if (!(featureSource instanceof SimpleFeatureStore)) {
                    throw new CommandFailedException(
                            "Could not create feature store. Data source is read only.");
                }
                final SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
                if (overwrite) {
                    featureStore.removeFeatures(Filter.INCLUDE);
                }
                ExportOp op = cli.getGeogig().command(ExportOp.class).setFeatureStore(featureStore)
                        .setPath(path).setFeatureTypeConversionFunction(function);
                try {
                    op.setProgressListener(cli.getProgressListener()).call();
                    cli.getConsole().println("OSM data exported successfully to " + tableName);
                } catch (IllegalArgumentException iae) {
                    throw new org.locationtech.geogig.cli.InvalidParameterException(iae.getMessage(), iae);
                } catch (GeoToolsOpException e) {
                    throw new CommandFailedException("Could not export. Error:"
                            + e.statusCode.name(), e);
                }
            } catch (IOException e) {
                throw new IllegalStateException("Cannot connect to database: " + e.getMessage(), e);
            } finally {
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.