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 get_collection_datasets to exclude fields in a list in schema constants #769

Merged
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: 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
Loading