Commit 240fe8d2 authored by Willem ter Berg's avatar Willem ter Berg

added initial rights validation.

parent eebb78fc
......@@ -46,6 +46,7 @@ def create_schema(schema):
contact_point_validation = tk.get_validator('contact_point_validation')
hash_validation = tk.get_validator('hash_validation')
legal_foundation_validation = tk.get_validator('legal_foundation_validation')
rights_validation = tk.get_validator('rights_validation')
to_curly_string_if_list = tk.get_converter('convert_to_curly_string_if_list')
schema.update({
......@@ -96,7 +97,8 @@ def create_schema(schema):
temporal_validation,
contact_point_validation,
legal_foundation_validation,
date_planned_validation]
date_planned_validation,
rights_validation]
})
schema['resources'].update({
......@@ -165,6 +167,7 @@ def update_schema(schema):
contact_point_validation = tk.get_validator('contact_point_validation')
hash_validation = tk.get_validator('hash_validation')
legal_foundation_validation = tk.get_validator('legal_foundation_validation')
rights_validation = tk.get_validator('rights_validation')
schema.update({
'identifier': [mandatory, is_string, to_extras],
......@@ -214,7 +217,8 @@ def update_schema(schema):
temporal_validation,
contact_point_validation,
legal_foundation_validation,
date_planned_validation]
date_planned_validation,
rights_validation]
})
schema['resources'].update({
......
# encoding: utf-8
"""
Provides complex rights validation for a DCAT-AP-DONL dataset.
"""
def validate_stated_rights(key, data_dict, errors, context):
"""
Validates that the various rights statements do not conflict each other.
:param key: str, argument to match CKAN method signature, not used
:param data_dict: dict, flattened dict of the dataset
:param errors: dict, flattened dict of the validation errors
:param context: dict, argument to match CKAN method signature, not used
:return: (key, data, errors, context), the original arguments, possibly modified
"""
non_open_licenses = [
{ 'id': 'http://standaarden.overheid.nl/owms/terms/geslotenlicentie' },
{ 'id': 'http://standaarden.overheid.nl/owms/terms/licentieonbekend' }
]
status_available = data_dict.get(('dataset_status',), None) == 'http://data.overheid.nl/status/beschikbaar'
status_closed = data_dict.get(('dataset_status',), None) == 'http://data.overheid.nl/status/niet beschikbaar'
access_rights_public = data_dict.get(('access_rights',), None) == 'http://publications.europa.eu/resource/authority/access-right/PUBLIC'
access_rights_restricted = data_dict.get(('access_rights',), None) == 'http://publications.europa.eu/resource/authority/access-right/RESTRICTED'
license_is_open = data_dict.get(('license',), None) not in non_open_licenses
if status_available and access_rights_public and not license_is_open:
errors[('license',)] = ['An open license must be provided when dataset_status is [http://data.overheid.nl/status/beschikbaar] and access_rights is [http://publications.europa.eu/resource/authority/access-right/PUBLIC]']
if status_available and not license_is_open and not access_rights_restricted:
errors[('access_rights',)] = ['access_rights must be [http://publications.europa.eu/resource/authority/access-right/RESTRICTED] when status is [http://data.overheid.nl/status/beschikbaar] and a non-open license is provided']
if status_closed and license_is_open:
errors[('license',)] = ['cannot provide an open license when dataset_status is [http://data.overheid.nl/status/niet beschikbaar]']
return key, data_dict, errors, context
......@@ -13,6 +13,7 @@ import ckanext.dcatdonl.validator.hash_validator as hash_validator
import ckanext.dcatdonl.validator.legal_foundation_validator as legal_foundation_validator
import ckanext.dcatdonl.validator.valuelist_validator as valuelist_validator
import ckanext.dcatdonl.validator.changetype_validator as changetype_validator
import ckanext.dcatdonl.validator.rights_validator as rights_validator
class ValidatorException(Exception):
......@@ -34,6 +35,7 @@ _VALIDATORS = {
'contact_point_validation': contact_point_validator.valid_contact_point,
'hash_validation': hash_validator.valid_hash,
'legal_foundation_validation': legal_foundation_validator.valid_legal_foundation,
'rights_validation': rights_validator.validate_stated_rights,
'overheid_dataset_status': valuelist_validator.overheid_dataset_status,
'overheid_taxonomiebeleidsagenda': valuelist_validator.overheid_taxonomiebeleidsagenda,
'overheid_openbaarheidsniveau': valuelist_validator.overheid_openbaarheidsniveau,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment