use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.
the class ImportOpTest method testDeleteException.
@Test
public void testDeleteException() throws Exception {
WorkingTree workTree = mock(WorkingTree.class);
Context cmdl = mock(Context.class);
when(cmdl.workingTree()).thenReturn(workTree);
doThrow(new RuntimeException("Exception")).when(workTree).delete(any(String.class));
ImportOp importOp = new ImportOp();
importOp.setContext(cmdl);
importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
importOp.setAll(true);
exception.expect(GeoToolsOpException.class);
importOp.call();
}
use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.
the class OSMHistoryImport method importOsmHistory.
private void importOsmHistory(GeogigCLI cli, ConsoleReader console, HistoryDownloader downloader, @Nullable Envelope featureFilter) throws IOException {
Iterator<Changeset> changesets = downloader.fetchChangesets();
GeoGIG geogig = cli.getGeogig();
WorkingTree workingTree = geogig.getContext().workingTree();
while (changesets.hasNext()) {
Changeset changeset = changesets.next();
if (changeset.isOpen()) {
throw new CommandFailedException("Can't import past changeset " + changeset.getId() + " as it is still open.");
}
String desc = String.format("obtaining osm changeset %,d...", changeset.getId());
console.print(desc);
console.flush();
Optional<Iterator<Change>> opchanges = changeset.getChanges().get();
if (!opchanges.isPresent()) {
updateBranchChangeset(geogig, changeset.getId());
console.println(" does not apply.");
console.flush();
continue;
}
Iterator<Change> changes = opchanges.get();
console.print("applying...");
console.flush();
ObjectId workTreeId = workingTree.getTree().getId();
long changeCount = insertChanges(cli, changes, featureFilter);
console.print(String.format("Applied %,d changes, staging...", changeCount));
console.flush();
ObjectId afterTreeId = workingTree.getTree().getId();
DiffObjectCount diffCount = geogig.command(DiffCount.class).setOldVersion(workTreeId.toString()).setNewVersion(afterTreeId.toString()).call();
geogig.command(AddOp.class).call();
console.println(String.format("done. %,d changes actually applied.", diffCount.featureCount()));
console.flush();
commit(cli, changeset);
}
}
use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.
the class OSMUnmapOpTest method testMappingAndUnmappingOfNodesWithAlias.
@Test
public void testMappingAndUnmappingOfNodesWithAlias() throws Exception {
// Import
String filename = OSMImportOp.class.getResource("nodes.xml").getFile();
File file = new File(filename);
geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setMessage("msg").call();
// Map
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("geom", FieldType.POINT));
fields.put("name", new AttributeDefinition("name_alias", 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();
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();
assertEquals(3, values.size());
String wkt = "POINT (7.1959361 50.739397)";
assertEquals(wkt, values.get(2).get().toString());
assertEquals(507464799l, values.get(0).get());
// unmap without having made any changes and check that the canonical folders are not
// modified
geogig.command(OSMUnmapOp.class).setPath("busstops").call();
WorkingTree workTree = geogig.getRepository().workingTree();
long unstaged = workTree.countUnstaged("way").count();
assertEquals(0, unstaged);
unstaged = workTree.countUnstaged("node").count();
assertEquals(0, unstaged);
// Modify a node
GeometryFactory gf = new GeometryFactory();
SimpleFeatureBuilder fb = new SimpleFeatureBuilder((SimpleFeatureType) featureType.get().type());
fb.set("geom", gf.createPoint(new Coordinate(0, 1)));
fb.set("name_alias", "newname");
fb.set("id", 507464799l);
SimpleFeature newFeature = fb.buildFeature("507464799");
geogig.getRepository().workingTree().insert("busstops", newFeature);
// check that it was correctly inserted in the working tree
Optional<RevFeature> mapped = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:busstops/507464799").call(RevFeature.class);
assertTrue(mapped.isPresent());
values = mapped.get().getValues();
assertEquals("POINT (0 1)", values.get(2).get().toString());
assertEquals(507464799l, ((Long) values.get(0).get()).longValue());
assertEquals("newname", values.get(1).get().toString());
// unmap
geogig.command(OSMUnmapOp.class).setPath("busstops").call();
unstaged = workTree.countUnstaged("node").featureCount();
assertEquals(1, unstaged);
// check that the unmapped node has the changes we introduced
Optional<RevFeature> unmapped = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node/507464799").call(RevFeature.class);
assertTrue(unmapped.isPresent());
values = unmapped.get().getValues();
assertEquals("POINT (0 1)", values.get(6).get().toString());
assertEquals("bus:yes|public_transport:platform|highway:bus_stop|VRS:ortsteil:Hoholz|name:newname|VRS:ref:68566|VRS:gemeinde:BONN", values.get(3).get().toString());
// check that unchanged nodes keep their attributes
Optional<RevFeature> unchanged = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node/1633594723").call(RevFeature.class);
values = unchanged.get().getValues();
assertEquals("14220478", values.get(4).get().toString());
assertEquals("1355097351000", values.get(2).get().toString());
assertEquals("2", values.get(1).get().toString());
}
use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.
the class OSMMapOpTest method testMappingwithNoGeometry.
@Test
public void testMappingwithNoGeometry() throws Exception {
// Test that an exception is thrown when the mapping does not contain a geometry field
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 a wrong mapping without geometry
Map<String, AttributeDefinition> fields = Maps.newHashMap();
Map<String, List<String>> filters = Maps.newHashMap();
filters.put("oneway", Lists.newArrayList("yes"));
fields.put("lit", new AttributeDefinition("lit", FieldType.STRING));
Map<String, List<String>> filterExclude = Maps.newHashMap();
MappingRule mappingRule = new MappingRule("onewaystreets", filters, filterExclude, fields, null);
List<MappingRule> mappingRules = Lists.newArrayList();
mappingRules.add(mappingRule);
Mapping mapping = new Mapping(mappingRules);
// Try to create a mapping
try {
geogig.command(OSMMapOp.class).setMapping(mapping).call();
fail();
} catch (NullPointerException e) {
assertTrue(e.getMessage().startsWith("The mapping rule does not define a geometry field"));
}
}
use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.
the class OSMMapOpTest method testMappingNodes.
@Test
public void testMappingNodes() 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("geom", FieldType.POINT));
fields.put("name", new AttributeDefinition("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();
assertEquals(3, values.size());
String wkt = "POINT (7.1959361 50.739397)";
assertEquals(wkt, values.get(2).get().toString());
assertEquals(507464799l, values.get(0).get());
// Check that the corresponding log files have been added
File osmMapFolder = geogig.command(ResolveOSMMappingLogFolder.class).call();
file = new File(osmMapFolder, "busstops");
assertTrue(file.exists());
file = new File(osmMapFolder, geogig.getRepository().workingTree().getTree().getId().toString());
assertTrue(file.exists());
}
Aggregations