Search in sources :

Example 11 with RevTree

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

the class OSMExportTest method testExportOnlyNodes.

@Test
public void testExportOnlyNodes() throws Exception {
    String filename = OSMImportOp.class.getResource("nodes.xml").getFile();
    File file = new File(filename);
    cli.execute("osm", "import", file.getAbsolutePath());
    cli.execute("add");
    cli.execute("commit", "-m", "message");
    Optional<RevTree> tree = cli.getGeogig().command(RevObjectParse.class).setRefSpec("HEAD:node").call(RevTree.class);
    assertTrue(tree.isPresent());
    assertTrue(tree.get().size() > 0);
    File exportFile = new File(tempFolder.getRoot(), "export.xml");
    cli.execute("osm", "export", exportFile.getAbsolutePath());
}
Also used : OSMImportOp(org.locationtech.geogig.osm.internal.OSMImportOp) File(java.io.File) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 12 with RevTree

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

the class DiffCountConsumer method addTreeFeatures.

private boolean addTreeFeatures(ObjectId treeId, boolean leftPresent, boolean rightPresent) {
    RevTree tree = db.getTree(treeId);
    long size = tree.size();
    if (leftPresent && rightPresent) {
        count.changedFeatures(size);
    } else if (leftPresent) {
        count.removedFeatures(size);
    } else {
        count.addedFeatures(size);
    }
    int numTrees = tree.numTrees();
    return numTrees > 0;
}
Also used : RevTree(org.locationtech.geogig.api.RevTree)

Example 13 with RevTree

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

the class LsTreeOp method _call.

/**
     * @see java.util.concurrent.Callable#call()
     */
protected Iterator<NodeRef> _call() {
    String ref = this.ref;
    if (ref == null) {
        ref = Ref.WORK_HEAD;
    }
    ObjectId metadataId = ObjectId.NULL;
    final String path = ref.lastIndexOf(':') != -1 ? ref.substring(ref.lastIndexOf(':') + 1) : "";
    if (!path.isEmpty()) {
        final String providedRefName = ref.lastIndexOf(':') != -1 ? ref.substring(0, ref.lastIndexOf(':')) : null;
        if (providedRefName != null) {
            Optional<ObjectId> rootTreeId = command(ResolveTreeish.class).setTreeish(providedRefName).call();
            if (rootTreeId.isPresent()) {
                RevTree rootTree = command(RevObjectParse.class).setObjectId(rootTreeId.get()).call(RevTree.class).get();
                Optional<NodeRef> treeRef = command(FindTreeChild.class).setChildPath(path).setIndex(true).setParent(rootTree).call();
                metadataId = treeRef.isPresent() ? treeRef.get().getMetadataId() : ObjectId.NULL;
            }
        }
    }
    // is it just a ref name?
    Optional<Ref> reference = command(RefParse.class).setName(ref).call();
    if (reference.isPresent()) {
        if (reference.get().getObjectId().isNull()) {
            return Iterators.emptyIterator();
        }
    }
    Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref).call(RevObject.class);
    Optional<NodeRef> treeRef = Optional.absent();
    if (!revObject.isPresent()) {
        if (Ref.WORK_HEAD.equals(ref)) {
            // tree but it is empty
            return Iterators.emptyIterator();
        }
        // let's try to see if it is a feature type or feature in the working tree
        NodeRef.checkValidPath(ref);
        treeRef = command(FindTreeChild.class).setParent(workingTree().getTree()).setChildPath(ref).setIndex(true).call();
        Preconditions.checkArgument(treeRef.isPresent(), "Invalid reference: %s", ref);
        ObjectId treeId = treeRef.get().objectId();
        metadataId = treeRef.get().getMetadataId();
        revObject = command(RevObjectParse.class).setObjectId(treeId).call(RevObject.class);
    }
    checkArgument(revObject.isPresent(), "Invalid reference: %s", ref);
    final TYPE type = revObject.get().getType();
    switch(type) {
        case FEATURE:
            NodeRef nodeRef = treeRef.isPresent() ? treeRef.get() : null;
            List<NodeRef> nodeRefs = Lists.newArrayList();
            nodeRefs.add(nodeRef);
            // If show trees options is passed in show all trees that contain this feature
            if (this.strategy == Strategy.TREES_ONLY) {
                if (nodeRef != null) {
                    while (!nodeRef.getParentPath().isEmpty()) {
                        treeRef = command(FindTreeChild.class).setParent(workingTree().getTree()).setChildPath(nodeRef.getParentPath()).setIndex(true).call();
                        nodeRef = treeRef.get();
                        nodeRefs.add(nodeRef);
                    }
                }
            }
            return nodeRefs.iterator();
        case COMMIT:
            RevCommit revCommit = (RevCommit) revObject.get();
            ObjectId treeId = revCommit.getTreeId();
            revObject = command(RevObjectParse.class).setObjectId(treeId).call(RevObject.class);
        case TREE:
            DepthTreeIterator.Strategy iterStrategy;
            switch(this.strategy) {
                case CHILDREN:
                    iterStrategy = DepthTreeIterator.Strategy.CHILDREN;
                    break;
                case FEATURES_ONLY:
                    iterStrategy = DepthTreeIterator.Strategy.FEATURES_ONLY;
                    break;
                case TREES_ONLY:
                    iterStrategy = DepthTreeIterator.Strategy.TREES_ONLY;
                    break;
                case DEPTHFIRST:
                    iterStrategy = DepthTreeIterator.Strategy.RECURSIVE;
                    break;
                case DEPTHFIRST_ONLY_FEATURES:
                    iterStrategy = DepthTreeIterator.Strategy.RECURSIVE_FEATURES_ONLY;
                    break;
                case DEPTHFIRST_ONLY_TREES:
                    iterStrategy = DepthTreeIterator.Strategy.RECURSIVE_TREES_ONLY;
                    break;
                default:
                    throw new IllegalStateException("Unknown strategy: " + this.strategy);
            }
            RevTree tree = (RevTree) revObject.get();
            ObjectDatabase database = stagingDatabase();
            DepthTreeIterator iter = new DepthTreeIterator(path, metadataId, tree, database, iterStrategy);
            iter.setBoundsFilter(refBoundsFilter);
            return iter;
        default:
            throw new IllegalArgumentException(String.format("Invalid reference: %s", ref));
    }
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) NodeRef(org.locationtech.geogig.api.NodeRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) DepthTreeIterator(org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator) TYPE(org.locationtech.geogig.api.RevObject.TYPE) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 14 with RevTree

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

the class ResolveFeatureType method _call.

@Override
protected Optional<RevFeatureType> _call() {
    Preconditions.checkState(refSpec != null, "ref spec has not been set.");
    final String fullRefspec;
    if (refSpec.contains(":")) {
        fullRefspec = refSpec;
    } else {
        fullRefspec = Ref.WORK_HEAD + ":" + refSpec;
    }
    final String ref = fullRefspec.substring(0, fullRefspec.indexOf(':'));
    final String path = fullRefspec.substring(fullRefspec.indexOf(':') + 1);
    ObjectId parentId = command(ResolveTreeish.class).setTreeish(ref).call().get();
    Optional<RevTree> parent = command(RevObjectParse.class).setObjectId(parentId).call(RevTree.class);
    if (!parent.isPresent()) {
        return Optional.absent();
    }
    Optional<NodeRef> node = command(FindTreeChild.class).setParent(parent.get()).setChildPath(path).setIndex(true).call();
    if (!node.isPresent()) {
        return Optional.absent();
    }
    NodeRef found = node.get();
    ObjectId metadataID = found.getMetadataId();
    Optional<RevFeatureType> ft = command(RevObjectParse.class).setObjectId(metadataID).call(RevFeatureType.class);
    return ft;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree)

Example 15 with RevTree

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

the class WriteBack method getTreeChild.

private Optional<NodeRef> getTreeChild(RevTreeBuilder parent, String childPath) {
    RevTree realParent = parent.build();
    FindTreeChild cmd = command(FindTreeChild.class).setIndex(true).setParent(realParent).setChildPath(childPath);
    Optional<NodeRef> nodeRef = cmd.call();
    return nodeRef;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) 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