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

Reworked get_organ_types #725

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 5 additions & 6 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3273,7 +3273,7 @@ def get_prov_info():
distinct_organ_uuid_list.append(item['uuid'])

organ_code = item['organ'].upper()
validate_organ_code(organ_code, organ_types_dict)
validate_organ_code(organ_code)

distinct_organ_type_list.append(organ_types_dict[organ_code].lower())
internal_dict[HEADER_ORGAN_HUBMAP_ID] = distinct_organ_hubmap_id_list
Expand Down Expand Up @@ -3593,7 +3593,7 @@ def get_prov_info_for_dataset(id):
distinct_organ_uuid_list.append(item['uuid'])

organ_code = item['organ'].upper()
validate_organ_code(organ_code, organ_types_dict )
validate_organ_code(organ_code)

distinct_organ_type_list.append(organ_types_dict[organ_code].lower())
internal_dict[HEADER_ORGAN_HUBMAP_ID] = distinct_organ_hubmap_id_list
Expand Down Expand Up @@ -3789,7 +3789,7 @@ def sankey_data():
internal_dict[HEADER_DATASET_GROUP_NAME] = dataset[HEADER_DATASET_GROUP_NAME]

organ_code = dataset[HEADER_ORGAN_TYPE].upper()
validate_organ_code(organ_code, organ_types_dict)
validate_organ_code(organ_code)

internal_dict[HEADER_ORGAN_TYPE] = organ_types_dict[organ_code].lower()

Expand Down Expand Up @@ -5456,9 +5456,8 @@ def access_level_prefix_dir(dir_name):
----------
organ_code : str
"""
def validate_organ_code(organ_code, organ_types_dict=None):
if organ_types_dict is None:
organ_types_dict = schema_manager.get_organ_types()
def validate_organ_code(organ_code):
organ_types_dict = schema_manager.get_organ_types()
if not organ_code.isalpha() or not len(organ_code) == 2:
internal_server_error(f"Invalid organ code {organ_code}. Must be 2-letter alphabetic code")

Expand Down
38 changes: 22 additions & 16 deletions src/schema/schema_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
_neo4j_driver = None
_memcached_client = None
_memcached_prefix = None
_organ_types = None


####################################################################################################
Expand Down Expand Up @@ -2160,29 +2161,34 @@ def delete_memcached_cache(uuids_list):
"""
def get_organ_types():
global _ontology_api_url
global _organ_types

target_url = _ontology_api_url + SchemaConstants.ONTOLOGY_API_ORGAN_TYPES_ENDPOINT
if _organ_types is None:
target_url = _ontology_api_url + SchemaConstants.ONTOLOGY_API_ORGAN_TYPES_ENDPOINT

# Use Memcached to improve performance
response = make_request_get(target_url, internal_token_used = True)
# Use Memcached to improve performance
response = make_request_get(target_url, internal_token_used = True)

# Invoke .raise_for_status(), an HTTPError will be raised with certain status codes
response.raise_for_status()
# Invoke .raise_for_status(), an HTTPError will be raised with certain status codes
response.raise_for_status()

if response.status_code == 200:
return response.json()
else:
# Log the full stack trace, prepend a line with our message
logger.exception("Unable to make a request to query the organ types via ontology-api")
if response.status_code == 200:
_organ_types = response.json()
return _organ_types
else:
# Log the full stack trace, prepend a line with our message
logger.exception("Unable to make a request to query the organ types via ontology-api")

logger.debug("======get_organ_types() status code from ontology-api======")
logger.debug(response.status_code)
logger.debug("======get_organ_types() status code from ontology-api======")
logger.debug(response.status_code)

logger.debug("======get_organ_types() response text from ontology-api======")
logger.debug(response.text)
logger.debug("======get_organ_types() response text from ontology-api======")
logger.debug(response.text)

# Also bubble up the error message from ontology-api
raise requests.exceptions.RequestException(response.text)
# Also bubble up the error message from ontology-api
raise requests.exceptions.RequestException(response.text)
else:
return _organ_types


"""
Expand Down
Loading