From 3e0480afa1646152d344931c36739d5379feb50c Mon Sep 17 00:00:00 2001 From: jo-pol Date: Mon, 20 Jan 2025 11:17:33 +0100 Subject: [PATCH] rezip shape files with upper case extension --- .../edu/harvard/iq/dataverse/util/ShapefileHandler.java | 8 ++++++-- .../iq/dataverse/util/shapefile/ShapefileHandlerTest.java | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/util/ShapefileHandler.java b/src/main/java/edu/harvard/iq/dataverse/util/ShapefileHandler.java index 2b54f7a3bfe..345a2d3cccc 100644 --- a/src/main/java/edu/harvard/iq/dataverse/util/ShapefileHandler.java +++ b/src/main/java/edu/harvard/iq/dataverse/util/ShapefileHandler.java @@ -8,6 +8,7 @@ import java.util.Date; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import java.util.zip.ZipFile; import java.util.HashMap; import java.util.*; @@ -561,7 +562,7 @@ private boolean isShapefileExtension(String ext_name){ if (ext_name == null){ return false; } - return SHAPEFILE_ALL_EXTENSIONS.contains(ext_name); + return SHAPEFILE_ALL_EXTENSIONS.contains(ext_name.toLowerCase()); } /* Does a list of file extensions match those required for a shapefile set? @@ -570,7 +571,10 @@ private boolean doesListContainShapefileExtensions(List ext_list){ if (ext_list == null){ return false; } - return ext_list.containsAll(SHAPEFILE_MANDATORY_EXTENSIONS); + var lowerCaseExtensions = ext_list.stream() + .map(String::toLowerCase) + .toList(); + return lowerCaseExtensions.containsAll(SHAPEFILE_MANDATORY_EXTENSIONS); } diff --git a/src/test/java/edu/harvard/iq/dataverse/util/shapefile/ShapefileHandlerTest.java b/src/test/java/edu/harvard/iq/dataverse/util/shapefile/ShapefileHandlerTest.java index c4ee4547ed7..e69793c4d33 100644 --- a/src/test/java/edu/harvard/iq/dataverse/util/shapefile/ShapefileHandlerTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/util/shapefile/ShapefileHandlerTest.java @@ -183,7 +183,7 @@ public void testZippedTwoShapefiles() throws IOException{ msgt("(2) testZippedTwoShapefiles"); // Create files and put them in a .zip - List file_names = Arrays.asList("shape1.shp", "shape1.shx", "shape1.dbf", "shape1.prj", "shape1.fbn", "shape1.fbx", // 1st shapefile + List file_names = Arrays.asList("shape1.shp", "shape1.shx", "shape1.DBF", "shape1.prj", "shape1.fbn", "shape1.fbx", // 1st shapefile "shape2.shp", "shape2.shx", "shape2.dbf", "shape2.prj", // 2nd shapefile "shape2.txt", "shape2.pdf", "shape2", // single files, same basename as 2nd shapefile "README.MD", "shp_dictionary.xls", "notes" ); //, "prj"); // single files @@ -211,7 +211,7 @@ public void testZippedTwoShapefiles() throws IOException{ assertTrue(file_groups.containsKey("shape2"), "verify key existance of 'shape2'"); // Verify the values - assertEquals(file_groups.get("shape1"), Arrays.asList("shp", "shx", "dbf", "prj", "fbn", "fbx"), "verify value of key 'shape1'"); + assertEquals(file_groups.get("shape1"), Arrays.asList("shp", "shx", "DBF", "prj", "fbn", "fbx"), "verify value of key 'shape1'"); assertEquals(file_groups.get("shape2"), Arrays.asList("shp", "shx", "dbf", "prj", "txt", "pdf", ShapefileHandler.BLANK_EXTENSION), "verify value of key 'shape2'"); // Rezip/Reorder the files @@ -240,7 +240,7 @@ public void testZippedShapefileWithExtraFiles() throws IOException{ msgt("(3) testZippedShapefileWithExtraFiles"); // Create files and put them in a .zip - List file_names = Arrays.asList("shape1.shp", "shape1.shx", "shape1.dbf", "shape1.prj", "shape1.pdf", "shape1.cpg", "shape1." + SHP_XML_EXTENSION, "README.md", "shape_notes.txt"); + List file_names = Arrays.asList("shape1.shp", "shape1.shx", "shape1.dbf", "shape1.prj", "shape1.pdf", "shape1.cpg", "shape1." + SHP_XML_EXTENSION, "README.md", "shape_notes.txt"); File zipfile_obj = createAndZipFiles(file_names, "shape-plus.zip"); // Pass the .zip to the ShapefileHandler