Search in sources :

Example 26 with PropertyDescriptor

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

the class ApplyPatchOpTest method testAddFeatureAttributeOutdatedPatch.

@Test
public void testAddFeatureAttributeOutdatedPatch() throws Exception {
    insert(points1B);
    Patch patch = new Patch();
    String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
    Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
    Optional<?> newValue = Optional.fromNullable(points1B.getProperty("extra").getValue());
    GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(null, newValue);
    map.put(modifiedPointsType.getDescriptor("extra"), diff);
    FeatureDiff featureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(modifiedPointsType), RevFeatureTypeImpl.build(modifiedPointsType));
    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 27 with PropertyDescriptor

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

the class ApplyPatchOpTest method testModifyFeatureAttributePatch.

@Test
public void testModifyFeatureAttributePatch() throws Exception {
    insert(points1);
    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);
    geogig.command(ApplyPatchOp.class).setPatch(patch).call();
    RevTree root = repo.workingTree().getTree();
    Optional<Node> featureBlobId = findTreeChild(root, path);
    assertTrue(featureBlobId.isPresent());
    Iterator<DiffEntry> unstaged = repo.workingTree().getUnstaged(pointsName);
    ArrayList<DiffEntry> diffs = Lists.newArrayList(unstaged);
    assertEquals(2, diffs.size());
    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("new", values.get(0).get());
}
Also used : PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) 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) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 28 with PropertyDescriptor

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

the class ApplyPatchOpTest method testAddFeatureAttributePatch.

@Test
public void testAddFeatureAttributePatch() throws Exception {
    insert(points1);
    Patch patch = new Patch();
    String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
    Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
    Optional<?> newValue = Optional.fromNullable(points1B.getProperty("extra").getValue());
    GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(null, newValue);
    map.put(modifiedPointsType.getDescriptor("extra"), diff);
    FeatureDiff featureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType), RevFeatureTypeImpl.build(modifiedPointsType));
    patch.addModifiedFeature(featureDiff);
    geogig.command(ApplyPatchOp.class).setPatch(patch).call();
// TODO
}
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) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) Test(org.junit.Test)

Example 29 with PropertyDescriptor

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

the class OSMMapOpTest method testMappingNodesWithAlias.

@Test
public void testMappingNodesWithAlias() throws Exception {
    // import and check that we have nodes
    String filename = OSMImportOp.class.getResource("nodes.xml").getFile();
    File file = new File(filename);
    geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
    WorkingTree workTree = geogig.getRepository().workingTree();
    long unstaged = workTree.countUnstaged("node").count();
    assertTrue(unstaged > 0);
    geogig.command(AddOp.class).call();
    geogig.command(CommitOp.class).setMessage("msg").call();
    // Define mapping
    Map<String, AttributeDefinition> fields = Maps.newHashMap();
    Map<String, List<String>> mappings = Maps.newHashMap();
    mappings.put("highway", Lists.newArrayList("bus_stop"));
    fields.put("geom", new AttributeDefinition("the_geometry", FieldType.POINT));
    fields.put("name", new AttributeDefinition("the_name", FieldType.STRING));
    Map<String, List<String>> filterExclude = Maps.newHashMap();
    MappingRule mappingRule = new MappingRule("busstops", mappings, filterExclude, fields, null);
    List<MappingRule> mappingRules = Lists.newArrayList();
    mappingRules.add(mappingRule);
    Mapping mapping = new Mapping(mappingRules);
    geogig.command(OSMMapOp.class).setMapping(mapping).call();
    // Check that mapping was correctly performed
    Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec("HEAD:busstops/507464799").call(RevFeature.class);
    assertTrue(revFeature.isPresent());
    Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class).setRefSpec("HEAD:busstops/507464799").call();
    assertTrue(featureType.isPresent());
    ImmutableList<Optional<Object>> values = revFeature.get().getValues();
    ImmutableList<PropertyDescriptor> descriptors = featureType.get().sortedDescriptors();
    assertEquals("the_name", descriptors.get(1).getName().getLocalPart());
    assertEquals("Gielgen", values.get(1).get());
    assertEquals("the_geometry", descriptors.get(2).getName().getLocalPart());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) Optional(com.google.common.base.Optional) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) WorkingTree(org.locationtech.geogig.repository.WorkingTree) RevFeature(org.locationtech.geogig.api.RevFeature) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) File(java.io.File) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Example 30 with PropertyDescriptor

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

the class OSMMapOpTest method testMappingDefaultFields.

@Test
public void testMappingDefaultFields() throws Exception {
    // import and check that we have both ways and nodes
    String filename = OSMImportOp.class.getResource("ways.xml").getFile();
    File file = new File(filename);
    geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
    WorkingTree workTree = geogig.getRepository().workingTree();
    long unstaged = workTree.countUnstaged("way").count();
    assertTrue(unstaged > 0);
    unstaged = workTree.countUnstaged("node").count();
    assertTrue(unstaged > 0);
    geogig.command(AddOp.class).call();
    geogig.command(CommitOp.class).setMessage("msg").call();
    // Define mapping
    Map<String, AttributeDefinition> fields = Maps.newHashMap();
    Map<String, List<String>> filter = Maps.newHashMap();
    filter.put("oneway", Lists.newArrayList("yes"));
    fields.put("geom", new AttributeDefinition("geom", FieldType.LINESTRING));
    fields.put("lit", new AttributeDefinition("lit", FieldType.STRING));
    ArrayList<DefaultField> defaultFields = Lists.newArrayList();
    defaultFields.add(DefaultField.timestamp);
    defaultFields.add(DefaultField.visible);
    MappingRule mappingRule = new MappingRule("onewaystreets", filter, null, fields, defaultFields);
    List<MappingRule> mappingRules = Lists.newArrayList();
    mappingRules.add(mappingRule);
    Mapping mapping = new Mapping(mappingRules);
    geogig.command(OSMMapOp.class).setMapping(mapping).call();
    // Check that mapping was correctly performed
    Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec("HEAD:onewaystreets/31045880").call(RevFeature.class);
    assertTrue(revFeature.isPresent());
    ImmutableList<Optional<Object>> values = revFeature.get().getValues();
    assertEquals(6, values.size());
    String wkt = "LINESTRING (7.1923367 50.7395887, 7.1923127 50.7396946, 7.1923444 50.7397419, 7.1924199 50.7397781)";
    assertEquals(wkt, values.get(4).get().toString());
    assertEquals("yes", values.get(3).get());
    assertEquals(true, values.get(2).get());
    assertEquals(1318750940000L, values.get(1).get());
    Optional<RevFeatureType> revFeatureType = geogig.command(ResolveFeatureType.class).setRefSpec("HEAD:onewaystreets/31045880").call();
    assertTrue(revFeatureType.isPresent());
    ImmutableList<PropertyDescriptor> descriptors = revFeatureType.get().sortedDescriptors();
    assertEquals("timestamp", descriptors.get(1).getName().toString());
    assertEquals("visible", descriptors.get(2).getName().toString());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) Optional(com.google.common.base.Optional) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) WorkingTree(org.locationtech.geogig.repository.WorkingTree) RevFeature(org.locationtech.geogig.api.RevFeature) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DefaultField(org.locationtech.geogig.osm.internal.MappingRule.DefaultField) File(java.io.File) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

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