Skip to content

Commit

Permalink
Merge pull request #726 from hubmapconsortium/Derek-Furst/initialize-…
Browse files Browse the repository at this point in the history
…get-organ-types

Derek furst/initialize get organ types
  • Loading branch information
yuanzhou authored Aug 27, 2024
2 parents 0f15329 + 0f133b7 commit dd04af3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
11 changes: 5 additions & 6 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3342,7 +3342,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 @@ -3662,7 +3662,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 @@ -3858,7 +3858,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 @@ -5554,9 +5554,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

0 comments on commit dd04af3

Please sign in to comment.