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);
}
}
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());
}
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
}
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());
}
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());
}
Aggregations