From f4c497c3890e607fb256443e93670edd0109c582 Mon Sep 17 00:00:00 2001 From: amercader Date: Tue, 17 Dec 2024 12:27:24 +0100 Subject: [PATCH] Fix parsing of spatial properties when using scheming Legacy `spatial_*` extras were not converted to the repeating subfield `spatial_coverage` --- ckanext/dcat/profiles/euro_dcat_ap_scheming.py | 8 +++++++- .../tests/profiles/dcat_ap_2/test_scheming_support.py | 6 ++++++ examples/dcat/dataset.rdf | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ckanext/dcat/profiles/euro_dcat_ap_scheming.py b/ckanext/dcat/profiles/euro_dcat_ap_scheming.py index b8402a65..3a2742a1 100644 --- a/ckanext/dcat/profiles/euro_dcat_ap_scheming.py +++ b/ckanext/dcat/profiles/euro_dcat_ap_scheming.py @@ -77,7 +77,10 @@ def _parse_list_value(data_dict, field_name): _parse_list_value(resource_dict, field_name) # Repeating subfields - new_fields_mapping = {"temporal_coverage": "temporal"} + new_fields_mapping = { + "spatial_coverage": "spatial", + "temporal_coverage": "temporal", + } for schema_field in self._dataset_schema["dataset_fields"]: if "repeating_subfields" in schema_field: # Check if existing extras need to be migrated @@ -94,6 +97,9 @@ def _parse_list_value(data_dict, field_name): new_dict[subfield] = extra["value"] else: new_extras.append(extra) + elif extra["key"] == "spatial" and field_name == "spatial_coverage": + # Special case, spatial geom + new_dict["geom"] = extra["value"] else: new_extras.append(extra) if new_dict: diff --git a/ckanext/dcat/tests/profiles/dcat_ap_2/test_scheming_support.py b/ckanext/dcat/tests/profiles/dcat_ap_2/test_scheming_support.py index de0c0866..27c6e770 100644 --- a/ckanext/dcat/tests/profiles/dcat_ap_2/test_scheming_support.py +++ b/ckanext/dcat/tests/profiles/dcat_ap_2/test_scheming_support.py @@ -741,6 +741,12 @@ def test_e2e_dcat_to_ckan(self): assert dataset["temporal_coverage"][0]["start"] == "1905-03-01" assert dataset["temporal_coverage"][0]["end"] == "2013-01-05" + assert ( + dataset["spatial_coverage"][0]["uri"] + == "http://publications.europa.eu/mdr/authority/country/ZWE" + ) + assert dataset["spatial_coverage"][0]["geom"] + resource = dataset["resources"][0] # Resources: core fields diff --git a/examples/dcat/dataset.rdf b/examples/dcat/dataset.rdf index ff280d9a..42f1ea5e 100644 --- a/examples/dcat/dataset.rdf +++ b/examples/dcat/dataset.rdf @@ -9,6 +9,7 @@ xmlns:adms="http://www.w3.org/ns/adms#" xmlns:schema="http://schema.org/" xmlns:vcard="http://www.w3.org/2006/vcard/ns#" + xmlns:locn="http://www.w3.org/ns/locn#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:spdx="http://spdx.org/rdf/terms#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" @@ -38,6 +39,11 @@ Standard 2 + + + POLYGON ((11.9936 54.0486, 11.9936 54.2466, 12.3045 54.2466, 12.3045 54.0486, 11.9936 54.0486)) + + 1.5 public