Search in sources :

Example 66 with RevTree

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

the class WriteTree2Test method verifyTree.

private void verifyTree(ObjectDatabase objectDb, String path, ObjectId repoTreeId) {
    assertTrue(String.format("tree '%s' (%s) is not present", path, repoTreeId), objectDb.exists(repoTreeId));
    RevTree tree = objectDb.getTree(repoTreeId);
    Iterator<Node> children = tree.children();
    while (children.hasNext()) {
        final Node node = children.next();
        if (TYPE.TREE.equals(node.getType())) {
            path = NodeRef.appendChild(path, node.getName());
            ObjectId objectId = node.getObjectId();
            verifyRepositoryTree(path, objectId);
        } else if (TYPE.FEATURE.equals(node.getType())) {
            verifyFeature(node);
        } else {
            throw new IllegalStateException(node.getType().toString());
        }
        verifyMetadata(node);
    }
    if (tree.buckets().isPresent()) {
        ImmutableCollection<Bucket> buckets = tree.buckets().get().values();
        for (Bucket b : buckets) {
            ObjectId bucketTreeId = b.id();
            verifyRepositoryTree(path + "/" + bucketTreeId.toString().substring(0, 8), bucketTreeId);
        }
    }
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Bucket(org.locationtech.geogig.api.Bucket) Node(org.locationtech.geogig.api.Node) RevTree(org.locationtech.geogig.api.RevTree)

Example 67 with RevTree

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

the class WriteTree2Test method createHeadTree.

private RevTree createHeadTree(NodeRef... treeRefs) {
    RevTree root = createFromRefs(objectDb, treeRefs);
    objectDb.put(root);
    CommitBuilder cb = new CommitBuilder(geogig.getPlatform());
    ObjectId treeId = root.getId();
    RevCommit commit = cb.setTreeId(treeId).setCommitter("Gabriel Roldan").setAuthor("Gabriel Roldan").build();
    objectDb.put(commit);
    SymRef head = (SymRef) geogig.command(RefParse.class).setName(Ref.HEAD).call().get();
    final String currentBranch = head.getTarget();
    geogig.command(UpdateRef.class).setName(currentBranch).setNewValue(commit.getId()).call();
    verifyRepositoryTree(NodeRef.ROOT, treeId);
    verifyTreeStructure(treeId, treeRefs);
    return root;
}
Also used : SymRef(org.locationtech.geogig.api.SymRef) ObjectId(org.locationtech.geogig.api.ObjectId) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 68 with RevTree

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

the class WriteTree2Test method createStageHeadTree.

private RevTree createStageHeadTree(NodeRef... treeRefs) {
    RevTree root = createFromRefs(indexDb, treeRefs);
    geogig.command(UpdateRef.class).setName(Ref.STAGE_HEAD).setNewValue(root.getId()).call();
    return root;
}
Also used : RevTree(org.locationtech.geogig.api.RevTree)

Example 69 with RevTree

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

the class WriteTree2Test method tree.

/**
     * Creates a tree reference for testing, forcing the specified id and metadata id, and with the
     * specified number of features (zero or more).
     * <p>
     * Note the tree is saved to the specified database only if its a leaf tree (more than zero
     * features), in order for the {@link #createFromRefs} method to be able of saving the parent
     */
private NodeRef tree(ObjectDatabase db, String path, String id, String mdId, int numFeatures) {
    Preconditions.checkArgument(numFeatures != 0 || EMPTY_ID.equals(id), "for zero features trees use RevTree.EMPTY_TREE_ID");
    final ObjectId treeId = id(id);
    final ObjectId metadataId = id(mdId);
    final String feturePrefix = NodeRef.nodeFromPath(path);
    RevTreeBuilder b = new RevTreeBuilder(db);
    if (numFeatures > 0) {
        for (int i = 0; i < numFeatures; i++) {
            Node fn = feature(db, feturePrefix, i);
            b.put(fn);
        }
    }
    RevTree fakenId = forceTreeId(b, treeId);
    if (!db.exists(fakenId.getId())) {
        db.put(fakenId);
    }
    if (!metadataId.isNull()) {
        RevFeatureType fakeType = new RevFeatureTypeImpl(metadataId, pointsType);
        if (!db.exists(fakeType.getId())) {
            db.put(fakeType);
        }
    }
    String name = NodeRef.nodeFromPath(path);
    String parent = NodeRef.parentPath(path);
    Envelope bounds = SpatialOps.boundsOf(fakenId);
    Node node = Node.create(name, treeId, metadataId, TYPE.TREE, bounds);
    return new NodeRef(node, parent, ObjectId.NULL);
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) RevFeatureTypeImpl(org.locationtech.geogig.api.RevFeatureTypeImpl) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) Envelope(com.vividsolutions.jts.geom.Envelope) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree)

Example 70 with RevTree

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

the class WriteBackTest method testSiblingsSingleLevel.

@Test
public void testSiblingsSingleLevel() {
    RevTreeBuilder ancestor = new RevTreeBuilder(odb);
    RevTree tree1 = new RevTreeBuilder(odb).put(blob("blob")).build();
    RevTree tree2 = new RevTreeBuilder(odb).put(blob("blob")).build();
    ObjectId newRootId1 = writeBack.setAncestor(ancestor).setChildPath("subtree1").setTree(tree1).call();
    ancestor = odb.getTree(newRootId1).builder(odb);
    ObjectId newRootId2 = writeBack.setAncestor(ancestor).setChildPath("subtree2").setTree(tree2).call();
    // created the intermediate tree node?
    DepthSearch depthSearch = new DepthSearch(odb);
    assertTrue(depthSearch.find(newRootId2, "subtree1").isPresent());
    assertTrue(depthSearch.find(newRootId2, "subtree2").isPresent());
    assertTrue(depthSearch.find(newRootId2, "subtree1/blob").isPresent());
    assertTrue(depthSearch.find(newRootId2, "subtree2/blob").isPresent());
}
Also used : DepthSearch(org.locationtech.geogig.repository.DepthSearch) ObjectId(org.locationtech.geogig.api.ObjectId) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

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