1414from jsonschema import Draft7Validator
1515import requests
1616
17- from ..models import NAME_PATTERN , Organization , Person , PublishedDandiset , RoleType
17+ from ..models import NAME_PATTERN , Organization , Person , PublishedDandiset , RoleType , Dandiset
1818
1919DATACITE_CONTRTYPE = {
2020 "ContactPerson" ,
6464}
6565DATACITE_MAP = {el .lower (): el for el in DATACITE_IDENTYPE }
6666
67-
6867def 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