Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure no w3id.org loop; use data portal API #403

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Changes from all commits
Commits
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
16 changes: 10 additions & 6 deletions nmdc_runtime/api/endpoints/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,23 @@ def get_object_info(
then try https://data.microbiomedata.org/details/sample/nmdc:{object_id}
3. if object_id.startswith some known typecode
then try https://api.microbiomedata.org/nmdcschema/ids/nmdc:{object_id}
4. try https://w3id.org/nmdc/{object_id}
4. try https://microbiomedata.github.io/nmdc-schema/{object_id}
5. try mdb.objects.find_one({"id": object_id})
"""
if object_id.startswith("sty"):
url_to_try = f"https://data.microbiomedata.org/details/study/nmdc:{object_id}"
rv = requests.head(url_to_try, allow_redirects=True)
url_to_try = f"https://data.microbiomedata.org/api/study/nmdc:{object_id}"
rv = requests.get(
url_to_try, allow_redirects=True
) # TODO use HEAD when enabled upstream
if rv.status_code != 404:
return RedirectResponse(
url_to_try, status_code=status.HTTP_307_TEMPORARY_REDIRECT
)
elif object_id.startswith("bsm"):
url_to_try = f"https://data.microbiomedata.org/details/sample/nmdc:{object_id}"
rv = requests.head(url_to_try, allow_redirects=True)
url_to_try = f"https://data.microbiomedata.org/api/biosample/nmdc:{object_id}"
rv = requests.get(
url_to_try, allow_redirects=True
) # TODO use HEAD when enabled upstream
if rv.status_code != 404:
return RedirectResponse(
url_to_try, status_code=status.HTTP_307_TEMPORARY_REDIRECT
Expand All @@ -140,7 +144,7 @@ def get_object_info(
url_to_try, status_code=status.HTTP_307_TEMPORARY_REDIRECT
)

url_to_try = f"https://w3id.org/nmdc/{object_id}"
url_to_try = f"https://microbiomedata.github.io/nmdc-schema/{object_id}"
rv = requests.head(url_to_try, allow_redirects=True)
print(rv.status_code)
if rv.status_code != 404:
Expand Down