This is an automated email from the ASF dual-hosted git repository. bchapuis pushed a commit to branch workflow in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit 06a9f62ce0a7baf921fdebb2d8cd188724a6cad2 Author: Bertil Chapuis <[email protected]> AuthorDate: Fri Nov 17 16:52:54 2023 +0100 Remove UnzipFile task --- .../apache/baremaps/workflow/tasks/UnzipFile.java | 92 ---------------------- .../org/apache/baremaps/workflow/WorkflowTest.java | 19 ++--- .../workflow/tasks/ImportShapefileTest.java | 15 ++-- .../baremaps/workflow/tasks/UnzipFileTest.java | 40 ---------- 4 files changed, 16 insertions(+), 150 deletions(-) diff --git a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/UnzipFile.java b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/UnzipFile.java deleted file mode 100644 index 0804168b..00000000 --- a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/UnzipFile.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.baremaps.workflow.tasks; - -import com.fasterxml.jackson.annotation.JsonTypeName; -import java.io.*; -import java.nio.file.*; -import java.util.zip.ZipFile; -import org.apache.baremaps.workflow.Task; -import org.apache.baremaps.workflow.WorkflowContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Unzip a file. - */ -@JsonTypeName("UnzipFile") -public class UnzipFile implements Task { - - private static final Logger logger = LoggerFactory.getLogger(UnzipFile.class); - - private Path file; - private Path directory; - - /** - * Constructs an {@code UnzipFile}. - * - * @param file the file - * @param directory the directory - */ - public UnzipFile(Path file, Path directory) { - this.file = file; - this.directory = directory; - } - - /** - * {@inheritDoc} - */ - @Override - public void execute(WorkflowContext context) throws Exception { - var filePath = file.toAbsolutePath(); - var directoryPath = directory.toAbsolutePath(); - - try (var zipFile = new ZipFile(filePath.toFile())) { - var entries = zipFile.entries(); - - while (entries.hasMoreElements()) { - var ze = entries.nextElement(); - if (ze.isDirectory()) { - continue; - } - - var path = directoryPath.resolve(ze.getName()); - - var file = path.toFile().getCanonicalFile(); - var directory = directoryPath.toFile().getCanonicalFile(); - if (!file.toPath().startsWith(directory.toPath())) { - throw new IOException("Entry is outside of the target directory"); - } - - Files.createDirectories(path.getParent()); - Files.write(path, new byte[] {}, StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING); - - try (var input = new BufferedInputStream(zipFile.getInputStream(ze)); - var output = new BufferedOutputStream(new FileOutputStream(path.toFile()))) { - - int nBytes; - byte[] buffer = new byte[4096]; - while ((nBytes = input.read(buffer)) > 0) { - output.write(buffer, 0, nBytes); - } - } - } - } - } -} 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 c8ba01d8..6e7d220f 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 @@ -22,11 +22,8 @@ package org.apache.baremaps.workflow; import java.nio.file.Paths; import java.util.List; import org.apache.baremaps.testing.PostgresContainerTest; -import org.apache.baremaps.workflow.tasks.DownloadUrl; -import org.apache.baremaps.workflow.tasks.ImportGeoPackage; -import org.apache.baremaps.workflow.tasks.ImportOsmPbf; -import org.apache.baremaps.workflow.tasks.ImportShapefile; -import org.apache.baremaps.workflow.tasks.UnzipFile; +import org.apache.baremaps.workflow.tasks.*; +import org.apache.baremaps.workflow.tasks.DecompressFile.Compression; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -38,8 +35,8 @@ class WorkflowTest extends PostgresContainerTest { var workflow = new Workflow(List.of(new Step("fetch-geopackage", List.of(), List.of( new DownloadUrl("https://naciscdn.org/naturalearth/packages/natural_earth_vector.gpkg.zip", Paths.get("natural_earth_vector.gpkg.zip"), false), - new UnzipFile(Paths.get("natural_earth_vector.gpkg.zip"), - Paths.get("natural_earth_vector")), + new DecompressFile(Paths.get("natural_earth_vector.gpkg.zip"), + Paths.get("natural_earth_vector"), Compression.zip), new ImportGeoPackage(Paths.get("natural_earth_vector/packages/natural_earth_vector.gpkg"), jdbcUrl(), 4326, 3857))))); @@ -53,8 +50,8 @@ class WorkflowTest extends PostgresContainerTest { List.of( new DownloadUrl("https://osmdata.openstreetmap.de/download/coastlines-split-4326.zip", Paths.get("coastlines-split-4326.zip"), false), - new UnzipFile(Paths.get("coastlines-split-4326.zip"), - Paths.get("coastlines-split-4326")), + new DecompressFile(Paths.get("coastlines-split-4326.zip"), + Paths.get("coastlines-split-4326"), Compression.zip), new ImportShapefile(Paths.get("coastlines-split-4326/coastlines-split-4326/lines.shp"), jdbcUrl(), 4326, 3857))))); @@ -111,8 +108,8 @@ class WorkflowTest extends PostgresContainerTest { Paths.get("downloads/simplified-water-polygons-split-3857.zip"), false))), new Step("unzip-shapefile", List.of("fetch-shapefile"), List.of( - new UnzipFile(Paths.get("downloads/simplified-water-polygons-split-3857.zip"), - Paths.get("archives")))), + new DecompressFile(Paths.get("downloads/simplified-water-polygons-split-3857.zip"), + Paths.get("archives"), Compression.zip))), new Step("fetch-projection", List.of("unzip-shapefile"), List.of(new DownloadUrl("https://spatialreference.org/ref/sr-org/epsg3857/prj/", Paths.get( diff --git a/baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/ImportShapefileTest.java b/baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/ImportShapefileTest.java index d611efb0..1f63b986 100644 --- a/baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/ImportShapefileTest.java +++ b/baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/ImportShapefileTest.java @@ -24,6 +24,7 @@ import org.apache.baremaps.testing.PostgresContainerTest; import org.apache.baremaps.testing.TestFiles; import org.apache.baremaps.utils.FileUtils; import org.apache.baremaps.workflow.WorkflowContext; +import org.apache.baremaps.workflow.tasks.DecompressFile.Compression; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -32,13 +33,13 @@ class ImportShapefileTest extends PostgresContainerTest { @Test @Tag("integration") void execute() throws Exception { - var zip = TestFiles.resolve("monaco-shapefile.zip"); - var directory = Files.createTempDirectory("tmp_"); - var unzip = new UnzipFile(zip, directory); - unzip.execute(new WorkflowContext()); - var task = new ImportShapefile(directory.resolve("gis_osm_buildings_a_free_1.shp"), + var source = TestFiles.resolve("monaco-shapefile.zip"); + var target = Files.createTempDirectory("tmp_"); + var decompressFile = new DecompressFile(source, target, Compression.zip); + decompressFile.execute(new WorkflowContext()); + var importShapefile = new ImportShapefile(target.resolve("gis_osm_buildings_a_free_1.shp"), jdbcUrl(), 4326, 3857); - task.execute(new WorkflowContext()); - FileUtils.deleteRecursively(directory); + importShapefile.execute(new WorkflowContext()); + FileUtils.deleteRecursively(target); } } diff --git a/baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/UnzipFileTest.java b/baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/UnzipFileTest.java deleted file mode 100644 index a9350139..00000000 --- a/baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/UnzipFileTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.baremaps.workflow.tasks; - - - -import java.nio.file.Files; -import org.apache.baremaps.testing.TestFiles; -import org.apache.baremaps.utils.FileUtils; -import org.apache.baremaps.workflow.WorkflowContext; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -class UnzipFileTest { - - @Test - @Tag("integration") - void execute() throws Exception { - var zip = TestFiles.resolve("monaco-shapefile.zip"); - var directory = Files.createTempDirectory("tmp_"); - var task = new UnzipFile(zip, directory); - task.execute(new WorkflowContext()); - FileUtils.deleteRecursively(directory); - } -}
