Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions invenio_rdm_records/resources/serializers/dcat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,45 @@ def access_url(file):
"{{{dcat}}}mediaType": media_type,
"{{{dcat}}}byteSize": byte_size,
"{{{dcat}}}accessURL": access_url,
# TODO: there's also "spdx:checksum", but it's not in the W3C spec yet
}

for f in files:
for file in files:
dist_wrapper = ET.SubElement(root[0], "{{{dcat}}}distribution".format(**ns))
dist = ET.SubElement(dist_wrapper, "{{{dcat}}}Distribution".format(**ns))

for tag, func in files_fields.items():
tag_value = func(f)

tag_value = func(file)
if tag_value:
el = ET.SubElement(dist, tag.format(**ns))
if isinstance(tag_value, str):
el.text = tag_value
if isinstance(tag_value, dict):
el.attrib.update(tag_value)

checksum = file.get("checksum") if file.get("checksum") else None
if checksum:
value = checksum.split(":")[1]
spdx_checksum_el = ET.SubElement(
dist, "{{{spdx}}}checksum".format(**ns)
)
spdx_checksum_obj = ET.SubElement(
spdx_checksum_el, "{{{spdx}}}Checksum".format(**ns)
)

algo_el = ET.SubElement(
spdx_checksum_obj,
"{{{spdx}}}algorithm".format(**ns),
)
algo_el.attrib["{{{rdf}}}resource".format(**ns)] = (
f"http://spdx.org/rdf/terms#checksumAlgorithm_md5"
)

value_el = ET.SubElement(
spdx_checksum_obj,
"{{{spdx}}}checksumValue".format(**ns),
)
value_el.text = value

def add_missing_creatibutor_links(self, rdf_tree):
"""Add missing `rdf:about` attributes to <rdf:Description> within <dct:creator> and <dct:contributor> and <foaf:Organization> within <org:memberOf>."""
namespaces = rdf_tree.nsmap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
xmlns:dct = "http://purl.org/dc/terms/"
xmlns:dctype = "http://purl.org/dc/dcmitype/"
xmlns:dcat = "http://www.w3.org/ns/dcat#"
xmlns:spdx = "http://spdx.org/rdf/terms#"
xmlns:foaf = "http://xmlns.com/foaf/0.1/"
xmlns:gsp = "http://www.opengis.net/ont/geosparql#"
xmlns:locn = "http://www.w3.org/ns/locn#"
Expand Down
1 change: 1 addition & 0 deletions invenio_rdm_records/resources/serializers/dcat/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def get_files(self, obj):
access_url=access_url,
download_url=url,
key=value["key"],
checksum=value["checksum"],
)
)

Expand Down
8 changes: 8 additions & 0 deletions tests/resources/serializers/test_dcat_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_dcat_serializer(running_app, full_record_to_dict):
'xmlns:dct="http://purl.org/dc/terms/" '
'xmlns:dctype="http://purl.org/dc/dcmitype/" '
'xmlns:dcat="http://www.w3.org/ns/dcat#" '
'xmlns:spdx="http://spdx.org/rdf/terms#" '
'xmlns:foaf="http://xmlns.com/foaf/0.1/" '
'xmlns:gsp="http://www.opengis.net/ont/geosparql#" '
'xmlns:locn="http://www.w3.org/ns/locn#" '
Expand Down Expand Up @@ -253,6 +254,13 @@ def test_dcat_serializer(running_app, full_record_to_dict):
" <dcat:byteSize>9</dcat:byteSize>\n"
" <dcat:accessURL "
'rdf:resource="https://doi.org/10.1234/12345-abcde"/>\n'
" <spdx:checksum>\n"
" <spdx:Checksum>\n"
" <spdx:algorithm "
'rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_md5"/>\n'
" <spdx:checksumValue>e795abeef2c38de2b064be9f6364ceae</spdx:checksumValue>\n"
" </spdx:Checksum>\n"
" </spdx:checksum>\n"
" </dcat:Distribution>\n"
" </dcat:distribution>\n"
" </rdf:Description>\n"
Expand Down
Loading