Search in sources :

Example 6 with PropertyDescriptor

use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.

the class ApplyPatchOpTest method testPartialApplication.

@Test
public void testPartialApplication() throws Exception {
    insert(points1, points2);
    Patch patch = new Patch();
    String pathRemove = NodeRef.appendChild(pointsName, points2.getIdentifier().getID());
    patch.addRemovedFeature(pathRemove, points2, RevFeatureTypeImpl.build(pointsType));
    String pathModify = 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(pathModify, map, RevFeatureTypeImpl.build(modifiedPointsType), RevFeatureTypeImpl.build(pointsType));
    patch.addModifiedFeature(featureDiff);
    Patch rejected = geogig.command(ApplyPatchOp.class).setPatch(patch).setApplyPartial(true).call();
    assertFalse(rejected.isEmpty());
    RevTree root = repo.workingTree().getTree();
    assertNotNull(root);
    Optional<Node> featureBlobId = findTreeChild(root, pathRemove);
    assertFalse(featureBlobId.isPresent());
    // now we take the rejected patch and apply it, and the new rejected should be identical to
    // it
    Patch newRejected = geogig.command(ApplyPatchOp.class).setPatch(rejected).setApplyPartial(true).call();
    assertEquals(rejected, newRejected);
}
Also used : FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) GenericAttributeDiffImpl(org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl) Node(org.locationtech.geogig.api.Node) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) ApplyPatchOp(org.locationtech.geogig.api.porcelain.ApplyPatchOp) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 7 with PropertyDescriptor

use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.

the class ApplyPatchOpTest method testModifiedFeatureDoesNotExists.

@Test
public void testModifiedFeatureDoesNotExists() throws Exception {
    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 featureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType), RevFeatureTypeImpl.build(pointsType));
    patch.addModifiedFeature(featureDiff);
    try {
        geogig.command(ApplyPatchOp.class).setPatch(patch).call();
        fail();
    } catch (CannotApplyPatchException e) {
        assertTrue(true);
    }
}
Also used : FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) GenericAttributeDiffImpl(org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) CannotApplyPatchException(org.locationtech.geogig.api.porcelain.CannotApplyPatchException) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) Test(org.junit.Test)

Example 8 with PropertyDescriptor

use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.

the class ApplyPatchOpTest method testModifyFeatureAttributeOutdatedPatch.

@Test
public void testModifyFeatureAttributeOutdatedPatch() throws Exception {
    insert(points1_modified);
    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);
    try {
        geogig.command(ApplyPatchOp.class).setPatch(patch).call();
        fail();
    } catch (CannotApplyPatchException e) {
        assertTrue(true);
    }
}
Also used : FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) GenericAttributeDiffImpl(org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) CannotApplyPatchException(org.locationtech.geogig.api.porcelain.CannotApplyPatchException) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) Test(org.junit.Test)

Example 9 with PropertyDescriptor

use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.

the class ApplyPatchOpTest method testRemoveFeatureAttributeOutdatedPatch.

@Test
public void testRemoveFeatureAttributeOutdatedPatch() throws Exception {
    insert(points1B_modified);
    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);
    try {
        geogig.command(ApplyPatchOp.class).setPatch(patch).call();
        fail();
    } catch (CannotApplyPatchException e) {
        assertTrue(true);
    }
}
Also used : FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) GenericAttributeDiffImpl(org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) CannotApplyPatchException(org.locationtech.geogig.api.porcelain.CannotApplyPatchException) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) Test(org.junit.Test)

Example 10 with PropertyDescriptor

use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.

the class GeogigSimpleFeature method buildAttNameToRevTypeIndex.

public static Map<String, Integer> buildAttNameToRevTypeIndex(RevFeatureType revType) {
    List<PropertyDescriptor> sortedDescriptors = revType.sortedDescriptors();
    Map<String, Integer> typeAttNameToRevTypeIndex = Maps.newHashMap();
    final GeometryDescriptor defaultGeometry = ((SimpleFeatureType) revType.type()).getGeometryDescriptor();
    for (int revFeatureIndex = 0; revFeatureIndex < sortedDescriptors.size(); revFeatureIndex++) {
        PropertyDescriptor prop = sortedDescriptors.get(revFeatureIndex);
        typeAttNameToRevTypeIndex.put(prop.getName().getLocalPart(), Integer.valueOf(revFeatureIndex));
        if (prop.equals(defaultGeometry)) {
            typeAttNameToRevTypeIndex.put(null, Integer.valueOf(revFeatureIndex));
        }
    }
    return typeAttNameToRevTypeIndex;
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Point(com.vividsolutions.jts.geom.Point)

Aggregations

PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)47 RevFeature (org.locationtech.geogig.api.RevFeature)24 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)23 Optional (com.google.common.base.Optional)18 AttributeDiff (org.locationtech.geogig.api.plumbing.diff.AttributeDiff)17 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)16 FeatureDiff (org.locationtech.geogig.api.plumbing.diff.FeatureDiff)15 Test (org.junit.Test)12 RevObject (org.locationtech.geogig.api.RevObject)12 GenericAttributeDiffImpl (org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl)11 NodeRef (org.locationtech.geogig.api.NodeRef)10 Patch (org.locationtech.geogig.api.plumbing.diff.Patch)10 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)9 ObjectId (org.locationtech.geogig.api.ObjectId)8 Entry (java.util.Map.Entry)7 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)6 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)6 GeometryType (org.opengis.feature.type.GeometryType)6 PropertyType (org.opengis.feature.type.PropertyType)6