Skip to content
Snippets Groups Projects
Commit ef6730aa authored by Thorge Petersen's avatar Thorge Petersen
Browse files

Merge branch '15-dct-modified-und-dct-issued-fur-distributionen' into 'v1.3'

Add distributions last_modified and created values when graph is created from...

See merge request !4
parents 9f0f6303 48cf4a53
No related branches found
No related tags found
2 merge requests!17Stage System soll in Zukunft Master Branch erhalten,!4Add distributions last_modified and created values when graph is created from...
...@@ -57,7 +57,6 @@ class ODSHDCATdeProfile(DCATdeProfile): ...@@ -57,7 +57,6 @@ class ODSHDCATdeProfile(DCATdeProfile):
def _mark_for_adding_to_ckan_collection(self, dataset_dict, dataset_ref): def _mark_for_adding_to_ckan_collection(self, dataset_dict, dataset_ref):
dataset_dict.update({'add_to_collection': True}) dataset_dict.update({'add_to_collection': True})
# to RDF # to RDF
def graph_from_dataset(self, dataset_dict, dataset_ref): def graph_from_dataset(self, dataset_dict, dataset_ref):
...@@ -72,6 +71,7 @@ class ODSHDCATdeProfile(DCATdeProfile): ...@@ -72,6 +71,7 @@ class ODSHDCATdeProfile(DCATdeProfile):
self._add_contributor_id(dataset_dict, dataset_ref) self._add_contributor_id(dataset_dict, dataset_ref)
self._add_license_attribution_by_text(dataset_dict, dataset_ref) self._add_license_attribution_by_text(dataset_dict, dataset_ref)
self._add_type(dataset_dict, dataset_ref) self._add_type(dataset_dict, dataset_ref)
self._add_modified_and_issued(dataset_dict, dataset_ref)
if self._is_dataset_collection(dataset_dict): if self._is_dataset_collection(dataset_dict):
self._remove_predefined_collection_members() self._remove_predefined_collection_members()
self._add_collection_members(dataset_dict, dataset_ref) self._add_collection_members(dataset_dict, dataset_ref)
...@@ -87,14 +87,39 @@ class ODSHDCATdeProfile(DCATdeProfile): ...@@ -87,14 +87,39 @@ class ODSHDCATdeProfile(DCATdeProfile):
) )
def _add_license_attribution_by_text(self, dataset_dict, dataset_ref): def _add_license_attribution_by_text(self, dataset_dict, dataset_ref):
licenseAttributionByText = self._get_dataset_value(dataset_dict, 'licenseAttributionByText') licenseAttributionByText = self._get_dataset_value(
dataset_dict, 'licenseAttributionByText')
if licenseAttributionByText: if licenseAttributionByText:
self.g.set( self.g.set(
(dataset_ref, DCATDE.licenseAttributionByText, rdflib.Literal(licenseAttributionByText)) (dataset_ref, DCATDE.licenseAttributionByText,
rdflib.Literal(licenseAttributionByText))
)
for distribution in self.g.objects(dataset_ref, DCAT.distribution):
self.g.set(
(distribution, DCATDE.licenseAttributionByText,
rdflib.Literal(licenseAttributionByText))
) )
def _add_modified_and_issued(self, dataset_dict, dataset_ref):
'''
Adds distributions last_modified and created values to
dcat:modified and dcat:issued.
'''
for distribution in self.g.objects(dataset_ref, DCAT.distribution): 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):
last_modified = resource_dict.get('last_modified', None)
if last_modified:
self.g.set(
(distribution, DCT.modified, rdflib.Literal(
last_modified, datatype="http://www.w3.org/2001/XMLSchema#dateTime"))
)
created = resource_dict.get('created', None)
if created:
self.g.set( self.g.set(
(distribution, DCATDE.licenseAttributionByText, rdflib.Literal(licenseAttributionByText)) (distribution, DCT.issued, rdflib.Literal(
created, datatype="http://www.w3.org/2001/XMLSchema#dateTime"))
) )
def _add_type(self, dataset_dict, dataset_ref): def _add_type(self, dataset_dict, dataset_ref):
...@@ -121,7 +146,8 @@ class ODSHDCATdeProfile(DCATdeProfile): ...@@ -121,7 +146,8 @@ class ODSHDCATdeProfile(DCATdeProfile):
self.g.remove((s, p, o)) self.g.remove((s, p, o))
def _add_collection_members(self, dataset_dict, dataset_ref): def _add_collection_members(self, dataset_dict, dataset_ref):
dataset_refs_belonging_to_collection = self._get_dataset_refs_belonging_to_collection(dataset_dict) dataset_refs_belonging_to_collection = self._get_dataset_refs_belonging_to_collection(
dataset_dict)
for ref in dataset_refs_belonging_to_collection: for ref in dataset_refs_belonging_to_collection:
self.g.add( self.g.add(
(dataset_ref, DCT.hasVersion, rdflib.URIRef(ref)) (dataset_ref, DCT.hasVersion, rdflib.URIRef(ref))
...@@ -134,8 +160,10 @@ class ODSHDCATdeProfile(DCATdeProfile): ...@@ -134,8 +160,10 @@ class ODSHDCATdeProfile(DCATdeProfile):
def _get_dataset_refs_belonging_to_collection(self, dataset_dict): def _get_dataset_refs_belonging_to_collection(self, dataset_dict):
dataset_names = helpers_collection.get_dataset_names(dataset_dict) dataset_names = helpers_collection.get_dataset_names(dataset_dict)
dataset_dicts = [model.Package.get(name).as_dict() for name in dataset_names] dataset_dicts = [model.Package.get(
dataset_ids = [dataset_dict.get('id') for dataset_dict in dataset_dicts] name).as_dict() for name in dataset_names]
dataset_ids = [dataset_dict.get('id')
for dataset_dict in dataset_dicts]
dataset_refs = [self._construct_refs(id) for id in dataset_ids] dataset_refs = [self._construct_refs(id) for id in dataset_ids]
return dataset_refs return dataset_refs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment