Skip to content

Commit

Permalink
Merge pull request #261 from dandi/rf-identifiers2
Browse files Browse the repository at this point in the history
Upgrade to datacite v4.5 serialization from inveniosoftware
  • Loading branch information
yarikoptic authored Dec 11, 2024
2 parents 9812ced + c48079c commit 395bc5b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
28 changes: 16 additions & 12 deletions dandischema/datacite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,14 @@ def to_datacite(
if publish:
attributes["event"] = "publish"

attributes["identifiers"] = [
# TODO: the first element is ignored, not sure how to fix it...
{"identifier": f"https://doi.org/{meta.doi}", "identifierType": "DOI"},
attributes["alternateIdentifiers"] = [
{
"identifier": f"https://identifiers.org/{meta.id}",
"identifierType": "URL",
"alternateIdentifier": f"https://identifiers.org/{meta.id}",
"alternateIdentifierType": "URL",
},
{
"identifier": str(meta.url),
"identifierType": "URL",
"alternateIdentifier": str(meta.url),
"alternateIdentifierType": "URL",
},
]

Expand All @@ -98,7 +96,13 @@ def to_datacite(
attributes["descriptions"] = [
{"description": meta.description, "descriptionType": "Abstract"}
]
attributes["publisher"] = "DANDI Archive"
attributes["publisher"] = {
"name": "DANDI Archive",
"schemeUri": "https://scicrunch.org/resolver/",
"publisherIdentifier": "https://scicrunch.org/resolver/RRID:SCR_017571",
"publisherIdentifierScheme": "RRID",
"lang": "en",
}
attributes["publicationYear"] = str(meta.datePublished.year)
# not sure about it dandi-api had "resourceTypeGeneral": "NWB"
attributes["types"] = {
Expand All @@ -110,7 +114,7 @@ def to_datacite(
# assuming that all licenses are from SPDX?
attributes["rightsList"] = [
{
"schemeURI": "https://spdx.org/licenses/",
"schemeUri": "https://spdx.org/licenses/",
"rightsIdentifierScheme": "SPDX",
"rightsIdentifier": el.name,
}
Expand Down Expand Up @@ -147,7 +151,7 @@ def to_datacite(
contr_dict: Dict[str, Any] = {
"name": contr_el.name,
"contributorName": contr_el.name,
"schemeURI": "orcid.org",
"schemeUri": "orcid.org",
}
if isinstance(contr_el, Person):
contr_dict["nameType"] = "Personal"
Expand All @@ -163,7 +167,7 @@ def to_datacite(
contr_dict["affiliation"] = []
if getattr(contr_el, "identifier"):
orcid_dict = {
"nameIdentifier": contr_el.identifier,
"nameIdentifier": f"https://orcid.org/{contr_el.identifier}",
"nameIdentifierScheme": "ORCID",
"schemeUri": "https://orcid.org/",
}
Expand Down Expand Up @@ -252,7 +256,7 @@ def to_datacite(


@lru_cache()
def _get_datacite_schema(version_id: str = "datacite-4.3-17-gaa5db56") -> Any:
def _get_datacite_schema(version_id: str = "inveniosoftware-4.5-81-g160250d") -> Any:
"""Load datacite schema based on the version id provided."""
schema_folder = Path(__file__).parent / "schema"
return json.loads((schema_folder / f"{version_id}.json").read_text())
Expand Down
46 changes: 27 additions & 19 deletions dandischema/datacite/tests/test_datacite.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,16 @@ def test_datacite(dandi_id: str, schema: Any) -> None:
1,
{"description": "testing", "descriptionType": "Abstract"},
),
"publisher": (None, "DANDI Archive"),
"publisher": (
None,
{
"name": "DANDI Archive",
"publisherIdentifier": "https://scicrunch.org/resolver/RRID:SCR_017571",
"publisherIdentifierScheme": "RRID",
"schemeUri": "https://scicrunch.org/resolver/",
"lang": "en",
},
),
"rightsList": (
1,
{"rightsIdentifierScheme": "SPDX", "rightsIdentifier": "CC_BY_40"},
Expand Down Expand Up @@ -302,7 +311,7 @@ def test_datacite(dandi_id: str, schema: Any) -> None:
"name": "A_last, A_first",
"nameIdentifiers": [
{
"nameIdentifier": "0000-0001-0000-0000",
"nameIdentifier": "https://orcid.org/0000-0001-0000-0000",
"nameIdentifierScheme": "ORCID",
"schemeUri": "https://orcid.org/",
}
Expand All @@ -316,7 +325,7 @@ def test_datacite(dandi_id: str, schema: Any) -> None:
"contributorType": "Other",
"nameIdentifiers": [
{
"nameIdentifier": "0000-0001-0000-0000",
"nameIdentifier": "https://orcid.org/0000-0001-0000-0000",
"nameIdentifierScheme": "ORCID",
"schemeUri": "https://orcid.org/",
}
Expand Down Expand Up @@ -423,7 +432,7 @@ def test_datacite_publish(metadata_basic: Dict[str, Any]) -> None:
"givenName": "A_first",
"name": "A_last, A_first",
"nameType": "Personal",
"schemeURI": "orcid.org",
"schemeUri": "orcid.org",
}
],
"creators": [
Expand All @@ -434,40 +443,39 @@ def test_datacite_publish(metadata_basic: Dict[str, Any]) -> None:
"givenName": "A_first",
"name": "A_last, A_first",
"nameType": "Personal",
"schemeURI": "orcid.org",
"schemeUri": "orcid.org",
}
],
"descriptions": [
{"description": "testing", "descriptionType": "Abstract"}
],
"doi": f"10.80507/dandi.{dandi_id_noprefix}/{version}",
"identifiers": [
"alternateIdentifiers": [
{
"identifier": (
f"https://doi.org/10.80507"
f"/dandi.{dandi_id_noprefix}/{version}"
),
"identifierType": "DOI",
},
{
"identifier": f"https://identifiers.org/{dandi_id}/{version}",
"identifierType": "URL",
"alternateIdentifier": f"https://identifiers.org/{dandi_id}/{version}",
"alternateIdentifierType": "URL",
},
{
"identifier": (
"alternateIdentifier": (
f"https://dandiarchive.org/dandiset"
f"/{dandi_id_noprefix}/{version}"
),
"identifierType": "URL",
"alternateIdentifierType": "URL",
},
],
"publicationYear": "1970",
"publisher": "DANDI Archive",
"publisher": {
"name": "DANDI Archive",
"publisherIdentifier": "https://scicrunch.org/resolver/RRID:SCR_017571",
"publisherIdentifierScheme": "RRID",
"schemeUri": "https://scicrunch.org/resolver/",
"lang": "en",
},
"rightsList": [
{
"rightsIdentifier": "CC_BY_40",
"rightsIdentifierScheme": "SPDX",
"schemeURI": "https://spdx.org/licenses/",
"schemeUri": "https://spdx.org/licenses/",
}
],
"schemaVersion": "http://datacite.org/schema/kernel-4",
Expand Down

0 comments on commit 395bc5b

Please sign in to comment.