Skip to content

Commit 44ad5b5

Browse files
committed
enh: allow creation of dandiset dois (contrasted to a version doi)
1 parent c86c265 commit 44ad5b5

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

dandischema/datacite/__init__.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from jsonschema import Draft7Validator
1515
import requests
1616

17-
from ..models import NAME_PATTERN, Organization, Person, PublishedDandiset, RoleType
17+
from ..models import NAME_PATTERN, Organization, Person, PublishedDandiset, RoleType, Dandiset
1818

1919
DATACITE_CONTRTYPE = {
2020
"ContactPerson",
@@ -64,19 +64,26 @@
6464
}
6565
DATACITE_MAP = {el.lower(): el for el in DATACITE_IDENTYPE}
6666

67-
6867
def to_datacite(
6968
meta: Union[dict, PublishedDandiset],
69+
event: str = None,
7070
validate: bool = False,
71-
publish: bool = False,
71+
version_doi: bool = True,
7272
) -> dict:
73-
"""Convert published Dandiset metadata to Datacite"""
74-
if not isinstance(meta, PublishedDandiset):
73+
"""Convert published Dandiset metadata to DataCite payload."""
74+
if version_doi and not isinstance(meta, PublishedDandiset):
7575
meta = PublishedDandiset(**meta)
76+
elif not version_doi and not isinstance(meta, Dandiset):
77+
meta = Dandiset(**meta)
78+
7679

7780
attributes: Dict[str, Any] = {}
78-
if publish:
79-
attributes["event"] = "publish"
81+
82+
# None event means create a Draft DOI
83+
if event is not None:
84+
if event not in {"publish", "hide"}:
85+
raise ValueError("Invalid event value: must be 'publish' or 'hide'")
86+
attributes["event"] = event
8087

8188
attributes["alternateIdentifiers"] = [
8289
{
@@ -103,7 +110,8 @@ def to_datacite(
103110
"publisherIdentifierScheme": "RRID",
104111
"lang": "en",
105112
}
106-
attributes["publicationYear"] = str(meta.datePublished.year)
113+
if getattr(meta, "datePublished", None):
114+
attributes["publicationYear"] = str(meta.datePublished.year)
107115
# not sure about it dandi-api had "resourceTypeGeneral": "NWB"
108116
attributes["types"] = {
109117
"resourceType": "Neural Data",

0 commit comments

Comments
 (0)