Skip to content

Commit

Permalink
Merge pull request #783 from hubmapconsortium/Derek-Furst/remove-offe…
Browse files Browse the repository at this point in the history
…nding-fields

Derek furst/remove offending fields
  • Loading branch information
yuanzhou authored Jan 16, 2025
2 parents 1eac2fc + 09a9076 commit a35b992
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/schema/schema_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SchemaConstants(object):

DOI_BASE_URL = 'https://doi.org/'

DATASETS_OMITTED_FIELDS = ['ingest_metadata', 'metadata', 'files']
OMITTED_FIELDS = ['ingest_metadata', 'files']

# Define an enumeration to classify an entity's visibility, which can be combined with
# authorization info when verify operations on a request.
Expand Down
31 changes: 23 additions & 8 deletions src/schema/schema_neo4j_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def filter_ancestors_by_type(neo4j_driver, direct_ancestor_uuids, entity_type):
"""
def get_children(neo4j_driver, uuid, property_key = None):
results = []

fields_to_omit = SchemaConstants.OMITTED_FIELDS
if property_key:
query = (f"MATCH (e:Entity)-[:ACTIVITY_INPUT]->(:Activity)-[:ACTIVITY_OUTPUT]->(child:Entity) "
# The target entity can't be a Lab
Expand Down Expand Up @@ -193,7 +193,10 @@ def get_children(neo4j_driver, uuid, property_key = None):
else:
# Convert the list of nodes to a list of dicts
results = nodes_to_dicts(record[record_field_name])

if fields_to_omit:
for node_dict in results:
for field in fields_to_omit:
node_dict.pop(field, None)
return results


Expand All @@ -216,7 +219,7 @@ def get_children(neo4j_driver, uuid, property_key = None):
"""
def get_parents(neo4j_driver, uuid, property_key = None):
results = []

fields_to_omit = SchemaConstants.OMITTED_FIELDS
if property_key:
query = (f"MATCH (e:Entity)<-[:ACTIVITY_OUTPUT]-(:Activity)<-[:ACTIVITY_INPUT]-(parent:Entity) "
# Filter out the Lab entities
Expand Down Expand Up @@ -245,6 +248,10 @@ def get_parents(neo4j_driver, uuid, property_key = None):
else:
# Convert the list of nodes to a list of dicts
results = nodes_to_dicts(record[record_field_name])
if fields_to_omit:
for node_dict in results:
for field in fields_to_omit:
node_dict.pop(field, None)

return results

Expand Down Expand Up @@ -380,7 +387,7 @@ def get_tuplets(neo4j_driver, uuid, property_key=None):
"""
def get_ancestors(neo4j_driver, uuid, property_key = None):
results = []

fields_to_omit = SchemaConstants.OMITTED_FIELDS
if property_key:
query = (f"MATCH (e:Entity)<-[:ACTIVITY_INPUT|ACTIVITY_OUTPUT*]-(ancestor:Entity) "
# Filter out the Lab entities
Expand Down Expand Up @@ -410,6 +417,11 @@ def get_ancestors(neo4j_driver, uuid, property_key = None):
# Convert the list of nodes to a list of dicts
results = nodes_to_dicts(record[record_field_name])

if fields_to_omit:
for node_dict in results:
for field in fields_to_omit:
node_dict.pop(field, None)

return results

"""
Expand All @@ -431,7 +443,7 @@ def get_ancestors(neo4j_driver, uuid, property_key = None):
"""
def get_descendants(neo4j_driver, uuid, property_key = None):
results = []

fields_to_omit = SchemaConstants.OMITTED_FIELDS
if property_key:
query = (f"MATCH (e:Entity)-[:ACTIVITY_INPUT|ACTIVITY_OUTPUT*]->(descendant:Entity) "
# The target entity can't be a Lab
Expand Down Expand Up @@ -460,7 +472,10 @@ def get_descendants(neo4j_driver, uuid, property_key = None):
else:
# Convert the list of nodes to a list of dicts
results = nodes_to_dicts(record[record_field_name])

if fields_to_omit:
for node_dict in results:
for field in fields_to_omit:
node_dict.pop(field, None)
return results


Expand Down Expand Up @@ -1185,7 +1200,7 @@ def get_dataset_upload(neo4j_driver, uuid):
def get_collection_datasets(neo4j_driver, uuid):
results = []

fields_to_omit = SchemaConstants.DATASETS_OMITTED_FIELDS
fields_to_omit = SchemaConstants.OMITTED_FIELDS
query = (f"MATCH (e:Dataset)-[:IN_COLLECTION]->(c:Collection) "
f"WHERE c.uuid = '{uuid}' "
f"RETURN COLLECT(apoc.create.vNode(labels(e), apoc.map.removeKeys(properties(e), {fields_to_omit}))) AS {record_field_name}")
Expand Down Expand Up @@ -1391,7 +1406,7 @@ def unlink_datasets_from_upload(neo4j_driver, upload_uuid, dataset_uuids_list):
"""
def get_upload_datasets(neo4j_driver, uuid, property_key = None):
results = []
fields_to_omit = SchemaConstants.DATASETS_OMITTED_FIELDS
fields_to_omit = SchemaConstants.OMITTED_FIELDS
if property_key:
query = (f"MATCH (e:Dataset)-[:IN_UPLOAD]->(s:Upload) "
f"WHERE s.uuid = '{uuid}' "
Expand Down

0 comments on commit a35b992

Please sign in to comment.