Skip to content

Commit 4486afa

Browse files
authored
Enhance validation for contributors and creators
1 parent 3d925bc commit 4486afa

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

caltechdata_api/customize_schema.py

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -408,32 +408,6 @@ def validate_metadata(json_record):
408408

409409
# Publication date is handled by customize function
410410

411-
# Check for 'creators'
412-
if "creators" not in json_record:
413-
errors.append("'creators' field is missing.")
414-
elif (
415-
not isinstance(json_record["creators"], list)
416-
or len(json_record["creators"]) == 0
417-
):
418-
errors.append("'creators' should be a non-empty list.")
419-
else:
420-
for creator in json_record["creators"]:
421-
if not isinstance(creator, dict) or "name" not in creator:
422-
errors.append(
423-
"Each creator in 'creators' must be a dictionary with a 'name' key."
424-
)
425-
426-
# Check for 'contributors'
427-
if "contributors" in json_record:
428-
if not isinstance(json_record["contributors"], list):
429-
errors.append("'contributors' should be a list.")
430-
else:
431-
for contributor in json_record["contributors"]:
432-
if not isinstance(contributor, dict) or "name" not in contributor:
433-
errors.append(
434-
"Each contributor must be a dictionary with a 'name' key."
435-
)
436-
437411
# Check for 'resourceType'
438412
if "resourceType" not in json_record["types"]:
439413
errors.append("'resourceType' field is missing in 'types'.")
@@ -545,8 +519,15 @@ def validate_metadata(json_record):
545519
errors.append("'creators' should be a non-empty list.")
546520
else:
547521
for creator in json_record["creators"]:
548-
if not isinstance(creator, dict) or "name" not in creator:
549-
errors.append("Each 'creator' must have 'name'.")
522+
if not isinstance(creator, dict):
523+
errors.append("Each 'creator' must be a dictionry")
524+
if "nameType" in creator:
525+
if creator["nameType"] == "Organizational"
526+
if "name" not in creator:
527+
errors.append("Each organizational 'creator' must have 'name'.")
528+
else
529+
if "familyName" not in creator:
530+
errors.append("Each 'creator' must have a "familyName" or have type Organizational")
550531
if "affiliation" in creator:
551532
if not isinstance(creator["affiliation"], list):
552533
errors.append("'affiliation' in 'creators' should be a list.")
@@ -556,12 +537,33 @@ def validate_metadata(json_record):
556537
"Each 'affiliation' in 'creators' must have a 'name'."
557538
)
558539

559-
for rights in json_record["rightsList"]:
560-
if not isinstance(rights, dict) or "rights" not in rights:
561-
errors.append(
562-
"Each entry in 'rightsList' must be a dictionary with a 'rights' key."
563-
)
564-
540+
# Check for 'contributors'
541+
if "contributors" in json_record:
542+
if (
543+
not isinstance(json_record["contributors"], list)
544+
or len(json_record["contributors"]) == 0
545+
):
546+
errors.append("'creators' should be a non-empty list.")
547+
else:
548+
for contributor in json_record["contributors"]:
549+
if not isinstance(contributor, dict):
550+
errors.append("Each 'contributor' must be a dictionry")
551+
if "nameType" in contributor:
552+
if contributor["nameType"] == "Organizational"
553+
if "name" not in creator:
554+
errors.append("Each organizational 'contributor' must have 'name'.")
555+
else
556+
if "familyName" not in contributor:
557+
errors.append("Each 'contributor' must have a "familyName" or have type Organizational")
558+
if "affiliation" in contributor:
559+
if not isinstance(contributor["affiliation"], list):
560+
errors.append("'affiliation' in 'contributors' should be a list.")
561+
for affiliation in contributor["affiliation"]:
562+
if not isinstance(affiliation, dict) or "name" not in affiliation:
563+
errors.append(
564+
"Each 'affiliation' in 'contributors' must have a 'name'."
565+
)
566+
565567
# Check for 'geoLocations'
566568
if "geoLocations" in json_record:
567569
if not isinstance(json_record["geoLocations"], list):

0 commit comments

Comments
 (0)