From 9ef0da2abe2d520f5f6ef25a4ddd7b1fd6513ea8 Mon Sep 17 00:00:00 2001
From: Jesper Zedlitz <jesper@zedlitz.de>
Date: Thu, 2 Jan 2025 08:21:26 +0100
Subject: [PATCH] =?UTF-8?q?=C3=9Cbertragung=20der=20Property=20politicalGe?=
 =?UTF-8?q?ocodingURI=20nach=20spatial=5Furi,=20falls=20eine=20spatial=5Fu?=
 =?UTF-8?q?ri=20fehlt.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ckanext/odsh/profiles/odsh_dcat_de_profile.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/ckanext/odsh/profiles/odsh_dcat_de_profile.py b/ckanext/odsh/profiles/odsh_dcat_de_profile.py
index 351e78d..eb57db6 100644
--- a/ckanext/odsh/profiles/odsh_dcat_de_profile.py
+++ b/ckanext/odsh/profiles/odsh_dcat_de_profile.py
@@ -33,6 +33,7 @@ class ODSHDCATdeProfile(DCATdeProfile):
         )
         self._parse_distributions(dataset_dict, dataset_ref)
         self._parse_type(dataset_dict, dataset_ref)
+        self._parse_political_geocoding_uri(dataset_dict, dataset_ref)
         self._parse_references(dataset_dict, dataset_ref)
         self._parse_applicable_legislation(dataset_dict, dataset_ref)
         self._parse_hvd_category(dataset_dict, dataset_ref)
@@ -104,6 +105,16 @@ class ODSHDCATdeProfile(DCATdeProfile):
             ds_utils.insert_new_extras_field(
                 dataset_dict, 'hvdCategory', "{" + value + "}")
 
+    def _parse_political_geocoding_uri(self, dataset_dict, dataset_ref):
+        """There are datasets that have a politicalGeocodingURI but no spatial_uri."""
+        extras = extras=dataset_dict.get('extras')
+        political_geocoding_uri = helpers_odsh.odsh_extract_value_from_extras(extras=extras, key='politicalGeocodingURI')
+        spatial_uri = helpers_odsh.odsh_extract_value_from_extras(extras=extras, key='spatial_uri')
+        if not spatial_uri and political_geocoding_uri:
+            if '"' in political_geocoding_uri:
+                political_geocoding_uri = political_geocoding_uri.split('"')[1]
+            ds_utils.insert_new_extras_field( dataset_dict, 'spatial_uri', political_geocoding_uri)
+
     def _belongs_to_collection(self, dataset_dict, dataset_ref):
         dct_is_version_of = self._object(dataset_ref, DCT.isVersionOf)
         belongs_to_collection = True if dct_is_version_of else False
-- 
GitLab