Skip to content
Snippets Groups Projects
Commit 9edcd4d9 authored by anonymous's avatar anonymous
Browse files

extend dcatde profile

parent 0e7c7fc5
No related branches found
No related tags found
No related merge requests found
...@@ -232,12 +232,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -232,12 +232,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
for field in ['title', 'notes','license_id']: for field in ['title', 'notes','license_id']:
schema.update({field: [toolkit.get_converter('not_empty')]}) schema.update({field: [toolkit.get_converter('not_empty')]})
##schema.update({'group_string': [toolkit.get_converter('odsh_group_string_convert')]})
# for i, item in enumerate(schema['groups']):
#schema['id'].update({'id': schema['groups']['id']+[toolkit.get_converter('odsh_group_convert')]})
##schema['groups'].update({'id': schema['groups']['id']})
## schema.update({'groups': [toolkit.get_converter('empty')]})
for i, item in enumerate(schema['tags']['name']): for i, item in enumerate(schema['tags']['name']):
if item == toolkit.get_validator('tag_name_validator'): if item == toolkit.get_validator('tag_name_validator'):
schema['tags']['name'][i] = toolkit.get_validator( schema['tags']['name'][i] = toolkit.get_validator(
...@@ -256,7 +250,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -256,7 +250,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
toolkit.get_converter('odsh_validate_temporal_start'), toolkit.get_converter('odsh_validate_temporal_start'),
toolkit.get_converter('odsh_validate_temporal_end'), toolkit.get_converter('odsh_validate_temporal_end'),
toolkit.get_converter('known_spatial_uri'), toolkit.get_converter('known_spatial_uri'),
toolkit.get_converter('licenseAttributionByText')
] ]
}) })
##schema.update({'title': [toolkit.get_converter('odsh_validate_extras')]+ schema['title']}) ##schema.update({'title': [toolkit.get_converter('odsh_validate_extras')]+ schema['title']})
......
from ckanext.dcatde.profiles import DCATdeProfile from ckanext.dcatde.profiles import DCATdeProfile, DCATDE, DCAT, VCARD, dcat_theme_prefix
from ckanext.dcat.utils import resource_uri
from ckanext.dcat.profiles import EuropeanDCATAPProfile, DCT from ckanext.dcat.profiles import EuropeanDCATAPProfile, DCT
from ckan.model.license import LicenseRegister from ckan.model.license import LicenseRegister
import ckanext.dcatde.dataset_utils as ds_utils
class ODSHDCATdeProfile(EuropeanDCATAPProfile): class ODSHEuropeanDCATAPProfile(EuropeanDCATAPProfile):
def _license(self, dataset_ref): def _license(self, dataset_ref):
if self._licenceregister_cache is not None: if self._licenceregister_cache is not None:
...@@ -28,3 +30,81 @@ class ODSHDCATdeProfile(EuropeanDCATAPProfile): ...@@ -28,3 +30,81 @@ class ODSHDCATdeProfile(EuropeanDCATAPProfile):
if license_id: if license_id:
return license_id return license_id
return '' return ''
class ODSHDCATdeProfile(DCATdeProfile):
def parse_dataset(self, dataset_dict, dataset_ref):
""" Transforms DCAT-AP.de-Data to CKAN-Dictionary """
# Simple additional fields
for key, predicate in (
('qualityProcessURI', DCATDE.qualityProcessURI),
('metadata_original_html', DCAT.landingPage),
('politicalGeocodingLevelURI', DCATDE.politicalGeocodingLevelURI),
):
value = self._object_value(dataset_ref, predicate)
if value:
ds_utils.insert_new_extras_field(dataset_dict, key, value)
# List fields
for key, predicate, in (
('contributorID', DCATDE.contributorID),
('politicalGeocodingURI', DCATDE.politicalGeocodingURI),
('legalbasisText', DCATDE.legalbasisText),
('geocodingText', DCATDE.geocodingText),
):
values = self._object_value_list(dataset_ref, predicate)
if values:
ds_utils.insert_new_extras_field(dataset_dict, key, json.dumps(values))
self._parse_contact(dataset_dict, dataset_ref, DCATDE.originator, 'originator', True)
self._parse_contact(dataset_dict, dataset_ref, DCATDE.maintainer, 'maintainer', False)
self._parse_contact(dataset_dict, dataset_ref, DCT.contributor, 'contributor', True)
self._parse_contact(dataset_dict, dataset_ref, DCT.creator, 'author', False)
# dcat:contactPoint
# TODO: dcat-ap adds the values to extras.contact_... . Maybe better than maintainer?
contact = self._object(dataset_ref, DCAT.contactPoint)
self._add_maintainer_field(dataset_dict, contact, 'url', VCARD.hasURL)
contact_tel = self._object_value(contact, VCARD.hasTelephone)
if contact_tel:
ds_utils.insert(dataset_dict, 'maintainer_tel', self._without_tel(contact_tel), True)
self._add_maintainer_field(dataset_dict, contact, 'street', VCARD.hasStreetAddress)
self._add_maintainer_field(dataset_dict, contact, 'city', VCARD.hasLocality)
self._add_maintainer_field(dataset_dict, contact, 'zip', VCARD.hasPostalCode)
self._add_maintainer_field(dataset_dict, contact, 'country', VCARD.hasCountryName)
# Groups
groups = self._get_dataset_value(dataset_dict, 'groups')
if not groups:
groups = []
for obj in self.g.objects(dataset_ref, DCAT.theme):
current_theme = unicode(obj)
if current_theme.startswith(dcat_theme_prefix):
group = current_theme.replace(dcat_theme_prefix, '').lower()
groups.append({'id': group, 'name': group})
dataset_dict['groups'] = groups
# Add additional distribution fields
hasAttr = False
for distribution in self.g.objects(dataset_ref, DCAT.distribution):
for resource_dict in dataset_dict.get('resources', []):
# Match distribution in graph and distribution in ckan-dict
if unicode(distribution) == resource_uri(resource_dict):
for key, predicate in (
('licenseAttributionByText', DCATDE.licenseAttributionByText),
('plannedAvailability', DCATDE.plannedAvailability)
):
value = self._object_value(distribution, predicate)
if value:
ds_utils.insert_resource_extra(resource_dict, key, value)
if not hasAttr and key == 'licenseAttributionByText':
ds_utils.insert_new_extras_field(dataset_dict, key, value)
hasAttr = True
return dataset_dict
\ No newline at end of file
...@@ -21,9 +21,11 @@ def _extract_value(data, field): ...@@ -21,9 +21,11 @@ def _extract_value(data, field):
return None return None
return data[(key[0], key[1], 'value')] return data[(key[0], key[1], 'value')]
def validate_extra_groups(data): def validate_extra_groups(data, requireAtLeastOne):
value = _extract_value(data, 'groups') value = _extract_value(data, 'groups')
if not value: if not value:
if not requireAtLeastOne:
return None
return 'at least one group needed' return 'at least one group needed'
groups = [g.strip() for g in value.split(',') if value.strip()] groups = [g.strip() for g in value.split(',') if value.strip()]
...@@ -32,6 +34,8 @@ def validate_extra_groups(data): ...@@ -32,6 +34,8 @@ def validate_extra_groups(data):
data[k]='' data[k]=''
# del data[k] # del data[k]
if len(groups)==0: if len(groups)==0:
if not requireAtLeastOne:
return None
return 'at least one group needed' return 'at least one group needed'
for num, tag in zip(range(len(groups)), groups): for num, tag in zip(range(len(groups)), groups):
...@@ -40,7 +44,7 @@ def validate_extra_groups(data): ...@@ -40,7 +44,7 @@ def validate_extra_groups(data):
def validate_extras(key, data, errors, context): def validate_extras(key, data, errors, context):
pass pass
extra_errors = {} extra_errors = {}
error = validate_extra_groups(data) error = validate_extra_groups(data,False)
if error: if error:
extra_errors['groups'] = error extra_errors['groups'] = error
...@@ -48,6 +52,10 @@ def validate_extras(key, data, errors, context): ...@@ -48,6 +52,10 @@ def validate_extras(key, data, errors, context):
if error: if error:
extra_errors['issued'] = error extra_errors['issued'] = error
error = validate_licenseAttributionByText(data)
if error:
extra_errors['licenseAttributionByText'] = error
if extra_errors: if extra_errors:
raise toolkit.Invalid(extra_errors) raise toolkit.Invalid(extra_errors)
...@@ -105,7 +113,7 @@ def validate_extra_date(key, field, data, optional=False): ...@@ -105,7 +113,7 @@ def validate_extra_date(key, field, data, optional=False):
def validate_extra_date_factory(field, optional=False): def validate_extra_date_factory(field, optional=False):
return lambda key, data, errors, context: validate_extra_date(key, field, data, optional) return lambda key, data, errors, context: validate_extra_date(key, field, data, optional)
def validate_licenseAttributionByText(key, data, errors, context): def validate_licenseAttributionByText(data):
register = model.Package.get_license_register() register = model.Package.get_license_register()
isByLicense=False isByLicense=False
for k in data: for k in data:
...@@ -125,9 +133,9 @@ def validate_licenseAttributionByText(key, data, errors, context): ...@@ -125,9 +133,9 @@ def validate_licenseAttributionByText(key, data, errors, context):
hasAttribution = value != '' hasAttribution = value != ''
break break
if isByLicense and not hasAttribution: if isByLicense and not hasAttribution:
raise toolkit.Invalid('licenseAttributionByText:odsh_licence_text_missing_error_label') return 'empty not allowed'
if not isByLicense and hasAttribution: if not isByLicense and hasAttribution:
raise toolkit.Invalid('licenseAttributionByText:odsh_licence_text_not_allowed_error_label') return 'text not allowed for this license'
def known_spatial_uri(key, data, errors, context): def known_spatial_uri(key, data, errors, context):
value = _extract_value(data, 'spatial_uri') value = _extract_value(data, 'spatial_uri')
...@@ -201,7 +209,6 @@ def tag_string_convert(key, data, errors, context): ...@@ -201,7 +209,6 @@ def tag_string_convert(key, data, errors, context):
def get_validators(): def get_validators():
return { return {
'licenseAttributionByText': validate_licenseAttributionByText,
'known_spatial_uri': known_spatial_uri, 'known_spatial_uri': known_spatial_uri,
'odsh_validate_temporal_start': validate_extra_date_factory('temporal_start'), 'odsh_validate_temporal_start': validate_extra_date_factory('temporal_start'),
'odsh_validate_temporal_end': validate_extra_date_factory('temporal_end', True), 'odsh_validate_temporal_end': validate_extra_date_factory('temporal_end', True),
......
...@@ -92,6 +92,7 @@ setup( ...@@ -92,6 +92,7 @@ setup(
ckan = ckan.lib.extract:extract_ckan ckan = ckan.lib.extract:extract_ckan
[ckan.rdf.profiles] [ckan.rdf.profiles]
odsheuro_dcat_ap=ckanext.odsh.profiles:ODSHEuropeanDCATAPProfile
odshdcatap_de=ckanext.odsh.profiles:ODSHDCATdeProfile odshdcatap_de=ckanext.odsh.profiles:ODSHDCATdeProfile
''', ''',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment