Skip to content

Commit ccd6c73

Browse files
committed
Fix validation on context of cli
1 parent 1c14752 commit ccd6c73

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

caltechdata_api/cli.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def get_funding_entries():
140140
def validate_funder_identifier(funder_identifier):
141141
response = requests.get(f"https://api.ror.org/organizations/{funder_identifier}")
142142
if response.status_code == 200:
143-
return True
143+
return response.json().get("name")
144144
else:
145145
return False
146146

@@ -157,7 +157,8 @@ def get_funding_details():
157157
award_title = get_user_input("Enter the award title for funding: ")
158158
while True:
159159
funder_identifier = get_user_input("Enter the funder ROR (https://ror.org): ")
160-
if validate_funder_identifier(funder_identifier):
160+
name = validate_funder_identifier(funder_identifier)
161+
if name:
161162
break
162163
else:
163164
print(
@@ -169,6 +170,7 @@ def get_funding_details():
169170
return {
170171
"awardNumber": award_number,
171172
"awardTitle": award_title,
173+
"funderName": name,
172174
"funderIdentifier": funder_identifier,
173175
"funderIdentifierType": "ROR",
174176
}
@@ -194,9 +196,18 @@ def parse_arguments():
194196
if license_number.isdigit() and 1 <= int(license_number) <= 8:
195197
# Valid license number selected
196198
args["license"] = {
197-
"1": "cc0-1.0",
198-
"2": "cc-by-4.0",
199-
"3": "cc-by-nc-4.0",
199+
"1": {
200+
"rights": "Creative Commons Zero v1.0 Universal",
201+
"rightsIdentifier": "cc0-1.0",
202+
},
203+
"2": {
204+
"rights": "Creative Commons Attribution v4.0 Universal",
205+
"rightsIdentifier": "cc-by-4.0",
206+
},
207+
"3": {
208+
"rights": "Creative Commons Attribution Non-Commercial v4.0 Universal",
209+
"rightsIdentifier": "cc-by-nc-4.0",
210+
},
200211
}[license_number]
201212
break
202213
else:
@@ -259,9 +270,11 @@ def get_names(orcid):
259270
return family_name, given_name
260271

261272

262-
def write_s3cmd_config(access_key, secret_key, endpoint):
273+
def write_s3cmd_config(endpoint):
263274
configf = os.path.join(home_directory, ".s3cfg")
264275
if not os.path.exists(configf):
276+
access_key = get_user_input("Enter the access key: ")
277+
secret_key = get_user_input("Enter the secret key: ")
265278
with open(configf, "w") as file:
266279
file.write(
267280
f"""[default]
@@ -286,9 +299,7 @@ def upload_supporting_file(record_id=None):
286299
endpoint = "sdsc.osn.xsede.org"
287300
path = "ini230004-bucket01/"
288301
if not record_id:
289-
access_key = get_user_input("Enter the access key: ")
290-
secret_key = get_user_input("Enter the secret key: ")
291-
write_s3cmd_config(access_key, secret_key, endpoint)
302+
write_s3cmd_config(endpoint)
292303
print("""S3 connection configured.""")
293304
break
294305
endpoint = f"https://{endpoint}/"
@@ -478,9 +489,7 @@ def create_record(production):
478489
],
479490
"types": {"resourceType": "", "resourceTypeGeneral": "Dataset"},
480491
"rightsList": [
481-
{
482-
"rightsIdentifier": args["license"],
483-
}
492+
args["license"],
484493
],
485494
"fundingReferences": args["fundingReferences"],
486495
"schemaVersion": "http://datacite.org/schema/kernel-4",

caltechdata_api/customize_schema.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -415,24 +415,7 @@ def validate_metadata(json_record):
415415
"Each entry in 'titles' must be a dictionary with a 'title' key."
416416
)
417417

418-
# Check for 'publication_date'
419-
if "publicationYear" not in json_record and "dates" not in json_record:
420-
errors.append(
421-
"A publication date is required ('publicationYear' or 'dates' field is missing)."
422-
)
423-
if "dates" in json_record:
424-
if not isinstance(json_record["dates"], list):
425-
errors.append("'dates' should be a list.")
426-
else:
427-
for date_entry in json_record["dates"]:
428-
if (
429-
not isinstance(date_entry, dict)
430-
or "dateType" not in date_entry
431-
or "date" not in date_entry
432-
):
433-
errors.append(
434-
"Each entry in 'dates' must be a dictionary with 'dateType' and 'date' keys."
435-
)
418+
# Publication date is handled by customize function
436419

437420
# Check for 'creators'
438421
if "creators" not in json_record:

0 commit comments

Comments
 (0)