Search in sources :

Example 1 with Feature

use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.

the class MergeOpTest method testMergeConflictingBranches.

@Test
public void testMergeConflictingBranches() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - Points 1,2 added
    // |\
    // | o - TestBranch - Points 1 modified, 2 removed, 3 added
    // |
    // o - master - HEAD - Points 1 modifiedB, 2 removed
    insertAndAdd(points1, points2);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("TestBranch").call();
    Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
    insert(points1Modified);
    delete(points2);
    insert(points3);
    geogig.command(AddOp.class).call();
    RevCommit masterCommit = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("TestBranch").call();
    Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
    insert(points1ModifiedB);
    delete(points2);
    geogig.command(AddOp.class).call();
    RevCommit branchCommit = geogig.command(CommitOp.class).call();
    // Now try to merge branch into master
    geogig.command(CheckoutOp.class).setSource("master").call();
    Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
    try {
        geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).call();
        fail();
    } catch (MergeConflictsException e) {
        assertTrue(e.getMessage().contains("conflict"));
    }
    Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
    assertTrue(ref.isPresent());
    assertEquals(masterCommit.getId(), ref.get().getObjectId());
    ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
    assertTrue(ref.isPresent());
    assertEquals(branch.getObjectId(), ref.get().getObjectId());
    String msg = geogig.command(ReadMergeCommitMessageOp.class).call();
    assertFalse(Strings.isNullOrEmpty(msg));
    List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
    assertEquals(1, conflicts.size());
    String path = NodeRef.appendChild(pointsName, idP1);
    assertEquals(conflicts.get(0).getPath(), path);
    assertEquals(conflicts.get(0).getOurs(), RevFeatureBuilder.build(points1Modified).getId());
    assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1ModifiedB).getId());
    // try to commit
    try {
        geogig.command(CommitOp.class).call();
        fail();
    } catch (IllegalStateException e) {
        assertEquals(e.getMessage(), "Cannot run operation while merge conflicts exist.");
    }
    // solve, and commit
    Feature points1Merged = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
    insert(points1Merged);
    geogig.command(AddOp.class).call();
    RevCommit commit = geogig.command(CommitOp.class).call();
    assertTrue(commit.getMessage().contains(idP1));
    List<ObjectId> parents = commit.getParentIds();
    assertEquals(2, parents.size());
    assertEquals(masterCommit.getId(), parents.get(0));
    assertEquals(branchCommit.getId(), parents.get(1));
    Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(revFeature.isPresent());
    assertEquals(RevFeatureBuilder.build(points1Merged), revFeature.get());
    path = NodeRef.appendChild(pointsName, idP2);
    revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertFalse(revFeature.isPresent());
    path = NodeRef.appendChild(pointsName, idP3);
    revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(revFeature.isPresent());
    ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
    assertFalse(ref.isPresent());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) ObjectId(org.locationtech.geogig.api.ObjectId) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) MergeConflictsException(org.locationtech.geogig.api.porcelain.MergeConflictsException) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) RevFeature(org.locationtech.geogig.api.RevFeature) RefParse(org.locationtech.geogig.api.plumbing.RefParse) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) ReadMergeCommitMessageOp(org.locationtech.geogig.api.plumbing.merge.ReadMergeCommitMessageOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 2 with Feature

use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.

the class MergeOpTest method testOursAndTheirs.

@Test
public void testOursAndTheirs() throws Exception {
    insertAndAdd(points1);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("TestBranch").call();
    Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
    insertAndAdd(points1Modified);
    geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("TestBranch").call();
    Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
    insertAndAdd(points1ModifiedB);
    geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("master").call();
    Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
    try {
        geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).setTheirs(true).setOurs(true).call();
        fail();
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    }
}
Also used : UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) RefParse(org.locationtech.geogig.api.plumbing.RefParse) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Example 3 with Feature

use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.

the class MergeOpTest method testMergeWithPolygonAutoMerge.

@Test
public void testMergeWithPolygonAutoMerge() throws Exception {
    String polyId = "polyId";
    String polygonTypeSpec = "poly:Polygon:srid=4326";
    SimpleFeatureType polygonType = DataUtilities.createType("http://geogig.polygon", "polygons", polygonTypeSpec);
    Feature polygonOriginal = feature(polygonType, polyId, "POLYGON((0 0,1 0,2 0,3 0,4 0,5 0,5 1,4 1,3 1,2 1,1 1,1 0,0 0))");
    insertAndAdd(polygonOriginal);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("TestBranch").call();
    Feature polygonMaster = feature(polygonType, polyId, "POLYGON((0 0,1 0,2 0.2,3 0.2,4 0,5 0,5 1,4 1,3 1,2 1,1 1,1 0,0 0))");
    insertAndAdd(polygonMaster);
    geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("TestBranch").call();
    Feature polygonBranch = feature(polygonType, polyId, "POLYGON((0 0,1 0,2 0,3 0,4 0,5 0,5 1,4 1,3 0.8,2 0.8,1 1,1 0,0 0))");
    insertAndAdd(polygonBranch);
    geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("master").call();
    Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
    geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).call();
    Optional<RevFeature> feature = repo.command(RevObjectParse.class).setRefSpec("WORK_HEAD:polygons/polyId").call(RevFeature.class);
    assertTrue(feature.isPresent());
    RevFeature merged = feature.get();
    Feature expected = feature(polygonType, polyId, "POLYGON((0 0,1 0,2 0.2,3 0.2,4 0,5 0,5 1,4 1,3 0.8,2 0.8,1 1,1 0,0 0))");
    assertEquals(expected.getProperty("poly").getValue(), merged.getValues().get(0).get());
}
Also used : UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) RevFeature(org.locationtech.geogig.api.RevFeature) RefParse(org.locationtech.geogig.api.plumbing.RefParse) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Example 4 with Feature

use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.

the class MergeOpTest method testOctopusMergeWithAutomerge.

@Test
public void testOctopusMergeWithAutomerge() throws Exception {
    insertAndAdd(points1);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("branch1").call();
    geogig.command(BranchCreateOp.class).setName("branch2").call();
    geogig.command(BranchCreateOp.class).setName("branch3").call();
    geogig.command(BranchCreateOp.class).setName("branch4").call();
    geogig.command(BranchCreateOp.class).setName("branch5").call();
    geogig.command(BranchCreateOp.class).setName("branch6").call();
    Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
    insertAndAdd(points1Modified);
    geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch1").call();
    insertAndAdd(points2);
    RevCommit branch1 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch2").call();
    insertAndAdd(points3);
    RevCommit branch2 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch3").call();
    insertAndAdd(lines1);
    RevCommit branch3 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch4").call();
    insertAndAdd(lines2);
    RevCommit branch4 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch5").call();
    insertAndAdd(lines3);
    RevCommit branch5 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch6").call();
    Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
    insertAndAdd(points1ModifiedB);
    RevCommit branch6 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("master").call();
    MergeOp mergeOp = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getId())).addCommit(Suppliers.ofInstance(branch2.getId())).addCommit(Suppliers.ofInstance(branch3.getId())).addCommit(Suppliers.ofInstance(branch4.getId())).addCommit(Suppliers.ofInstance(branch5.getId())).addCommit(Suppliers.ofInstance(branch6.getId()));
    try {
        mergeOp.call();
        fail();
    } catch (IllegalStateException e) {
        assertTrue(e.getMessage().contains("Cannot merge more than two commits when conflicts exist"));
    }
}
Also used : MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 5 with Feature

use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.

the class GeogigAPITest method testGetFeatureFromHead.

@Test
public void testGetFeatureFromHead() throws Exception {
    insertAndAdd(points1);
    geogig.command(CommitOp.class).setMessage("Commit message").call();
    Feature feature = geogigAPI.getFeatureFromHead(NodeRef.appendChild(pointsName, idP1));
    assertNotNull(feature);
}
Also used : Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Aggregations

Feature (org.opengis.feature.Feature)128 Test (org.junit.Test)90 RevCommit (org.locationtech.geogig.api.RevCommit)52 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)43 SimpleFeature (org.opengis.feature.simple.SimpleFeature)38 ObjectId (org.locationtech.geogig.api.ObjectId)35 RevFeature (org.locationtech.geogig.api.RevFeature)32 NodeRef (org.locationtech.geogig.api.NodeRef)29 LinkedList (java.util.LinkedList)27 LogOp (org.locationtech.geogig.api.porcelain.LogOp)23 Ref (org.locationtech.geogig.api.Ref)21 RefParse (org.locationtech.geogig.api.plumbing.RefParse)19 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)18 ArrayList (java.util.ArrayList)16 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)16 RevObject (org.locationtech.geogig.api.RevObject)16 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)14 Function (com.google.common.base.Function)13 Optional (com.google.common.base.Optional)12 HashMap (java.util.HashMap)12