Skip to content

Commit

Permalink
Add DCAT_AP_HVD_CATEGORY_LEGISLATION constant and validator for hvd_c…
Browse files Browse the repository at this point in the history
…ategory
  • Loading branch information
mjanez committed Oct 31, 2024
1 parent bd1d368 commit e940fa2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ckanext/schemingdcat/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,6 @@
'resource':
['url', 'availability', 'mimetype', 'status', 'resource_relation', 'license', 'rights', 'conforms_to', 'reference_system']
}
EMAIL_FIELD_NAMES = ['publisher_email', 'maintainer_email', 'author_email', ]
EMAIL_FIELD_NAMES = ['publisher_email', 'maintainer_email', 'author_email', ]

DCAT_AP_HVD_CATEGORY_LEGISLATION = "http://data.europa.eu/eli/reg_impl/2023/138/oj"
29 changes: 28 additions & 1 deletion ckanext/schemingdcat/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
from ckanext.schemingdcat.utils import parse_json
from ckanext.schemingdcat.config import (
OGC2CKAN_HARVESTER_MD_CONFIG,
mimetype_base_uri
mimetype_base_uri,
DCAT_AP_HVD_CATEGORY_LEGISLATION
)

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -915,4 +916,30 @@ def validator(key, data, errors, context):

data[key] = value

return validator

@scheming_validator
@validator
def schemingdcat_hvd_category_applicable_legislation(field, schema):
"""
Returns a validator function that checks if the 'hvd_category' value is not empty. If it is not empty, it updates the value of the field by adding the Commission Implementing Regulation (EU) 2023/138 of 21 December 2022 laying down a list of specific high-value datasets and the arrangements for their publication and re-use (Text with EEA relevance) to all datasets that contain an hvd_category (HVD Category).
Args:
field (dict): Information about the field to be updated.
schema (dict): The schema for the field to be updated.
Returns:
function: A validation function that updates the field based on the presence of 'hvd_category'.
"""
def validator(key, data, errors, context):
hvd_category = data.get(('hvd_category', ))
if hvd_category:
if isinstance(data.get(key), list):
if not data[key]:
data[key] = [DCAT_AP_HVD_CATEGORY_LEGISLATION]
else:
data[key].append(DCAT_AP_HVD_CATEGORY_LEGISLATION)
else:
data[key] = [DCAT_AP_HVD_CATEGORY_LEGISLATION]

return validator

0 comments on commit e940fa2

Please sign in to comment.