Search in sources :

Example 16 with AttributeDiff

use of org.locationtech.geogig.api.plumbing.diff.AttributeDiff in project GeoGig by boundlessgeo.

the class ApplyPatchOpTest method testReversedPatch.

@Test
public void testReversedPatch() throws Exception {
    insert(points1, points2);
    Patch patch = new Patch();
    String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
    Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
    Optional<?> oldValue = Optional.fromNullable(points1.getProperty("sp").getValue());
    GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, Optional.of("new"));
    map.put(pointsType.getDescriptor("sp"), diff);
    FeatureDiff feaureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType), RevFeatureTypeImpl.build(pointsType));
    patch.addModifiedFeature(feaureDiff);
    String removedPath = NodeRef.appendChild(pointsName, points2.getIdentifier().getID());
    patch.addRemovedFeature(removedPath, points2, RevFeatureTypeImpl.build(pointsType));
    String addedPath = NodeRef.appendChild(pointsName, points3.getIdentifier().getID());
    patch.addAddedFeature(addedPath, points3, RevFeatureTypeImpl.build(pointsType));
    geogig.command(ApplyPatchOp.class).setPatch(patch).call();
    geogig.command(ApplyPatchOp.class).setPatch(patch.reversed()).call();
    RevTree root = repo.workingTree().getTree();
    Optional<Node> featureBlobId = findTreeChild(root, removedPath);
    assertTrue(featureBlobId.isPresent());
    featureBlobId = findTreeChild(root, addedPath);
    assertFalse(featureBlobId.isPresent());
    Optional<RevFeature> feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:" + path).call(RevFeature.class);
    assertTrue(feature.isPresent());
    assertEquals(oldValue, feature.get().getValues().get(0));
}
Also used : PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) GenericAttributeDiffImpl(org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl) Node(org.locationtech.geogig.api.Node) FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) RevFeature(org.locationtech.geogig.api.RevFeature) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 17 with AttributeDiff

use of org.locationtech.geogig.api.plumbing.diff.AttributeDiff in project GeoGig by boundlessgeo.

the class ApplyPatchOpTest method testRemoveFeatureAttributePatch.

@Test
public void testRemoveFeatureAttributePatch() throws Exception {
    insert(points1B);
    Patch patch = new Patch();
    String path = NodeRef.appendChild(pointsName, points1B.getIdentifier().getID());
    Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
    Optional<?> oldValue = Optional.fromNullable(points1B.getProperty("extra").getValue());
    GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, null);
    map.put(modifiedPointsType.getDescriptor("extra"), diff);
    FeatureDiff featureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(modifiedPointsType), RevFeatureTypeImpl.build(pointsType));
    patch.addModifiedFeature(featureDiff);
    geogig.command(ApplyPatchOp.class).setPatch(patch).call();
    Optional<RevFeature> feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:" + path).call(RevFeature.class);
    assertTrue(feature.isPresent());
    ImmutableList<Optional<Object>> values = feature.get().getValues();
    assertEquals(points1.getProperties().size(), values.size());
    assertFalse(values.contains("ExtraString"));
}
Also used : FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) GenericAttributeDiffImpl(org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl) RevFeature(org.locationtech.geogig.api.RevFeature) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) Test(org.junit.Test)

Aggregations

AttributeDiff (org.locationtech.geogig.api.plumbing.diff.AttributeDiff)17 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)17 FeatureDiff (org.locationtech.geogig.api.plumbing.diff.FeatureDiff)15 GenericAttributeDiffImpl (org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl)11 Patch (org.locationtech.geogig.api.plumbing.diff.Patch)10 Test (org.junit.Test)9 RevFeature (org.locationtech.geogig.api.RevFeature)8 Optional (com.google.common.base.Optional)5 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)5 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)5 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)5 Entry (java.util.Map.Entry)4 NodeRef (org.locationtech.geogig.api.NodeRef)4 CannotApplyPatchException (org.locationtech.geogig.api.porcelain.CannotApplyPatchException)4 Node (org.locationtech.geogig.api.Node)3 ObjectId (org.locationtech.geogig.api.ObjectId)3 RevObject (org.locationtech.geogig.api.RevObject)3 RevTree (org.locationtech.geogig.api.RevTree)3 DiffFeature (org.locationtech.geogig.api.plumbing.DiffFeature)3 TYPE (org.locationtech.geogig.api.RevObject.TYPE)2