Skip to content

Commit 7475d85

Browse files
committed
Bug fixes for version handling
1 parent 247ea9d commit 7475d85

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

caltechdata_api/caltechdata_edit.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,18 @@ def caltechdata_edit(
8080
# Check if file links were provided in the metadata
8181
descriptions = []
8282
ex_file_links = []
83-
for d in metadata["descriptions"]:
84-
if d["description"].startswith("Files available via S3"):
85-
file_text = d["description"]
86-
file_list = file_text.split('href="')
87-
# Loop over links in description, skip header text
88-
for file in file_list[1:]:
89-
ex_file_links.append(file.split('"\n')[0])
90-
else:
91-
descriptions.append(d)
92-
# We remove file link descriptions, and re-add below
93-
metadata["descriptions"] = descriptions
83+
if "descriptions" in metadata:
84+
for d in metadata["descriptions"]:
85+
if d["description"].startswith("Files available via S3"):
86+
file_text = d["description"]
87+
file_list = file_text.split('href="')
88+
# Loop over links in description, skip header text
89+
for file in file_list[1:]:
90+
ex_file_links.append(file.split('"\n')[0])
91+
else:
92+
descriptions.append(d)
93+
# We remove file link descriptions, and re-add below
94+
metadata["descriptions"] = descriptions
9495

9596
# If user has provided file links as a cli option, we add those
9697
if file_links:
@@ -131,7 +132,8 @@ def caltechdata_edit(
131132
if existing.status_code != 200:
132133
raise Exception(f"Record {idv} does not exist, cannot edit")
133134

134-
status = existing.json()["status"]
135+
existing = existing.json()
136+
status = existing["status"]
135137

136138
# Determine whether we need a new version
137139
version = False
@@ -161,7 +163,7 @@ def caltechdata_edit(
161163
pids = {}
162164
oai = False
163165
doi = False
164-
if "identifiers" in metadata:
166+
if "identifiers" in metadata and version == False:
165167
for identifier in metadata["identifiers"]:
166168
if identifier["identifierType"] == "DOI":
167169
doi = True
@@ -198,9 +200,17 @@ def caltechdata_edit(
198200
"provider": "datacite",
199201
"client": "datacite",
200202
}
201-
metadata["pids"] = pids
202203

203-
data = customize_schema.customize_schema(metadata, schema=schema)
204+
# If no metadata is provided, use existing. Otherwise customize provided
205+
# metadata
206+
if metadata == {}:
207+
data = existing
208+
if version == True:
209+
# We want to have the system set new DOIs
210+
data["pids"] = {}
211+
else:
212+
metadata["pids"] = pids
213+
data = customize_schema.customize_schema(metadata, schema=schema)
204214

205215
if files:
206216
if default_preview:

caltechdata_api/caltechdata_write.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def send_to_community(review_link, data, headers, publish, community, message=No
113113
result = requests.put(review_link, json=data, headers=headers)
114114
if result.status_code != 200:
115115
raise Exception(result.text)
116-
submit_link = review_link.replace('/review','/actions/submit-review')
116+
submit_link = review_link.replace("/review", "/actions/submit-review")
117117
data = comment = {
118118
"payload": {
119119
"content": message,

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"codeRepository": "https://github.com/caltechlibrary/caltechdata_api",
77
"issueTracker": "https://github.com/caltechlibrary/caltechdata_api/issues",
88
"license": "https://data.caltech.edu/license",
9-
"version": "1.4.3",
9+
"version": "1.4.4",
1010
"author": [
1111
{
1212
"@type": "Person",

0 commit comments

Comments
 (0)