Skip to content

Commit

Permalink
Merge pull request #770 from hubmapconsortium/Derek-Furst/remove-data…
Browse files Browse the repository at this point in the history
…set-fields-from-collection

modified get_collection_datasets to exclude fields in a list in schem…
  • Loading branch information
yuanzhou authored Dec 10, 2024
2 parents c9714a3 + 61fc015 commit 4126cde
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/schema/schema_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class SchemaConstants(object):

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

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

# Define an enumeration to classify an entity's visibility, which can be combined with
# authorization info when verify operations on a request.
class DataVisibilityEnum(Enum):
Expand Down
8 changes: 5 additions & 3 deletions src/schema/schema_neo4j_queries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from neo4j.exceptions import TransactionError
from schema.schema_constants import SchemaConstants
import logging

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -1184,9 +1185,10 @@ def get_dataset_upload(neo4j_driver, uuid):
def get_collection_datasets(neo4j_driver, uuid):
results = []

fields_to_omit = SchemaConstants.DATASETS_OMITTED_FIELDS
query = (f"MATCH (e:Dataset)-[:IN_COLLECTION]->(c:Collection) "
f"WHERE c.uuid = '{uuid}' "
f"RETURN apoc.coll.toSet(COLLECT(e)) AS {record_field_name}")
f"RETURN COLLECT(apoc.create.vNode(labels(e), apoc.map.removeKeys(properties(e), {fields_to_omit}))) AS {record_field_name}")

logger.info("======get_collection_datasets() query======")
logger.info(query)
Expand Down Expand Up @@ -1389,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
if property_key:
query = (f"MATCH (e:Dataset)-[:IN_UPLOAD]->(s:Upload) "
f"WHERE s.uuid = '{uuid}' "
Expand All @@ -1399,7 +1401,7 @@ def get_upload_datasets(neo4j_driver, uuid, property_key = None):
else:
query = (f"MATCH (e:Dataset)-[:IN_UPLOAD]->(s:Upload) "
f"WHERE s.uuid = '{uuid}' "
f"RETURN apoc.coll.toSet(COLLECT(e)) AS {record_field_name}")
f"RETURN COLLECT(apoc.create.vNode(labels(e), apoc.map.removeKeys(properties(e), {fields_to_omit}))) AS {record_field_name}")

logger.info("======get_upload_datasets() query======")
logger.info(query)
Expand Down

0 comments on commit 4126cde

Please sign in to comment.