Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ba1be71
Update cli.py
RohanBhattaraiNP Sep 23, 2024
1bff778
Update caltechdata_write.py
RohanBhattaraiNP Sep 23, 2024
65bc264
Merge pull request #1 from caltechlibrary/main
RohanBhattaraiNP Sep 24, 2024
a31d86f
Update caltechdata_write.py
RohanBhattaraiNP Sep 24, 2024
8b742cc
Update cli.py
RohanBhattaraiNP Sep 25, 2024
bf5ca3c
Update customize_schema.py
RohanBhattaraiNP Sep 25, 2024
d248c29
Merge pull request #2 from caltechlibrary/main
RohanBhattaraiNP Sep 26, 2024
f46700a
Update customize_schema.py
RohanBhattaraiNP Sep 26, 2024
d62c278
Update cli.py
RohanBhattaraiNP Sep 26, 2024
a57a075
Update caltechdata_write.py
RohanBhattaraiNP Sep 26, 2024
f0f40e3
Update cli.py
RohanBhattaraiNP Sep 26, 2024
687e098
Update customize_schema.py
RohanBhattaraiNP Oct 25, 2024
8693d66
Update customize_schema.py
RohanBhattaraiNP Oct 25, 2024
3426b40
Create generator.py
RohanBhattaraiNP Oct 25, 2024
f54d1e4
Add files via upload
RohanBhattaraiNP Oct 25, 2024
08a092f
Delete caltechdata_api/tester directory
RohanBhattaraiNP Oct 25, 2024
586f7bf
Create code.py
RohanBhattaraiNP Oct 25, 2024
055292e
Validator
RohanBhattaraiNP Oct 25, 2024
8804e3d
Delete caltechdata_api/tester/code.py
RohanBhattaraiNP Oct 25, 2024
f2ede3b
edit in caltech_write.py to test the function
RohanBhattaraiNP Oct 25, 2024
757cfb0
Create files
RohanBhattaraiNP Oct 25, 2024
098913e
Create files
RohanBhattaraiNP Oct 25, 2024
fc95460
Delete caltechdata_api/tester/datacite43 directory
RohanBhattaraiNP Oct 25, 2024
613f194
Add files via upload
RohanBhattaraiNP Oct 25, 2024
5e154b8
Create file.py
RohanBhattaraiNP Oct 25, 2024
782480e
Add files via upload
RohanBhattaraiNP Oct 25, 2024
f332483
Merge branch 'main' into main
RohanBhattaraiNP Oct 25, 2024
005d9cb
Add files via upload
RohanBhattaraiNP Nov 3, 2024
ed93fa8
Merge pull request #3 from caltechlibrary/main
RohanBhattaraiNP Nov 8, 2024
4f08a54
Add updated CITATION.cff from codemeta.json file
RohanBhattaraiNP Nov 8, 2024
735e74a
Update cli.py
RohanBhattaraiNP Nov 8, 2024
6c4a5e5
Update test_unit.py
RohanBhattaraiNP Nov 8, 2024
e617296
Create hehe.py
RohanBhattaraiNP Nov 8, 2024
ccf9552
Add files via upload
RohanBhattaraiNP Nov 8, 2024
947c91b
Delete tests/data/invalid_datacite43/hehe.py
RohanBhattaraiNP Nov 8, 2024
596651c
Create bot.py
RohanBhattaraiNP Nov 8, 2024
88bee6b
Delete caltechdata_api/tester directory
RohanBhattaraiNP Nov 8, 2024
d1230dc
Update cli.py
RohanBhattaraiNP Nov 8, 2024
7c8a434
Update tester.py
RohanBhattaraiNP Nov 8, 2024
0b25f18
Update caltechdata_write.py
RohanBhattaraiNP Nov 8, 2024
070da79
Update customize_schema.py
RohanBhattaraiNP Nov 8, 2024
1aed23c
Update customize_schema.py
RohanBhattaraiNP Nov 8, 2024
7716bfe
Update caltechdata_write.py
RohanBhattaraiNP Nov 8, 2024
6a696cb
Update test_unit.py
RohanBhattaraiNP Nov 8, 2024
31dcc99
Update bot.py
RohanBhattaraiNP Nov 8, 2024
2b74fff
Update cli.py
RohanBhattaraiNP Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ authors:
abstract: Python wrapper for CaltechDATA API.
repository-code: "https://github.com/caltechlibrary/caltechdata_api"
type: software
doi: 10.22002/wfjr5-kw507
version: 1.8.2
license-url: "https://data.caltech.edu/license"
keywords:
- GitHub
- metadata
- software
- InvenioRDM
date-released: 2024-11-06
date-released: 2024-11-08
5 changes: 4 additions & 1 deletion caltechdata_api/caltechdata_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ def caltechdata_write(
# Make draft and publish
result = requests.post(url + "/api/records", headers=headers, json=data)
if result.status_code != 201:
raise Exception(result.text)
if result.status_code == 400 and "Referer checking failed" in result.text:
raise Exception("Token is incorrect or missing referer.")
else:
raise Exception(result.text)
idv = result.json()["id"]
publish_link = result.json()["links"]["publish"]

Expand Down
3 changes: 2 additions & 1 deletion caltechdata_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests
import s3fs
from caltechdata_api import caltechdata_write, caltechdata_edit
from .md_to_json import parse_readme_to_json
from md_to_json import parse_readme_to_json
import json
import os
from cryptography.fernet import Fernet
Expand Down Expand Up @@ -469,6 +469,7 @@ def create_record(production):
"descriptions": [
{"description": args["description"], "descriptionType": "Abstract"}
],
"publisher": "CaltechDATA",
"creators": [
{
"affiliation": [
Expand Down
135 changes: 126 additions & 9 deletions caltechdata_api/customize_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,20 +393,12 @@ def validate_metadata(json_record):
"""
errors = []

# Check for 'types' and 'resourceTypeGeneral'
if "types" not in json_record:
errors.append("'types' field is missing.")
elif not isinstance(json_record["types"], dict):
errors.append("'types' field should be a dictionary.")
elif "resourceTypeGeneral" not in json_record["types"]:
errors.append("'resourceTypeGeneral' field is missing in 'types'.")

# Check for 'title'
if "titles" not in json_record:
errors.append("'titles' field is missing.")
elif not isinstance(json_record["titles"], list) or len(json_record["titles"]) == 0:
errors.append("'titles' should be a non-empty list.")
else:

# Ensure each title is a dictionary with 'title' field
for title in json_record["titles"]:
if not isinstance(title, dict) or "title" not in title:
Expand Down Expand Up @@ -480,6 +472,7 @@ def validate_metadata(json_record):
errors.append("'relatedIdentifiers' should be a list.")
else:
for related_id in json_record["relatedIdentifiers"]:

if (
not isinstance(related_id, dict)
or "relatedIdentifier" not in related_id
Expand All @@ -493,6 +486,76 @@ def validate_metadata(json_record):
if not isinstance(json_record["rightsList"], list):
errors.append("'rightsList' should be a list.")
else:

for right in json_record["rightsList"]:
if not isinstance(right, dict) or "rights" not in right:
errors.append("Each 'rightsList' entry must have 'rights'.")
if "rightsURI" in right and not isinstance(right["rightsURI"], str):
errors.append("'rightsURI' should be a string.")

# Check for 'subjects'
if "subjects" in json_record:
if not isinstance(json_record["subjects"], list):
errors.append("'subjects' should be a list.")
else:
for subject in json_record["subjects"]:
if not isinstance(subject, dict) or "subject" not in subject:
errors.append("Each 'subject' must have a 'subject' key.")

# Check for 'dates'
if "dates" not in json_record:
errors.append("'dates' field is missing.")
elif not isinstance(json_record["dates"], list) or len(json_record["dates"]) == 0:
errors.append("'dates' should be a non-empty list.")
else:
for date in json_record["dates"]:
if (
not isinstance(date, dict)
or "date" not in date
or "dateType" not in date
):
errors.append("Each 'date' must have 'date' and 'dateType'.")

# Check for 'identifiers'
if "identifiers" not in json_record:
errors.append("'identifiers' field is missing.")
elif (
not isinstance(json_record["identifiers"], list)
or len(json_record["identifiers"]) == 0
):
errors.append("'identifiers' should be a non-empty list.")
else:
for identifier in json_record["identifiers"]:
if (
not isinstance(identifier, dict)
or "identifier" not in identifier
or "identifierType" not in identifier
):
errors.append(
"Each 'identifier' must have 'identifier' and 'identifierType'."
)

# Check for 'creators'
if "creators" not in json_record:
errors.append("'creators' field is missing.")
elif (
not isinstance(json_record["creators"], list)
or len(json_record["creators"]) == 0
):
errors.append("'creators' should be a non-empty list.")
else:
for creator in json_record["creators"]:
if not isinstance(creator, dict) or "name" not in creator:
errors.append("Each 'creator' must have 'name'.")
if "affiliation" in creator:
if not isinstance(creator["affiliation"], list):
errors.append("'affiliation' in 'creators' should be a list.")
for affiliation in creator["affiliation"]:
if not isinstance(affiliation, dict) or "name" not in affiliation:
errors.append(
"Each 'affiliation' in 'creators' must have a 'name'."
)

for rights in json_record["rightsList"]:
if not isinstance(rights, dict) or "rights" not in rights:
errors.append(
Expand All @@ -504,6 +567,60 @@ def validate_metadata(json_record):
if not isinstance(json_record["geoLocations"], list):
errors.append("'geoLocations' should be a list.")
else:

for geo_loc in json_record["geoLocations"]:
if not isinstance(geo_loc, dict) or "geoLocationPlace" not in geo_loc:
errors.append("Each 'geoLocation' must have 'geoLocationPlace'.")
if "geoLocationPoint" in geo_loc:
point = geo_loc["geoLocationPoint"]
if (
not isinstance(point, dict)
or "pointLatitude" not in point
or "pointLongitude" not in point
):
errors.append(
"'geoLocationPoint' must have 'pointLatitude' and 'pointLongitude'."
)

# Check for 'formats'
if "formats" in json_record and (
not isinstance(json_record["formats"], list) or len(json_record["formats"]) == 0
):
errors.append("'formats' should be a non-empty list.")

# Check for 'language'
if "language" in json_record:
if not isinstance(json_record["language"], str):
errors.append("'language' should be a string.")

# Check for 'version'
if "version" in json_record and not isinstance(json_record["version"], str):
errors.append("'version' should be a string.")

# Check for 'publisher'
if "publisher" not in json_record:
errors.append("'publisher' field is missing.")
elif not isinstance(json_record["publisher"], str):
errors.append("'publisher' should be a string.")

# Check for 'publicationYear'
if "publicationYear" not in json_record:
errors.append("'publicationYear' field is missing.")
elif not isinstance(json_record["publicationYear"], str):
errors.append("'publicationYear' should be a string.")

# Check for 'types'
if "types" not in json_record:
errors.append("'types' field is missing.")
elif not isinstance(json_record["types"], dict):
errors.append("'types' should be a dictionary.")
else:
if "resourceTypeGeneral" not in json_record["types"]:
errors.append("'types' must have 'resourceTypeGeneral'.")
if "resourceType" in json_record["types"] and not isinstance(
json_record["types"]["resourceType"], str
):
errors.append("'resourceType' should be a string if provided.")
for location in json_record["geoLocations"]:
if not isinstance(location, dict):
errors.append("Each entry in 'geoLocations' must be a dictionary.")
Expand Down
Loading