@@ -691,7 +691,7 @@ def get_next_revision_uuid(neo4j_driver, uuid):
691691
692692
693693"""
694- Get a list of associated dataset and publication uuids for a given collection
694+ Get a list of associated Datasets and Publications (subclass of Dataset) uuids for a given collection
695695
696696Parameters
697697----------
@@ -707,7 +707,7 @@ def get_next_revision_uuid(neo4j_driver, uuid):
707707list
708708 A list of datasets and publications
709709"""
710- def get_collection_associated_entities (neo4j_driver , uuid , property_key = None ):
710+ def get_collection_associated_datasets (neo4j_driver , uuid , property_key = None ):
711711 results = []
712712
713713 if property_key :
@@ -719,7 +719,7 @@ def get_collection_associated_entities(neo4j_driver, uuid, property_key = None):
719719 f"WHERE c.uuid = '{ uuid } ' "
720720 f"RETURN apoc.coll.toSet(COLLECT(e)) AS { record_field_name } " )
721721
722- logger .info ("======get_collection_associated_entities () query======" )
722+ logger .info ("======get_collection_associated_datasets () query======" )
723723 logger .info (query )
724724
725725 with neo4j_driver .session () as session :
@@ -735,50 +735,6 @@ def get_collection_associated_entities(neo4j_driver, uuid, property_key = None):
735735
736736 return results
737737
738- """
739- Get a list of associated dataset and publication uuids for a given collection
740-
741- Parameters
742- ----------
743- neo4j_driver : neo4j.Driver object
744- The neo4j database connection pool
745- uuid : str
746- The uuid of collection
747- property_key : str
748- A target property key for result filtering
749-
750- Returns
751- -------
752- list
753- A list of datasets and publications
754- """
755- def get_collection_associated_entities (neo4j_driver , uuid , property_key = None ):
756- results = []
757-
758- if property_key :
759- query = (f"MATCH (e:Entity)-[:IN_COLLECTION|:USES_DATA]->(c:Collection) "
760- f"WHERE c.uuid = '{ uuid } ' "
761- f"RETURN apoc.coll.toSet(COLLECT(e.{ property_key } )) AS { record_field_name } " )
762- else :
763- query = (f"MATCH (e:Entity)-[:IN_COLLECTION|:USES_DATA]->(c:Collection) "
764- f"WHERE c.uuid = '{ uuid } ' "
765- f"RETURN apoc.coll.toSet(COLLECT(e)) AS { record_field_name } " )
766-
767- logger .info ("======get_collection_associated_entities() query======" )
768- logger .info (query )
769-
770- with neo4j_driver .session () as session :
771- record = session .read_transaction (execute_readonly_tx , query )
772-
773- if record and record [record_field_name ]:
774- if property_key :
775- # Just return the list of property values from each entity node
776- results = record [record_field_name ]
777- else :
778- # Convert the list of nodes to a list of dicts
779- results = nodes_to_dicts (record [record_field_name ])
780-
781- return results
782738
783739"""
784740Get a list of associated collection uuids for a given dataset or publication (subclass)
@@ -870,15 +826,13 @@ def get_publication_associated_collection(neo4j_driver, uuid):
870826 The neo4j database connection pool
871827uuid : str
872828 The uuid of dataset
873- property_key : str
874- A target property key for result filtering
875829
876830Returns
877831-------
878832dict
879833 A Upload dict
880834"""
881- def get_dataset_upload (neo4j_driver , uuid , property_key = None ):
835+ def get_dataset_upload (neo4j_driver , uuid ):
882836 result = {}
883837
884838 query = (f"MATCH (e:Entity)-[:IN_UPLOAD]->(s:Upload) "
@@ -1111,18 +1065,27 @@ def unlink_datasets_from_upload(neo4j_driver, upload_uuid, dataset_uuids_list):
11111065 The neo4j database connection pool
11121066uuid : str
11131067 The uuid of Upload
1068+ property_key : str
1069+ A target property key for result filtering
11141070
11151071Returns
11161072-------
11171073list
11181074 The list containing associated dataset dicts
11191075"""
1120- def get_upload_datasets (neo4j_driver , uuid ):
1076+ def get_upload_datasets (neo4j_driver , uuid , property_key = None ):
11211077 results = []
11221078
1123- query = (f"MATCH (e:Dataset)-[:IN_UPLOAD]->(s:Upload) "
1124- f"WHERE s.uuid = '{ uuid } ' "
1125- f"RETURN apoc.coll.toSet(COLLECT(e)) AS { record_field_name } " )
1079+ if property_key :
1080+ query = (f"MATCH (e:Dataset)-[:IN_UPLOAD]->(s:Upload) "
1081+ f"WHERE s.uuid = '{ uuid } ' "
1082+ # COLLECT() returns a list
1083+ # apoc.coll.toSet() reruns a set containing unique nodes
1084+ f"RETURN apoc.coll.toSet(COLLECT(e.{ property_key } )) AS { record_field_name } " )
1085+ else :
1086+ query = (f"MATCH (e:Dataset)-[:IN_UPLOAD]->(s:Upload) "
1087+ f"WHERE s.uuid = '{ uuid } ' "
1088+ f"RETURN apoc.coll.toSet(COLLECT(e)) AS { record_field_name } " )
11261089
11271090 logger .info ("======get_upload_datasets() query======" )
11281091 logger .info (query )
@@ -1131,8 +1094,12 @@ def get_upload_datasets(neo4j_driver, uuid):
11311094 record = session .read_transaction (execute_readonly_tx , query )
11321095
11331096 if record and record [record_field_name ]:
1134- # Convert the list of nodes to a list of dicts
1135- results = nodes_to_dicts (record [record_field_name ])
1097+ if property_key :
1098+ # Just return the list of property values from each entity node
1099+ results = record [record_field_name ]
1100+ else :
1101+ # Convert the list of nodes to a list of dicts
1102+ results = nodes_to_dicts (record [record_field_name ])
11361103
11371104 return results
11381105
0 commit comments