Skip to content

Commit

Permalink
Merge pull request #233 from GovDataOfficial/add-fallback-for-resourc…
Browse files Browse the repository at this point in the history
…e-dates

Add fallback for dct:issued and dct:modified in resources
  • Loading branch information
amercader authored Dec 2, 2022
2 parents c38a819 + 01d40c5 commit 9b5dae5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

## [Unreleased](https://github.com/ckan/ckanext-dcat/compare/v1.3.0...HEAD)

* RDF serialization: Add fallback values for resource dates

## [v1.3.0](https://github.com/ckan/ckanext-dcat/compare/v1.2.0...v1.3.0) - 2022-08-01

* Fix assert expressions in tests (#218)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ This mapping is compatible with the [DCAT-AP v1.1](https://joinup.ec.europa.eu/a
| dcat:Distribution | dct:license | resource:license | | text | See note about dataset license |
| dcat:Distribution | adms:status | resource:status | | text | |
| dcat:Distribution | dcat:byteSize | resource:size | | number | |
| dcat:Distribution | dct:issued | resource:issued | | text | |
| dcat:Distribution | dct:modified | resource:modified | | text | |
| dcat:Distribution | dct:issued | resource:issued | created | text | |
| dcat:Distribution | dct:modified | resource:modified | metadata_modified | text | |
| dcat:Distribution | dct:rights | resource:rights | | text | |
| dcat:Distribution | foaf:page | resource:documentation | | list | See note about lists |
| dcat:Distribution | dct:language | resource:language | | list | See note about lists |
Expand Down
4 changes: 2 additions & 2 deletions ckanext/dcat/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,8 +1426,8 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):

# Dates
items = [
('issued', DCT.issued, None, Literal),
('modified', DCT.modified, None, Literal),
('issued', DCT.issued, ['created'], Literal),
('modified', DCT.modified, ['metadata_modified'], Literal),
]

self._add_date_triples_from_dict(resource_dict, distribution, items)
Expand Down
32 changes: 32 additions & 0 deletions ckanext/dcat/tests/test_euro_dcatap_profile_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ def test_distribution_fields(self):
'status': 'http://purl.org/adms/status/Completed',
'rights': 'Some statement about rights',
'license': 'http://creativecommons.org/licenses/by/3.0/',
'created': '2015-07-06T15:21:09.034694',
'metadata_modified': '2015-07-07T15:21:09.075774',
'issued': '2015-06-26T15:21:09.034694',
'modified': '2015-06-26T15:21:09.075774',
'size': 1234,
Expand Down Expand Up @@ -1042,6 +1044,36 @@ def test_distribution_format_mediatype_same(self):
[Literal(fmt_text)]
)

def test_distribution_dates_fallback(self):

resource = {
'id': 'c041c635-054f-4431-b647-f9186926d022',
'package_id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6',
'metadata_modified': '2015-06-26T15:21:09.075774',
'created': '2015-06-26T15:21:09.034694',
}

dataset = {
'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6',
'name': 'test-dataset',
'title': 'Test DCAT dataset',
'resources': [
resource
]
}

s = RDFSerializer(profiles=['euro_dcat_ap'])
g = s.g

dataset_ref = s.graph_from_dataset(dataset)

assert len([t for t in g.triples((dataset_ref, DCAT.distribution, None))]) == 1
distribution = self._triple(g, dataset_ref, DCAT.distribution, None)[2]

# Dates
assert self._triple(g, distribution, DCT.modified, resource['metadata_modified'], XSD.dateTime)
assert self._triple(g, distribution, DCT.issued, resource['created'], XSD.dateTime)

def test_distribution_format_mediatype_different(self):
dataset_dict, resource = self._get_base_dataset_with_resource()
# if format and mediaType are different, output both
Expand Down

0 comments on commit 9b5dae5

Please sign in to comment.