Search in sources :

Example 96 with RevTree

use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.

the class ShpExport method getFeatureType.

private SimpleFeatureType getFeatureType(String path, GeogigCLI cli) {
    checkParameter(path != null, "No path specified.");
    String refspec;
    if (path.contains(":")) {
        refspec = path;
    } else {
        refspec = "WORK_HEAD:" + path;
    }
    checkParameter(!refspec.endsWith(":"), "No path specified.");
    final GeoGIG geogig = cli.getGeogig();
    Optional<ObjectId> rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(refspec.split(":")[0]).call();
    checkParameter(rootTreeId.isPresent(), "Couldn't resolve '" + refspec + "' to a treeish object");
    RevTree rootTree = geogig.getRepository().getTree(rootTreeId.get());
    Optional<NodeRef> featureTypeTree = geogig.command(FindTreeChild.class).setChildPath(refspec.split(":")[1]).setParent(rootTree).setIndex(true).call();
    checkParameter(featureTypeTree.isPresent(), "pathspec '" + refspec.split(":")[1] + "' did not match any valid path");
    Optional<RevObject> revObject = cli.getGeogig().command(RevObjectParse.class).setObjectId(featureTypeTree.get().getMetadataId()).call();
    if (revObject.isPresent() && revObject.get() instanceof RevFeatureType) {
        RevFeatureType revFeatureType = (RevFeatureType) revObject.get();
        if (revFeatureType.type() instanceof SimpleFeatureType) {
            return (SimpleFeatureType) revFeatureType.type();
        } else {
            throw new InvalidParameterException("Cannot find feature type for the specified path");
        }
    } else {
        throw new InvalidParameterException("Cannot find feature type for the specified path");
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevTree(org.locationtech.geogig.api.RevTree)

Example 97 with RevTree

use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.

the class PGExport method getFeatureType.

private SimpleFeatureType getFeatureType(String path, GeogigCLI cli) {
    checkParameter(path != null, "No path specified.");
    String refspec;
    if (path.contains(":")) {
        refspec = path;
    } else {
        refspec = "WORK_HEAD:" + path;
    }
    checkParameter(!refspec.endsWith(":"), "No path specified.");
    final GeoGIG geogig = cli.getGeogig();
    Optional<ObjectId> rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(refspec.split(":")[0]).call();
    checkParameter(rootTreeId.isPresent(), "Couldn't resolve '" + refspec + "' to a treeish object");
    RevTree rootTree = geogig.getRepository().getTree(rootTreeId.get());
    Optional<NodeRef> featureTypeTree = geogig.command(FindTreeChild.class).setChildPath(refspec.split(":")[1]).setParent(rootTree).setIndex(true).call();
    checkParameter(featureTypeTree.isPresent(), "pathspec '" + refspec.split(":")[1] + "' did not match any valid path");
    Optional<RevObject> revObject = cli.getGeogig().command(RevObjectParse.class).setObjectId(featureTypeTree.get().getMetadataId()).call();
    if (revObject.isPresent() && revObject.get() instanceof RevFeatureType) {
        RevFeatureType revFeatureType = (RevFeatureType) revObject.get();
        if (revFeatureType.type() instanceof SimpleFeatureType) {
            return (SimpleFeatureType) revFeatureType.type();
        } else {
            throw new InvalidParameterException("Cannot find feature type for the specified path");
        }
    } else {
        throw new InvalidParameterException("Cannot find feature type for the specified path");
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevTree(org.locationtech.geogig.api.RevTree)

Example 98 with RevTree

use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.

the class GeoJsonExport method getFeatureType.

private SimpleFeatureType getFeatureType(String path, GeogigCLI cli) {
    checkParameter(path != null, "No path specified.");
    String refspec;
    if (path.contains(":")) {
        refspec = path;
    } else {
        refspec = "WORK_HEAD:" + path;
    }
    checkParameter(!refspec.endsWith(":"), "No path specified.");
    final GeoGIG geogig = cli.getGeogig();
    Optional<ObjectId> rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(refspec.split(":")[0]).call();
    checkParameter(rootTreeId.isPresent(), "Couldn't resolve '" + refspec + "' to a treeish object");
    RevTree rootTree = geogig.getRepository().getTree(rootTreeId.get());
    Optional<NodeRef> featureTypeTree = geogig.command(FindTreeChild.class).setChildPath(refspec.split(":")[1]).setParent(rootTree).setIndex(true).call();
    checkParameter(featureTypeTree.isPresent(), "pathspec '" + refspec.split(":")[1] + "' did not match any valid path");
    Optional<RevObject> revObject = cli.getGeogig().command(RevObjectParse.class).setObjectId(featureTypeTree.get().getMetadataId()).call();
    if (revObject.isPresent() && revObject.get() instanceof RevFeatureType) {
        RevFeatureType revFeatureType = (RevFeatureType) revObject.get();
        if (revFeatureType.type() instanceof SimpleFeatureType) {
            return (SimpleFeatureType) revFeatureType.type();
        } else {
            throw new InvalidParameterException("Cannot find feature type for the specified path");
        }
    } else {
        throw new InvalidParameterException("Cannot find feature type for the specified path");
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevTree(org.locationtech.geogig.api.RevTree)

Example 99 with RevTree

use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.

the class CatWebOp method run.

/**
     * Runs the command and builds the appropriate response
     * 
     * @param context - the context to use for this command
     * 
     * @throws CommandSpecException
     */
@Override
public void run(CommandContext context) {
    Preconditions.checkArgument(object != null && !object.equals(ObjectId.NULL));
    final Context geogig = this.getCommandLocator(context);
    Preconditions.checkState(geogig.stagingDatabase().exists(object));
    final RevObject revObject = geogig.stagingDatabase().get(object);
    switch(revObject.getType()) {
        case COMMIT:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeCommit((RevCommit) revObject, "commit", null, null, null);
                    out.finish();
                }
            });
            break;
        case TREE:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeTree((RevTree) revObject, "tree");
                    out.finish();
                }
            });
            break;
        case FEATURE:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeFeature((RevFeature) revObject, "feature");
                    out.finish();
                }
            });
            break;
        case FEATURETYPE:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeFeatureType((RevFeatureType) revObject, "featuretype");
                    out.finish();
                }
            });
            break;
        case TAG:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeTag((RevTag) revObject, "tag");
                    out.finish();
                }
            });
            break;
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) RevTag(org.locationtech.geogig.api.RevTag) RevObject(org.locationtech.geogig.api.RevObject) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) RevFeature(org.locationtech.geogig.api.RevFeature) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 100 with RevTree

use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.

the class LsTree method runInternal.

@Override
public void runInternal(final GeogigCLI cli) throws IOException {
    String ref;
    if (refList.isEmpty()) {
        ref = null;
    } else {
        ref = refList.get(0);
    }
    Strategy lsStrategy = Strategy.CHILDREN;
    if (recursive) {
        if (includeTrees) {
            lsStrategy = Strategy.DEPTHFIRST;
        } else if (onlyTrees) {
            lsStrategy = Strategy.DEPTHFIRST_ONLY_TREES;
        } else {
            lsStrategy = Strategy.DEPTHFIRST_ONLY_FEATURES;
        }
    } else {
        if (onlyTrees) {
            lsStrategy = Strategy.TREES_ONLY;
        }
    }
    Iterator<NodeRef> iter = cli.getGeogig().command(LsTreeOp.class).setReference(ref).setStrategy(lsStrategy).call();
    final ConsoleReader console = cli.getConsole();
    Function<NodeRef, CharSequence> printFunctor = new Function<NodeRef, CharSequence>() {

        @Override
        public CharSequence apply(NodeRef input) {
            StringBuilder sb = new StringBuilder();
            if (!verbose) {
                sb.append(input.path());
            } else {
                Envelope env = new Envelope();
                input.getNode().expand(env);
                StringBuilder sbenv = new StringBuilder();
                sbenv.append(Double.toString(env.getMinX())).append(";").append(Double.toString(env.getMaxX())).append(";").append(Double.toString(env.getMinY())).append(";").append(Double.toString(env.getMaxY()));
                sb.append(input.getMetadataId().toString()).append(' ').append(input.getType().toString().toLowerCase()).append(' ').append(input.objectId().toString()).append(' ').append(input.path()).append(' ').append(sbenv);
                if (input.getType().equals(TYPE.TREE)) {
                    RevTree tree = cli.getGeogig().command(RevObjectParse.class).setObjectId(input.objectId()).call(RevTree.class).get();
                    sb.append(' ').append(tree.size()).append(' ').append(tree.numTrees());
                }
            }
            return sb;
        }
    };
    Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
    while (lines.hasNext()) {
        console.println(lines.next());
    }
    console.flush();
}
Also used : ConsoleReader(jline.console.ConsoleReader) Envelope(com.vividsolutions.jts.geom.Envelope) NodeRef(org.locationtech.geogig.api.NodeRef) Function(com.google.common.base.Function) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) Strategy(org.locationtech.geogig.api.plumbing.LsTreeOp.Strategy) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevTree(org.locationtech.geogig.api.RevTree)

Aggregations

RevTree (org.locationtech.geogig.api.RevTree)214 Test (org.junit.Test)120 ObjectId (org.locationtech.geogig.api.ObjectId)91 NodeRef (org.locationtech.geogig.api.NodeRef)73 Node (org.locationtech.geogig.api.Node)56 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)47 RevCommit (org.locationtech.geogig.api.RevCommit)36 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)29 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)27 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)24 RevObject (org.locationtech.geogig.api.RevObject)21 RevFeature (org.locationtech.geogig.api.RevFeature)18 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)18 Bucket (org.locationtech.geogig.api.Bucket)17 TreeTestSupport.featureNode (org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode)17 File (java.io.File)16 Ref (org.locationtech.geogig.api.Ref)16 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)15 GeoGIG (org.locationtech.geogig.api.GeoGIG)14 OSMImportOp (org.locationtech.geogig.osm.internal.OSMImportOp)14