Skip to content
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
4 changes: 2 additions & 2 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4538,7 +4538,7 @@ def _get_entity_visibility(normalized_entity_type, entity_dict):
return entity_visibility


'''
"""
Retrieve the organ, donor, or sample metadata information associated with a Dataset, based
up the user's authorization to access the Dataset.

Expand All @@ -4561,7 +4561,7 @@ def _get_entity_visibility(normalized_entity_type, entity_dict):
-------
list
A dictionary containing the metadata properties the Dataset associated data.
'''
"""
def _get_dataset_associated_metadata(dataset_dict, dataset_visibility, valid_user_token, request, associated_data: str):

# Confirm the associated data requested is supported by this method.
Expand Down
71 changes: 43 additions & 28 deletions src/schema/schema_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def get_all_entity_types():


"""
Get the superclass (if defined) of the given entity class
Get the optional superclass (if defined) of the given entity class

Parameters
----------
Expand All @@ -209,32 +209,40 @@ def get_entity_superclass(normalized_entity_class):

all_entity_types = get_all_entity_types()

if normalized_entity_class in all_entity_types:
if 'superclass' in _schema['ENTITIES'][normalized_entity_class]:
normalized_superclass = normalize_entity_type(_schema['ENTITIES'][normalized_entity_class]['superclass'])
if normalized_entity_class not in all_entity_types:
msg = f"Unrecognized value of 'normalized_entity_class': {normalized_entity_class}"
logger.error(msg)
raise ValueError(msg)

if normalized_superclass not in all_entity_types:
msg = f"Invalid 'superclass' value defined for {normalized_entity_class}: {normalized_superclass}"
logger.error(msg)
raise ValueError(msg)
else:
# Since the 'superclass' property is optional, we just log the warning message, no need to bubble up
msg = f"The 'superclass' property is not defined for entity class: {normalized_entity_class}"
logger.warning(msg)
if 'superclass' in _schema['ENTITIES'][normalized_entity_class]:
normalized_superclass = normalize_entity_type(_schema['ENTITIES'][normalized_entity_class]['superclass'])

# Additional check to ensure no schema yaml mistake
if normalized_superclass not in all_entity_types:
msg = f"Invalid 'superclass' value defined for {normalized_entity_class}: {normalized_superclass}"
logger.error(msg)
raise ValueError(msg)

return normalized_superclass


def entity_type_instanceof(entity_type: str, entity_class: str) -> bool:
"""
Determine if the Entity type with 'entity_type' is an instance of 'entity_class'.
Use this function if you already have the Entity type. Use entity_instanceof(uuid, class)
if you just have the Entity uuid.
"""
Determine if the Entity type with 'entity_type' is an instance of 'entity_class'.
Use this function if you already have the Entity type. Use `entity_instanceof(uuid, class)`
if you just have the Entity uuid.

:param entity_type: from Entity
:param entity_class: found in .yaml file
:return: True or False
"""
Parameters
----------
entity_type : str
The superclass
entity_class : str
The subclass

Returns
-------
bool
"""
def entity_type_instanceof(entity_type: str, entity_class: str) -> bool:
if entity_type is None:
return False

Expand All @@ -247,14 +255,21 @@ def entity_type_instanceof(entity_type: str, entity_class: str) -> bool:
return False


def entity_instanceof(entity_uuid: str, entity_class: str) -> bool:
"""
Determine if the Entity with 'entity_uuid' is an instance of 'entity_class'.
"""
Determine if the Entity with 'entity_uuid' is an instance of 'entity_class'.

:param entity_uuid: from Entity
:param entity_class: found in .yaml file
:return: True or False
"""
Parameters
----------
entity_uuid : str
The uuid of the given entity
entity_class : str
The superclass

Returns
-------
bool
"""
def entity_instanceof(entity_uuid: str, entity_class: str) -> bool:
entity_type: str =\
schema_neo4j_queries.get_entity_type(get_neo4j_driver_instance(), entity_uuid.strip())
return entity_type_instanceof(entity_type, entity_class)
Expand Down
4 changes: 2 additions & 2 deletions src/schema/schema_neo4j_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
The neo4j database connection pool
entity_type : str
One of the normalized entity types: Dataset, Collection, Sample, Donor
superclass : str
The normalized entity superclass type if defined, None by default
entity_data_dict : dict
The target Entity node to be created
superclass : str
The normalized entity superclass type if defined, None by default

Returns
-------
Expand Down