Skip to content

Commit

Permalink
legacy: serialize custom fields
Browse files Browse the repository at this point in the history
  • Loading branch information
slint committed Oct 31, 2023
1 parent dde3572 commit 75e4c98
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
130 changes: 130 additions & 0 deletions site/tests/legacy/deposits/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,71 @@ def test_data():
],
title="Test title",
upload_type="publication",
custom={
# dwc
"dwc:basisOfRecord": ["foo", "bar"],
"dwc:catalogNumber": ["foo", "bar"],
"dwc:class": ["foo", "bar"],
"dwc:collectionCode": ["MUSM", "ZMPC"],
"dwc:country": ["foo", "bar"],
"dwc:county": ["foo", "bar"],
"dwc:dateIdentified": ["2011-05-17", "2022-08-18"],
"dwc:decimalLatitude": [45.90621, -33.85249],
"dwc:decimalLongitude": [6.1267, 151.21046],
"dwc:eventDate": ["2011-05-17", "2022-08-18"],
"dwc:family": ["Cerambycidae"],
"dwc:genus": ["Asynapteron"],
"dwc:identifiedBy": ["foo", "bar"],
"dwc:individualCount": ["foo", "bar"],
"dwc:institutionCode": ["foo", "bar"],
"dwc:kingdom": ["Animalia"],
"dwc:lifeStage": ["foo", "bar"],
"dwc:locality": ["foo", "bar"],
"dwc:materialSampleID": ["foo", "bar"],
"dwc:namePublishedInID": ["foo", "bar"],
"dwc:namePublishedInYear": ["foo", "bar"],
"dwc:order": ["Coleoptera"],
"dwc:otherCatalogNumbers": ["foo", "bar"],
"dwc:phylum": ["Arthropoda"],
"dwc:preparations": ["foo", "bar"],
"dwc:recordedBy": ["foo", "bar"],
"dwc:scientificName": ["foo", "bar"],
"dwc:scientificNameAuthorship": [
"Ju\u00e1rez-No\u00e9 & Gonz\u00e1lez-Coronado"
],
"dwc:scientificNameID": ["foo", "bar"],
"dwc:sex": ["foo", "bar"],
"dwc:specificEpithet": ["andinum"],
"dwc:stateProvince": ["foo", "bar"],
"dwc:taxonID": ["foo", "bar"],
"dwc:taxonRank": ["species"],
"dwc:taxonomicStatus": ["sp. nov."],
"dwc:typeStatus": ["holotype"],
"dwc:verbatimElevation": ["foo", "bar"],
"dwc:verbatimEventDate": ["2011-05-17"],
# openbiodiv
"openbiodiv:TaxonomicConceptLabel": [
"Asynapteron andinum Ju\u00e1rez-No\u00e9 & Gonz\u00e1lez-Coronado, 2023"
],
# ac
"ac:associatedSpecimenReference": ["foo", "bar"],
"ac:captureDevice": ["foo", "bar"],
"ac:physicalSetting": ["foo", "bar"],
"ac:resourceCreationTechnique": ["foo", "bar"],
"ac:subjectOrientation": ["foo", "bar"],
"ac:subjectPart": ["foo", "bar"],
# dc
"dc:creator": ["foo", "bar"],
"dc:rightsHolder": ["foo", "bar"],
# obo
"obo:RO_0002453": [
{"subject": ["foo", "bar"], "object": ["foo", "bar"]},
{"subject": ["foo", "bar"], "object": ["foo", "bar"]},
],
# gbif-dwc
"gbif-dwc:identifiedByID": ["foo", "bar"],
"gbif-dwc:recordedByID": ["foo", "bar"],
},
)
)

Expand Down Expand Up @@ -210,4 +275,69 @@ def expected_record_metadata():
],
title="Test title",
upload_type="publication",
custom={
# dwc
"dwc:basisOfRecord": ["foo", "bar"],
"dwc:catalogNumber": ["foo", "bar"],
"dwc:class": ["foo", "bar"],
"dwc:collectionCode": ["MUSM", "ZMPC"],
"dwc:country": ["foo", "bar"],
"dwc:county": ["foo", "bar"],
"dwc:dateIdentified": ["2011-05-17", "2022-08-18"],
"dwc:decimalLatitude": [45.90621, -33.85249],
"dwc:decimalLongitude": [6.1267, 151.21046],
"dwc:eventDate": ["2011-05-17", "2022-08-18"],
"dwc:family": ["Cerambycidae"],
"dwc:genus": ["Asynapteron"],
"dwc:identifiedBy": ["foo", "bar"],
"dwc:individualCount": ["foo", "bar"],
"dwc:institutionCode": ["foo", "bar"],
"dwc:kingdom": ["Animalia"],
"dwc:lifeStage": ["foo", "bar"],
"dwc:locality": ["foo", "bar"],
"dwc:materialSampleID": ["foo", "bar"],
"dwc:namePublishedInID": ["foo", "bar"],
"dwc:namePublishedInYear": ["foo", "bar"],
"dwc:order": ["Coleoptera"],
"dwc:otherCatalogNumbers": ["foo", "bar"],
"dwc:phylum": ["Arthropoda"],
"dwc:preparations": ["foo", "bar"],
"dwc:recordedBy": ["foo", "bar"],
"dwc:scientificName": ["foo", "bar"],
"dwc:scientificNameAuthorship": [
"Ju\u00e1rez-No\u00e9 & Gonz\u00e1lez-Coronado"
],
"dwc:scientificNameID": ["foo", "bar"],
"dwc:sex": ["foo", "bar"],
"dwc:specificEpithet": ["andinum"],
"dwc:stateProvince": ["foo", "bar"],
"dwc:taxonID": ["foo", "bar"],
"dwc:taxonRank": ["species"],
"dwc:taxonomicStatus": ["sp. nov."],
"dwc:typeStatus": ["holotype"],
"dwc:verbatimElevation": ["foo", "bar"],
"dwc:verbatimEventDate": ["2011-05-17"],
# openbiodiv
"openbiodiv:TaxonomicConceptLabel": [
"Asynapteron andinum Ju\u00e1rez-No\u00e9 & Gonz\u00e1lez-Coronado, 2023"
],
# ac
"ac:associatedSpecimenReference": ["foo", "bar"],
"ac:captureDevice": ["foo", "bar"],
"ac:physicalSetting": ["foo", "bar"],
"ac:resourceCreationTechnique": ["foo", "bar"],
"ac:subjectOrientation": ["foo", "bar"],
"ac:subjectPart": ["foo", "bar"],
# dc
"dc:creator": ["foo", "bar"],
"dc:rightsHolder": ["foo", "bar"],
# obo
"obo:RO_0002453": [
{"subject": ["foo", "bar"], "object": ["foo", "bar"]},
{"subject": ["foo", "bar"], "object": ["foo", "bar"]},
],
# gbif-dwc
"gbif-dwc:identifiedByID": ["foo", "bar"],
"gbif-dwc:recordedByID": ["foo", "bar"],
},
)
3 changes: 3 additions & 0 deletions site/zenodo_rdm/legacy/deserializers/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def _imprint(data):
"thesis:university": university,
}

# Add the legacy custom fields
custom_fields.update(metadata.get("custom", {}))

clear_none(custom_fields)

if custom_fields:
Expand Down
20 changes: 20 additions & 0 deletions site/zenodo_rdm/legacy/serializers/schemas/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class MetadataSchema(Schema):
references = fields.Method("dump_reference")
language = fields.Method("dump_languages")

custom = fields.Method("dump_custom_fields")

@pre_dump
def resolve_communities(self, data, **kwargs):
"""Resolve communities for the draft/record."""
Expand Down Expand Up @@ -379,6 +381,24 @@ def dump_languages(self, obj):
# Zenodo-RDM implements ISO-639-2 so no mapping is needed.
return languages[0]["id"]

def dump_custom_fields(self, obj):
"""Dump custom fields."""
custom_fields = obj.get("custom_fields", {})
return {
k: v
for k, v in custom_fields.items()
if not k.startswith(
(
"legacy:",
"thesis:",
"imprint:",
"meeting:",
"journal:",
"part_of:",
)
)
} or missing


class LegacySchema(Schema):
"""Legacy schema."""
Expand Down

0 comments on commit 75e4c98

Please sign in to comment.