@@ -51,7 +51,7 @@ def caltechdata_accept(ids, token=None, production=False):
5151
5252
5353def caltechdata_edit (
54- ids ,
54+ idv ,
5555 metadata = {},
5656 token = None ,
5757 files = {},
@@ -61,7 +61,7 @@ def caltechdata_edit(
6161 file_links = [],
6262 s3 = None ,
6363 community = None ,
64- new_version = False
64+ new_version = False ,
6565):
6666
6767 # If no token is provided, get from RDMTOK environment variable
@@ -71,10 +71,6 @@ def caltechdata_edit(
7171 # If files is a string - change to single value array
7272 if isinstance (files , str ) == True :
7373 files = [files ]
74- if isinstance (ids , int ):
75- ids = [str (ids )]
76- if isinstance (ids , str ):
77- ids = [ids ]
7874
7975 if file_links :
8076 metadata = add_file_links (metadata , file_links )
@@ -85,6 +81,7 @@ def caltechdata_edit(
8581 else :
8682 repo_prefix = "10.33569"
8783 pids = {}
84+ oai = False
8885 if "identifiers" in metadata :
8986 for identifier in metadata ["identifiers" ]:
9087 if identifier ["identifierType" ] == "DOI" :
@@ -107,6 +104,12 @@ def caltechdata_edit(
107104 "identifier" : identifier ["identifier" ],
108105 "provider" : "oai" ,
109106 }
107+ oai = True
108+ if oai == False :
109+ pids ["oai" ] = {
110+ "identifier" : f"oai:data.caltech.edu:{ idv } " ,
111+ "provider" : "oai" ,
112+ }
110113 metadata ["pids" ] = pids
111114
112115 data = customize_schema .customize_schema (copy .deepcopy (metadata ), schema = schema )
@@ -125,77 +128,69 @@ def caltechdata_edit(
125128 "Content-type" : "application/octet-stream" ,
126129 }
127130
128- completed = []
131+ if files or new_version :
132+ # We need to make new version
133+ data ["files" ] = {"enabled" : True }
134+ result = requests .post (
135+ url + "/api/records/" + idv + "/versions" ,
136+ headers = headers ,
137+ )
138+ if result .status_code != 201 :
139+ raise Exception (result .text )
140+ # Get the id of the new version
141+ idv = result .json ()["id" ]
142+ # Update metadata
143+ result = requests .put (
144+ url + "/api/records/" + idv + "/draft" ,
145+ headers = headers ,
146+ json = data ,
147+ )
129148
130- for idv in ids :
149+ file_link = result .json ()["links" ]["files" ]
150+ write_files_rdm (files , file_link , headers , f_headers )
131151
132- if files or new_version :
133- # We need to make new version
134- data ["files" ] = {"enabled" : True }
152+ else :
153+ # Check for existing draft
154+ result = requests .get (
155+ url + "/api/records/" + idv + "/draft" ,
156+ headers = headers ,
157+ )
158+ if result .status_code != 200 :
159+ # We make a draft
135160 result = requests .post (
136- url + "/api/records/" + idv + "/versions" ,
161+ url + "/api/records/" + idv + "/draft" ,
162+ json = data ,
137163 headers = headers ,
138164 )
139165 if result .status_code != 201 :
140166 raise Exception (result .text )
141- # Get the id of the new version
142- idv = result .json ()["id" ]
143- # Update metadata
144- result = requests .put (
145- url + "/api/records/" + idv + "/draft" ,
146- headers = headers ,
147- json = data ,
148- )
149-
150- file_link = result .json ()["links" ]["files" ]
151- write_files_rdm (files , file_link , headers , f_headers )
152-
153- else :
154- # Check for existing draft
155167 result = requests .get (
156- url + "/api/records/" + idv + "/draft" ,
157- headers = headers ,
158- )
159- if result .status_code != 200 :
160- # We make a draft
161- result = requests .post (
162- url + "/api/records/" + idv + "/draft" ,
163- json = data ,
164- headers = headers ,
165- )
166- if result .status_code != 201 :
167- raise Exception (result .text )
168- result = requests .get (
169- url + "/api/records/" + idv ,
170- headers = headers ,
171- )
172- if result .status_code != 200 :
173- raise Exception (result .text )
174- # We want files to stay the same as the existing record
175- data ["files" ] = result .json ()["files" ]
176- result = requests .put (
177- url + "/api/records/" + idv + "/draft" ,
168+ url + "/api/records/" + idv ,
178169 headers = headers ,
179- json = data ,
180170 )
181171 if result .status_code != 200 :
182172 raise Exception (result .text )
173+ # We want files to stay the same as the existing record
174+ data ["files" ] = result .json ()["files" ]
175+ result = requests .put (
176+ url + "/api/records/" + idv + "/draft" ,
177+ headers = headers ,
178+ json = data ,
179+ )
180+ if result .status_code != 200 :
181+ raise Exception (result .text )
183182
184- if community :
185- review_link = result .json ()["links" ]["review" ]
186- result = send_to_community (review_link , data , headers , publish , community )
187- doi = result .json ()["pids" ]["doi" ]["identifier" ]
188- completed .append (doi )
189- elif publish :
190- publish_link = f"{ url } /api/records/{ idv } /draft/actions/publish"
191- result = requests .post (publish_link , headers = headers )
192- if result .status_code != 202 :
193- raise Exception (result .text )
194- doi = result .json ()["pids" ]["doi" ]["identifier" ]
195- completed .append (doi )
196- else :
197- completed .append (idv )
198- if len (completed ) == 1 :
199- return completed [0 ]
183+ if community :
184+ review_link = result .json ()["links" ]["review" ]
185+ result = send_to_community (review_link , data , headers , publish , community )
186+ doi = result .json ()["pids" ]["doi" ]["identifier" ]
187+ return doi
188+ elif publish :
189+ publish_link = f"{ url } /api/records/{ idv } /draft/actions/publish"
190+ result = requests .post (publish_link , headers = headers )
191+ if result .status_code != 202 :
192+ raise Exception (result .text )
193+ doi = result .json ()["pids" ]["doi" ]["identifier" ]
194+ return doi
200195 else :
201- return completed
196+ return idv
0 commit comments