From bbe4252bdccd2e497ad4dbefa7e7aef88ac82460 Mon Sep 17 00:00:00 2001 From: Bertil Chapuis Date: Fri, 27 Oct 2023 22:28:20 +0200 Subject: [PATCH] Make the replacement of tables optional --- .../baremaps/cli/database/ImportOsmPbf.java | 3 ++- .../baremaps/workflow/tasks/ImportOsmPbf.java | 22 +++++++++---------- .../baremaps/workflow/ObjectMapperTest.java | 2 +- .../baremaps/workflow/WorkflowTest.java | 2 +- .../workflow/tasks/ImportPbfTest.java | 2 +- basemap/workflow.js | 3 ++- daylight/workflow.js | 6 +++-- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/database/ImportOsmPbf.java b/baremaps-cli/src/main/java/org/apache/baremaps/cli/database/ImportOsmPbf.java index 71249f053..572476948 100644 --- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/database/ImportOsmPbf.java +++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/database/ImportOsmPbf.java @@ -50,7 +50,8 @@ public Integer call() throws Exception { new org.apache.baremaps.workflow.tasks.ImportOsmPbf( file.toAbsolutePath(), database, - srid).execute(new WorkflowContext()); + srid, + true).execute(new WorkflowContext()); return 0; } } diff --git a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportOsmPbf.java b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportOsmPbf.java index 14398fa3b..c8697fba4 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportOsmPbf.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportOsmPbf.java @@ -46,7 +46,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public record ImportOsmPbf(Path file, Object database, Integer databaseSrid) +public record ImportOsmPbf(Path file, Object database, Integer databaseSrid, Boolean replaceTables) implements Task { @@ -62,16 +62,16 @@ public void execute(WorkflowContext context) throws Exception { var wayRepository = new PostgresWayRepository(dataSource); var relationRepository = new PostgresRelationRepository(dataSource); - headerRepository.drop(); - nodeRepository.drop(); - wayRepository.drop(); - relationRepository.drop(); - - headerRepository.create(); - nodeRepository.create(); - wayRepository.create(); - relationRepository.create(); - + if (replaceTables) { + headerRepository.drop(); + nodeRepository.drop(); + wayRepository.drop(); + relationRepository.drop(); + headerRepository.create(); + nodeRepository.create(); + wayRepository.create(); + relationRepository.create(); + } var cacheDir = Files.createTempDirectory(Paths.get("."), "cache_"); DataMap coordinateMap; diff --git a/baremaps-core/src/test/java/org/apache/baremaps/workflow/ObjectMapperTest.java b/baremaps-core/src/test/java/org/apache/baremaps/workflow/ObjectMapperTest.java index 041f024ac..0b7ed9c05 100644 --- a/baremaps-core/src/test/java/org/apache/baremaps/workflow/ObjectMapperTest.java +++ b/baremaps-core/src/test/java/org/apache/baremaps/workflow/ObjectMapperTest.java @@ -43,7 +43,7 @@ public void test() throws IOException { new Step("import", List.of("download"), List.of(new ImportOsmPbf(Paths.get("liechtenstein-latest.osm.pbf"), "jdbc:postgresql://localhost:5432/baremaps?&user=baremaps&password=baremaps", - 3857))))); + 3857, true))))); var json = mapper.writeValueAsString(workflow1); assertTrue(json.contains(DownloadUrl.class.getSimpleName())); assertTrue(json.contains(ImportOsmPbf.class.getSimpleName())); diff --git a/baremaps-core/src/test/java/org/apache/baremaps/workflow/WorkflowTest.java b/baremaps-core/src/test/java/org/apache/baremaps/workflow/WorkflowTest.java index 408930b94..7591c2de0 100644 --- a/baremaps-core/src/test/java/org/apache/baremaps/workflow/WorkflowTest.java +++ b/baremaps-core/src/test/java/org/apache/baremaps/workflow/WorkflowTest.java @@ -104,7 +104,7 @@ void execute() { Paths.get("downloads/liechtenstein.osm.pbf")))), new Step("import-osmpbf", List.of("fetch-osmpbf"), List.of(new ImportOsmPbf(Paths.get("downloads/liechtenstein.osm.pbf"), jdbcUrl(), - 3857))), + 3857, true))), new Step("fetch-shapefile", List.of(), List.of(new DownloadUrl( "https://osmdata.openstreetmap.de/download/simplified-water-polygons-split-3857.zip", Paths.get("downloads/simplified-water-polygons-split-3857.zip")))), diff --git a/baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/ImportPbfTest.java b/baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/ImportPbfTest.java index 8750c2efc..4a913bc59 100644 --- a/baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/ImportPbfTest.java +++ b/baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/ImportPbfTest.java @@ -33,7 +33,7 @@ void execute() throws Exception { var file = TestFiles.resolve("data.osm.pbf"); var jdbcUrl = jdbcUrl(); var srid = 3857; - var task = new ImportOsmPbf(file, jdbcUrl, srid); + var task = new ImportOsmPbf(file, jdbcUrl, srid, true); task.execute(new WorkflowContext()); } } diff --git a/basemap/workflow.js b/basemap/workflow.js index be7c2e0fa..4b91c0a1d 100644 --- a/basemap/workflow.js +++ b/basemap/workflow.js @@ -130,7 +130,8 @@ export default { "type": "ImportOsmPbf", "file": "data/data.osm.pbf", "database": config.database, - "databaseSrid": 3857 + "databaseSrid": 3857, + "replaceTables": true, }, ] }, diff --git a/daylight/workflow.js b/daylight/workflow.js index 92b590480..08a5889be 100644 --- a/daylight/workflow.js +++ b/daylight/workflow.js @@ -27,7 +27,8 @@ export default { "type": "ImportOsmPbf", "file": "data/data.osm.pbf", "database": config.database, - "databaseSrid": 3857 + "databaseSrid": 3857, + "replaceTables": true, }, ] }, @@ -44,7 +45,8 @@ export default { "type": "ImportOsmPbf", "file": "data/buildings.osm.pbf", "database": config.database, - "databaseSrid": 3857 + "databaseSrid": 3857, + "replaceTables": false, }, ] },