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

modified omitted fields to not include metadata. Modified /ancestors … #785

Merged
merged 3 commits into from
Jan 17, 2025
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
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
24 changes: 12 additions & 12 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 All @@ -178,7 +178,7 @@ def get_children(neo4j_driver, uuid, property_key = None):
f"WHERE e.uuid='{uuid}' AND e.entity_type <> 'Lab' "
# COLLECT() returns a list
# apoc.coll.toSet() reruns a set containing unique nodes
f"RETURN apoc.coll.toSet(COLLECT(child)) AS {record_field_name}")
f"RETURN apoc.coll.toSet(COLLECT(apoc.create.vNode(labels(child), apoc.map.removeKeys(properties(child), {fields_to_omit})))) AS {record_field_name}")

logger.info("======get_children() query======")
logger.info(query)
Expand All @@ -193,7 +193,7 @@ 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])

return results


Expand All @@ -216,7 +216,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 All @@ -230,7 +230,7 @@ def get_parents(neo4j_driver, uuid, property_key = None):
f"WHERE e.uuid='{uuid}' AND parent.entity_type <> 'Lab' "
# COLLECT() returns a list
# apoc.coll.toSet() reruns a set containing unique nodes
f"RETURN apoc.coll.toSet(COLLECT(parent)) AS {record_field_name}")
f"RETURN apoc.coll.toSet(COLLECT(apoc.create.vNode(labels(parent), apoc.map.removeKeys(properties(parent), {fields_to_omit})))) AS {record_field_name}")

logger.info("======get_parents() query======")
logger.info(query)
Expand Down Expand Up @@ -380,7 +380,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 All @@ -394,7 +394,7 @@ def get_ancestors(neo4j_driver, uuid, property_key = None):
f"WHERE e.uuid='{uuid}' AND ancestor.entity_type <> 'Lab' "
# COLLECT() returns a list
# apoc.coll.toSet() reruns a set containing unique nodes
f"RETURN apoc.coll.toSet(COLLECT(ancestor)) AS {record_field_name}")
f"RETURN apoc.coll.toSet(COLLECT(apoc.create.vNode(labels(ancestor), apoc.map.removeKeys(properties(ancestor), {fields_to_omit})))) AS {record_field_name}")

logger.info("======get_ancestors() query======")
logger.info(query)
Expand Down Expand Up @@ -431,7 +431,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 All @@ -445,7 +445,7 @@ def get_descendants(neo4j_driver, uuid, property_key = None):
f"WHERE e.uuid='{uuid}' AND e.entity_type <> 'Lab' "
# COLLECT() returns a list
# apoc.coll.toSet() reruns a set containing unique nodes
f"RETURN apoc.coll.toSet(COLLECT(descendant)) AS {record_field_name}")
f"RETURN apoc.coll.toSet(COLLECT(apoc.create.vNode(labels(descendant), apoc.map.removeKeys(properties(descendant), {fields_to_omit})))) AS {record_field_name}")

logger.info("======get_descendants() query======")
logger.info(query)
Expand All @@ -460,7 +460,7 @@ 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])

return results


Expand Down Expand Up @@ -1185,7 +1185,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 +1391,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
Loading