Skip to content

Commit 571c7a8

Browse files
committed
Improvements to map current edit workflow
1 parent 5c80ad6 commit 571c7a8

File tree

5 files changed

+46
-19
lines changed

5 files changed

+46
-19
lines changed

caltechdata_api/caltechdata_edit.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ def caltechdata_edit(
3636
if isinstance(ids, str):
3737
ids = [ids]
3838

39-
data = customize_schema.customize_schema(
40-
copy.deepcopy(metadata), schema=schema)
39+
data = customize_schema.customize_schema(copy.deepcopy(metadata), schema=schema)
4140
if production == True:
42-
url = "https://data.caltech.edu/"
41+
url = "https://data.caltech.edu"
4342
verify = True
4443
else:
45-
url = "https://data.caltechlibrary.dev/"
44+
url = "https://data.caltechlibrary.dev"
4645
verify = True
4746

4847
headers = {
@@ -90,8 +89,19 @@ def caltechdata_edit(
9089

9190
else:
9291
# just update metadata
92+
# result = requests.post(
93+
# url + "/api/records/" + idv + "/draft",
94+
# headers=headers,
95+
# verify=verify,
96+
# )
97+
# if result.status_code != 200:
98+
# print(result.text)
99+
# exit()
100+
# print(result.json())
101+
# exit()
102+
# print(url + "/api/records/" + idv + "/draft")
93103
result = requests.get(
94-
url + "/api/records/" + idv + "/draft",
104+
url + "/api/records/" + idv,
95105
headers=headers,
96106
verify=verify,
97107
)
@@ -100,6 +110,7 @@ def caltechdata_edit(
100110
exit()
101111
# We want files to stay the same as the existing record
102112
data["files"] = result.json()["files"]
113+
print(url + "/api/records/" + idv + "/draft")
103114
result = requests.put(
104115
url + "/api/records/" + idv + "/draft",
105116
headers=headers,
@@ -112,6 +123,7 @@ def caltechdata_edit(
112123

113124
if publish:
114125
publish_link = f"{url}/api/records/{idv}/draft/actions/publish"
126+
print(publish_link)
115127
result = requests.post(publish_link, headers=headers, verify=verify)
116128
if result.status_code != 202:
117129
print(result.text)

caltechdata_api/customize_schema.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,31 @@ def customize_schema_rdm(json_record):
221221
if "identifiers" in json_record:
222222
identifiers = []
223223
for identifier in json_record["identifiers"]:
224-
if identifier["identifierType"] != "DOI":
224+
if identifier["identifierType"] == "DOI":
225+
doi = identifier["identifier"]
226+
prefix = doi.split("/")[0]
227+
if prefix == "10.22002":
228+
pids = {
229+
"doi": {
230+
"identifier": doi,
231+
"provider": "datacite",
232+
"client": "datacite",
233+
}
234+
}
235+
else:
236+
pids = {
237+
"doi": {
238+
"identifier": doi,
239+
"provider": "external",
240+
}
241+
}
242+
elif identifier["identifierType"] == "oai":
243+
# All OAI identifiers are system generated, and are not accepted
244+
# via this API
245+
print("Discarding oai identifier")
246+
else:
225247
identifier["scheme"] = identifiertypes[identifier.pop("identifierType")]
226248
identifiers.append(identifier)
227-
else:
228-
pids = {
229-
"doi": {
230-
"identifier": identifier["identifier"],
231-
"provider": "external",
232-
}
233-
}
234249
json_record["identifiers"] = identifiers
235250

236251
if "relatedIdentifiers" in json_record:

caltechdata_api/vocabularies/identifier_types.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@
9595
en: W3ID
9696
- id: cdid
9797
props:
98-
datacite: CaltechDATA_Identifier
98+
datacite: cdid
9999
title:
100100
en: CALTECHDATA_ID

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def package_files(package, directory):
5858
REQUIRES_PYTHON = ">=3.6.0"
5959

6060
# What packages are required for this module to be executed?
61-
REQUIRED = ["requests", "datacite>1.1.0", "tqdm", "pyyaml"]
61+
REQUIRED = ["requests", "datacite>1.1.0", "tqdm>=4.62.3", "pyyaml"]
6262

6363
# What packages are optional?
6464
EXTRAS = {

outdated/write.py renamed to write.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
parser.add_argument(
1010
"json_file", nargs=1, help="file name for json DataCite metadata file"
1111
)
12-
parser.add_argument("-ids", nargs="*", help="CaltechDATA IDs")
1312
parser.add_argument("-fnames", nargs="*", help="New Files")
14-
parser.add_argument("-schema", default="40", help="Metadata Schema")
13+
parser.add_argument("-schema", default="43", help="Metadata Schema")
1514

1615
args = parser.parse_args()
1716

1817
# Get access token as environment variable
19-
token = os.environ["TINDTOK"]
18+
token = os.environ["RDMTOK"]
2019

2120
metaf = open(args.json_file[0], "r")
2221
metadata = json.load(metaf)
2322

2423
production = True
24+
publish = False
2525

26-
response = caltechdata_write(metadata, token, args.fnames, production, args.schema)
26+
response = caltechdata_write(metadata, token, args.fnames, production, args.schema, publish)
2727
print(response)

0 commit comments

Comments
 (0)