Skip to content

Commit 8ad7ae6

Browse files
authored
Merge pull request #666 from hubmapconsortium/Derek-Furst/limit-component-dataset
Derek furst/limit component dataset
2 parents e115e1a + 3dc6b47 commit 8ad7ae6

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3978,13 +3978,14 @@ def multiple_components():
39783978
direct_ancestor_uuids = json_data_dict.get('direct_ancestor_uuids')
39793979
if direct_ancestor_uuids is None or not isinstance(direct_ancestor_uuids, list) or len(direct_ancestor_uuids) !=1:
39803980
bad_request_error(f"Required field 'direct_ancestor_uuids' must be a list. This list may only contain 1 item: a string representing the uuid of the direct ancestor")
3981-
39823981
# validate existence of direct ancestors.
39833982
for direct_ancestor_uuid in direct_ancestor_uuids:
39843983
direct_ancestor_dict = query_target_entity(direct_ancestor_uuid, user_token)
39853984
if direct_ancestor_dict.get('entity_type').lower() != "dataset":
39863985
bad_request_error(f"Direct ancestor is of type: {direct_ancestor_dict.get('entity_type')}. Must be of type 'dataset'.")
3987-
3986+
dataset_has_component_children = app_neo4j_queries.dataset_has_component_children(neo4j_driver_instance, direct_ancestor_uuid)
3987+
if dataset_has_component_children:
3988+
bad_request_error(f"The dataset with uuid {direct_ancestor_uuid} already has component children dataset(s)")
39883989
# validate that there is at least one component dataset
39893990
if len(json_data_dict.get('datasets')) < 1:
39903991
bad_request_error(f"'datasets' field must contain at leawst 1 dataset.")

src/app_neo4j_queries.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,31 @@ def get_entities_by_type(neo4j_driver, entity_type, property_key = None):
9797

9898
return results
9999

100+
101+
"""
102+
Determine if given dataset has componet children
103+
104+
Parameters
105+
----------
106+
neo4j_driver : neo4j.Driver object
107+
The neo4j database connection pool
108+
dataset_uuid : str
109+
The uuid of the given dataset
110+
111+
112+
Returns
113+
-------
114+
boolean
115+
"""
116+
def dataset_has_component_children(neo4j_driver, dataset_uuid):
117+
query = (f"MATCH p=(ds1:Dataset)<-[:ACTIVITY_OUTPUT]-(a:Activity)<-[:ACTIVITY_INPUT]-(ds2:Dataset) "
118+
f"WHERE ds2.uuid = '{dataset_uuid}' AND a.creation_action = 'Multi-Assay Split' "
119+
f"RETURN (count(p) > 0) as {record_field_name}")
120+
121+
with neo4j_driver.session() as session:
122+
result = session.run(query).value()
123+
return result[0]
124+
100125
"""
101126
Retrieve the ancestor organ(s) of a given entity
102127

0 commit comments

Comments
 (0)