From 8727ab19585546520c5737c5778d7e41636ad344 Mon Sep 17 00:00:00 2001
From: Thorge Petersen <petersen@rz.uni-kiel.de>
Date: Fri, 8 Dec 2023 15:37:47 +0100
Subject: [PATCH] Worked on profile support for applicableLegislation and
 hvdCategory (wip)

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

diff --git a/ckanext/odsh/profiles/odsh_dcat_de_profile.py b/ckanext/odsh/profiles/odsh_dcat_de_profile.py
index 517a6627..1910368c 100644
--- a/ckanext/odsh/profiles/odsh_dcat_de_profile.py
+++ b/ckanext/odsh/profiles/odsh_dcat_de_profile.py
@@ -29,6 +29,9 @@ class ODSHDCATdeProfile(DCATdeProfile):
         self._parse_distributions(dataset_dict, dataset_ref)
         self._parse_type(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)
+        
         if self._belongs_to_collection(dataset_dict, dataset_ref):
             self._mark_for_adding_to_ckan_collection(dataset_dict, dataset_ref)
         return dataset_dict
@@ -56,6 +59,16 @@ class ODSHDCATdeProfile(DCATdeProfile):
         value = self._object(dataset_ref, DCT.references)
         if value:
             ds_utils.insert_new_extras_field(dataset_dict, 'reference', value)
+    
+    def _parse_applicable_legislation(self, dataset_dict, dataset_ref):
+        value = self._object(dataset_ref, DCT.applicableLegislation)
+        if value:
+            ds_utils.insert_new_extras_field(dataset_dict, 'applicableLegislation', value)
+
+    def _parse_hvd_category(self, dataset_dict, dataset_ref):
+        value = self._object(dataset_ref, DCT.hvdCategory)
+        if value:
+            ds_utils.insert_new_extras_field(dataset_dict, 'hvdCategory', value)
 
     def _belongs_to_collection(self, dataset_dict, dataset_ref):
         dct_is_version_of = self._object(dataset_ref, DCT.isVersionOf)
@@ -80,7 +93,9 @@ class ODSHDCATdeProfile(DCATdeProfile):
         self._add_license_attribution_by_text(dataset_dict, dataset_ref)
         self._add_type(dataset_dict, dataset_ref)
         self._add_modified_and_issued(dataset_dict, dataset_ref)
-        self._add_references(dataset_dict, dataset_ref)
+        self._add_extra_field(dataset_dict, dataset_ref, 'reference', DCT.references)
+        self._add_extra_field(dataset_dict, dataset_ref, 'applicableLegislation', DCAT.applicableLegislation)
+        self._add_extra_field(dataset_dict, dataset_ref, 'hvdCategory', DCAT.hvdCategory)
         self._add_version(dataset_dict, dataset_ref)
         if self._is_dataset_collection(dataset_dict):
             self._remove_predefined_collection_members()
@@ -110,18 +125,13 @@ class ODSHDCATdeProfile(DCATdeProfile):
                      rdflib.Literal(licenseAttributionByText))
                 )
 
-    def _add_references(self, dataset_dict, dataset_ref):
-        '''
-        Adds reference (Musterdatenkatalog/Musterdatensatz) extra field to
-        dcat:references.
-        '''
-        sample_dataset_uri = helpers_odsh.odsh_extract_value_from_extras(dataset_dict.get('extras'), 'reference')
-        if sample_dataset_uri:
+    def _add_extra_field(self, dataset_dict, dataset_ref, field_name, dcat_property):
+        uri = helpers_odsh.odsh_extract_value_from_extras(dataset_dict.get('extras'), field_name)
+        if uri:
             self.g.set(
-                (dataset_ref, DCT.references,
-                    rdflib.URIRef(sample_dataset_uri)
-                 )
+                (dataset_ref, dcat_property, rdflib.URIRef(uri))
             )
+
     
     def _add_modified_and_issued(self, dataset_dict, dataset_ref):
         '''
-- 
GitLab