Search in sources :

Example 46 with RevTreeBuilder

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

the class DiffTreeTest method testMixedFilters.

/**
     * Apply path, bounds, and changeType filtering all at once
     */
@Test
public void testMixedFilters() {
    ObjectDatabase db = geogit.getContext().objectDatabase();
    final RevTree tree1 = tree(1000, db);
    final RevTree tree2 = tree(50, db);
    final RevTree tree2Changed;
    {
        RevTreeBuilder builder = new RevTreeBuilder(db, tree2);
        // add 10 changed features, and delete 10 more
        for (int i = 0; i < 20; i++) {
            if (i % 2 == 0) {
                builder.remove(String.valueOf(i));
            } else {
                builder.put(feature(i, ObjectId.forString("changed" + i)));
            }
        }
        tree2Changed = builder.build();
        db.put(tree2Changed);
        assertEquals(tree2.size() - 10, tree2Changed.size());
    }
    final RevTree root1 = createRoot(db, tree1, tree2);
    final RevTree root2 = createRoot(db, tree1, tree2Changed);
    final ObjectId rootId1 = root1.getId();
    final ObjectId rootId2 = root2.getId();
    CoordinateReferenceSystem crs = revtype.type().getCoordinateReferenceSystem();
    // boundsFilter covers features 1-11
    ReferencedEnvelope boundsFilter = new ReferencedEnvelope(1.9, 11.1, 1.9, 11.1, crs);
    // first try with bounds only
    diffTree.setBoundsFilter(boundsFilter);
    assertEquals(10, Iterators.size(diffTree.setOldTree(rootId1).setNewTree(rootId2).call()));
    assertChangeTypeFilter(rootId1, rootId2, 0, 5, 5);
    assertChangeTypeFilter(rootId2, rootId1, 5, 0, 5);
    // now add path filtering
    diffTree.setPathFilter("tree1");
    assertChangeTypeFilter(rootId1, rootId2, 0, 0, 0);
    assertChangeTypeFilter(rootId2, rootId1, 0, 0, 0);
    diffTree.setPathFilter("tree2");
    assertChangeTypeFilter(rootId1, rootId2, 0, 5, 5);
    assertChangeTypeFilter(rootId2, rootId1, 5, 0, 5);
    // odd feature ids from 0 to 18 were removed from tree2
    // tree2/0 and tree2/12 match path filter but don't match bounds filter
    diffTree.setPathFilter(ImmutableList.of("tree2/0", "tree2/2", "tree2/4", "tree2/12"));
    diffTree.setBoundsFilter(null);
    assertChangeTypeFilter(rootId1, rootId2, 0, 4, 0);
    assertChangeTypeFilter(rootId2, rootId1, 4, 0, 0);
    diffTree.setBoundsFilter(boundsFilter);
    assertChangeTypeFilter(rootId1, rootId2, 0, 2, 0);
    assertChangeTypeFilter(rootId2, rootId1, 2, 0, 0);
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) ObjectId(org.locationtech.geogig.api.ObjectId) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 47 with RevTreeBuilder

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

the class DiffTreeTest method createRoot.

private RevTree createRoot(ObjectDatabase db, final RevTree tree1, final RevTree tree2) {
    RevTreeBuilder rootBuilder = new RevTreeBuilder(db);
    rootBuilder.put(Node.create("tree1", tree1.getId(), metadataId, TYPE.TREE, SpatialOps.boundsOf(tree1)));
    rootBuilder.put(Node.create("tree2", tree2.getId(), metadataId, TYPE.TREE, SpatialOps.boundsOf(tree2)));
    RevTree root = rootBuilder.build();
    db.put(root);
    return root;
}
Also used : RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree)

Example 48 with RevTreeBuilder

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

the class WriteBackTest method testSimple.

@Test
public void testSimple() {
    RevTreeBuilder oldRoot = new RevTreeBuilder(odb);
    RevTree tree = new RevTreeBuilder(odb).put(blob("blob")).build();
    ObjectId newRootId = writeBack.setAncestor(oldRoot).setChildPath("subtree").setTree(tree).call();
    Optional<NodeRef> ref = new DepthSearch(odb).find(newRootId, "subtree");
    assertTrue(ref.isPresent());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) 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)

Example 49 with RevTreeBuilder

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

the class WriteBackTest method testSingleNested.

@Test
public void testSingleNested() {
    RevTreeBuilder oldRoot = new RevTreeBuilder(odb);
    RevTree tree = new RevTreeBuilder(odb).put(blob("blob")).build();
    ObjectId newRootId = writeBack.setAncestor(oldRoot).setChildPath("level1/level2").setTree(tree).call();
    // created the intermediate tree node?
    Optional<NodeRef> ref;
    DepthSearch depthSearch = new DepthSearch(odb);
    ref = depthSearch.find(newRootId, "level1");
    assertTrue(ref.isPresent());
    ref = depthSearch.find(newRootId, "level1/level2");
    assertTrue(ref.isPresent());
    ref = depthSearch.find(newRootId, "level1/level2/blob");
    assertTrue(ref.isPresent());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) 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)

Example 50 with RevTreeBuilder

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

the class WriteBackTest method testSingleLevel.

@Test
public void testSingleLevel() {
    RevTreeBuilder oldRoot = new RevTreeBuilder(odb);
    RevTree tree = new RevTreeBuilder(odb).put(blob("blob")).build();
    ObjectId newRootId = writeBack.setAncestor(oldRoot).setChildPath("level1").setTree(tree).call();
    // created the intermediate tree node?
    Optional<NodeRef> ref;
    DepthSearch depthSearch = new DepthSearch(odb);
    ref = depthSearch.find(newRootId, "level1");
    assertTrue(ref.isPresent());
    ref = depthSearch.find(newRootId, "level1/blob");
    assertTrue(ref.isPresent());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) 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

RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)58 RevTree (org.locationtech.geogig.api.RevTree)47 ObjectId (org.locationtech.geogig.api.ObjectId)27 Test (org.junit.Test)25 NodeRef (org.locationtech.geogig.api.NodeRef)24 Node (org.locationtech.geogig.api.Node)14 DepthSearch (org.locationtech.geogig.repository.DepthSearch)6 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)5 Stopwatch (com.google.common.base.Stopwatch)4 Envelope (com.vividsolutions.jts.geom.Envelope)4 Map (java.util.Map)4 Context (org.locationtech.geogig.api.Context)4 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)4 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)4 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)4 Before (org.junit.Before)3 FindOrCreateSubtree (org.locationtech.geogig.api.plumbing.FindOrCreateSubtree)3 WriteBack (org.locationtech.geogig.api.plumbing.WriteBack)3 DepthTreeIterator (org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator)3 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)3