diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.cpg b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.cpg new file mode 100644 index 0000000000..3ad133c048 --- /dev/null +++ b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.cpg @@ -0,0 +1 @@ +UTF-8 \ No newline at end of file diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.dbf b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.dbf new file mode 100644 index 0000000000..9a272176cf Binary files /dev/null and b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.dbf differ diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.prj b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.prj new file mode 100644 index 0000000000..bd846aeb22 --- /dev/null +++ b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.prj @@ -0,0 +1 @@ +PROJCS["ETRS_1989_UTM_Zone_32N",GEOGCS["GCS_ETRS_1989",DATUM["D_ETRS_1989",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]] \ No newline at end of file diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.sbn b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.sbn new file mode 100644 index 0000000000..78f4fd9428 Binary files /dev/null and b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.sbn differ diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.sbx b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.sbx new file mode 100644 index 0000000000..5c9fea174c Binary files /dev/null and b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.sbx differ diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.shp b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.shp new file mode 100644 index 0000000000..86b7f39196 Binary files /dev/null and b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.shp differ diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.shx b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.shx new file mode 100644 index 0000000000..3e7fd191aa Binary files /dev/null and b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_fnpgelt.shx differ diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.cpg b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.cpg new file mode 100644 index 0000000000..3ad133c048 --- /dev/null +++ b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.cpg @@ -0,0 +1 @@ +UTF-8 \ No newline at end of file diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.dbf b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.dbf new file mode 100644 index 0000000000..9a272176cf Binary files /dev/null and b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.dbf differ diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.prj b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.prj new file mode 100644 index 0000000000..bd846aeb22 --- /dev/null +++ b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.prj @@ -0,0 +1 @@ +PROJCS["ETRS_1989_UTM_Zone_32N",GEOGCS["GCS_ETRS_1989",DATUM["D_ETRS_1989",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]] \ No newline at end of file diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.sbn b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.sbn new file mode 100644 index 0000000000..78f4fd9428 Binary files /dev/null and b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.sbn differ diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.sbx b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.sbx new file mode 100644 index 0000000000..5c9fea174c Binary files /dev/null and b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.sbx differ diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.shp b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.shp new file mode 100644 index 0000000000..86b7f39196 Binary files /dev/null and b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.shp differ diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.shx b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.shx new file mode 100644 index 0000000000..3e7fd191aa Binary files /dev/null and b/io/plugins/eu.esdihumboldt.hale.io.shp/resources/test/testdata/arokfnp/alt_name/result_ikg.shx differ diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/src/eu/esdihumboldt/hale/io/shp/reader/internal/ShapeInstanceReader.java b/io/plugins/eu.esdihumboldt.hale.io.shp/src/eu/esdihumboldt/hale/io/shp/reader/internal/ShapeInstanceReader.java index fe48bb8441..fa27fa2d8b 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.shp/src/eu/esdihumboldt/hale/io/shp/reader/internal/ShapeInstanceReader.java +++ b/io/plugins/eu.esdihumboldt.hale.io.shp/src/eu/esdihumboldt/hale/io/shp/reader/internal/ShapeInstanceReader.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.function.Function; import javax.xml.namespace.QName; @@ -242,15 +243,20 @@ public static Pair getMostCompatibleShapeType(TypeIndex TypeDefinition preferredType = types .getType(new QName(ShapefileConstants.SHAPEFILE_NS, preferredName)); if (allowNonShapefileTypes && preferredType == null) { - preferredType = types.getMappingRelevantTypes().stream() - .filter(t -> t.getName().getLocalPart().equals(preferredName)).findFirst() - .orElse(null); + preferredType = findPreferred(preferredName, findName -> { + return types.getMappingRelevantTypes().stream() + .filter(t -> t.getName().getLocalPart().equals(findName)).findFirst() + .orElse(null); + }); } if (allowNonShapefileTypes && preferredType == null) { - preferredType = types.getMappingRelevantTypes().stream() - // check displayname as well (e.g. in case of XSD where this - // represents the XML element) - .filter(t -> t.getDisplayName().equals(preferredName)).findFirst().orElse(null); + preferredType = findPreferred(preferredName, findName -> { + return types.getMappingRelevantTypes().stream() + // check displayname as well (e.g. in case of XSD where this + // represents the XML element) + .filter(t -> t.getDisplayName().equals(preferredName)).findFirst() + .orElse(null); + }); } if (preferredType != null) { int comp = checkCompatibility(preferredType, dataType, allowNonShapefileTypes); @@ -292,6 +298,23 @@ else if (maxCompatibility > 0 && comp == maxCompatibility) { return null; } + private static TypeDefinition findPreferred(String preferredName, + Function find) { + TypeDefinition result = find.apply(preferredName); + + if (result == null) { + // also allow for type w/o result_ prefix as the case for transformation results + // on hale-connect by default + String checkName = preferredName; + while (result == null && checkName.startsWith("result_")) { + checkName = checkName.substring("result_".length()); + result = find.apply(checkName); + } + } + + return result; + } + /** * Determines if the compatibility rating between the two Shapefile type * definitions. diff --git a/io/plugins/eu.esdihumboldt.hale.io.shp/test/eu/esdihumboldt/hale/io/shp/ShapeInstanceReaderTest.groovy b/io/plugins/eu.esdihumboldt.hale.io.shp/test/eu/esdihumboldt/hale/io/shp/ShapeInstanceReaderTest.groovy index fd971bb9ec..2de35fc7b8 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.shp/test/eu/esdihumboldt/hale/io/shp/ShapeInstanceReaderTest.groovy +++ b/io/plugins/eu.esdihumboldt.hale.io.shp/test/eu/esdihumboldt/hale/io/shp/ShapeInstanceReaderTest.groovy @@ -115,6 +115,48 @@ class ShapeInstanceReaderTest extends AbstractPlatformTest { validateArokFnpIkg(list, 'geometrie') } + /** + * Test reading Shapefile instances using an XML schema, type detection based on file name, but name has result_ prefix. + */ + @Test + void testReadXsdInstancesResultPrefix1() { + Schema xmlSchema = TestUtil.loadSchema(getClass().getClassLoader().getResource("testdata/arokfnp/arok-fnp.xsd").toURI()) + + InstanceCollection instances = loadInstances(xmlSchema, getClass().getClassLoader().getResource("testdata/arokfnp/alt_name/result_ikg.shp").toURI()) + + assertNotNull(instances) + List list = instances.toList() + + // test count + assertThat(list).hasSize(14) + + // instance validation + validateArokFnpIkg(list, 'geometrie') + } + + /** + * Test reading Shapefile instances using an XML schema, type detection based on file name, but name has result_ prefix. + */ + @CompileStatic(TypeCheckingMode.SKIP) // due to strange Groovy compile error on assertThat + @Test + void testReadXsdInstancesResultPrefix2() { + Schema xmlSchema = TestUtil.loadSchema(getClass().getClassLoader().getResource("testdata/arokfnp/arok-fnp.xsd").toURI()) + + InstanceCollection instances = loadInstances(xmlSchema, getClass().getClassLoader().getResource("testdata/arokfnp/alt_name/result_fnpgelt.shp").toURI()) + + assertNotNull(instances) + List list = instances.toList() + + // test count + assertThat(list).hasSize(14) + + // type validation + Set types = list.collect { it.definition.displayName }.toSet() + assertThat(types) + .hasSize(1) + .containsExactly('fnpgelt') + } + @CompileStatic(TypeCheckingMode.SKIP) private void validateArokFnpIkg(List instances, String geometryPropertyName) { Map> instancesByType = [:]