From 1d32eb58dfd2f6dc96f1c71d2616c956688414fa Mon Sep 17 00:00:00 2001
From: Thorge Petersen <petersen@rz.uni-kiel.de>
Date: Tue, 20 Feb 2024 13:06:58 +0100
Subject: [PATCH] Updated profile to parse multiple appl. legilation or hvd
 values in a single extra field according custom curly brace format

---
 ckanext/odsh/profiles/odsh_dcat_de_profile.py | 35 ++++++++++++++++---
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/ckanext/odsh/profiles/odsh_dcat_de_profile.py b/ckanext/odsh/profiles/odsh_dcat_de_profile.py
index 5ccf29f..16b87f3 100644
--- a/ckanext/odsh/profiles/odsh_dcat_de_profile.py
+++ b/ckanext/odsh/profiles/odsh_dcat_de_profile.py
@@ -65,17 +65,44 @@ class ODSHDCATdeProfile(DCATdeProfile):
         if value:
             ds_utils.insert_new_extras_field(dataset_dict, 'reference', value)
 
+    def _parse_metadata_list(self, dataset_dict, dataset_ref, field_name, rdf_predicate):
+        value = ""
+        for obj in self.g.objects(dataset_ref, rdf_predicate):
+            if value:
+                value += "," + str(obj)
+            else:
+                value = str(obj)
+        if value:
+            ds_utils.insert_new_extras_field(
+                dataset_dict, field_name, "{" + value + "}")
+
+    def _parse_applicable_legislation(self, dataset_dict, dataset_ref):
+        self._parse_metadata_list(dataset_dict, dataset_ref, 'applicableLegislation', DCATAP.applicableLegislation)
+
+    def _parse_hvd_category(self, dataset_dict, dataset_ref):
+        self._parse_metadata_list(dataset_dict, dataset_ref, 'hvdCategory', DCATAP.hvdCategory)
+
     def _parse_applicable_legislation(self, dataset_dict, dataset_ref):
-        value = self._object(dataset_ref, DCT.applicableLegislation)
+        value = ""
+        for applicable_legislation in self.g.objects(dataset_ref, DCATAP.applicableLegislation):
+            if value:
+                value += "," + applicable_legislation
+            else:
+                value = applicable_legislation
         if value:
             ds_utils.insert_new_extras_field(
-                dataset_dict, 'applicableLegislation', value)
+                dataset_dict, 'applicableLegislation', "{" + value + "}")
 
     def _parse_hvd_category(self, dataset_dict, dataset_ref):
-        value = self._object(dataset_ref, DCT.hvdCategory)
+        value = ""
+        for hvdCategory in self.g.objects(dataset_ref, DCATAP.hvdCategory):
+            if value:
+                value += "," + hvdCategory
+            else:
+                value = hvdCategory
         if value:
             ds_utils.insert_new_extras_field(
-                dataset_dict, 'hvdCategory', value)
+                dataset_dict, 'hvdCategory', "{" + value + "}")
 
     def _belongs_to_collection(self, dataset_dict, dataset_ref):
         dct_is_version_of = self._object(dataset_ref, DCT.isVersionOf)
-- 
GitLab