Skip to content

Commit 655e98f

Browse files
authored
Merge pull request #966 from hubmapconsortium/Derek-Furst/resurrect-publication-collection-association
Derek furst/resurrect publication collection association
2 parents c814ca5 + 5b6c92e commit 655e98f

File tree

5 files changed

+87
-15
lines changed

5 files changed

+87
-15
lines changed

entity-api-spec.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,10 @@ components:
937937
type: string
938938
readOnly: true
939939
description: 'The email address of the person or process authenticated when creating the object.'
940+
associated_publication:
941+
type: object
942+
description: 'The publication associated with the given collection'
943+
readOnly: true
940944
created_by_user_sub:
941945
type: string
942946
readOnly: true

src/app.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5403,8 +5403,6 @@ def delete_cache(entity_uuid, entity_type):
54035403
dataset_upload_dict = schema_neo4j_queries.get_dataset_upload(neo4j_driver_instance, entity_uuid)
54045404

54055405
# For Publication, also delete cache of the associated collection
5406-
# NOTE: As of 5/30/2025, the [:USES_DATA] workaround has been deprecated.
5407-
# Still keep it in the code until further decision - Zhou
54085406
if entity_type == 'Publication':
54095407
publication_collection_dict = schema_neo4j_queries.get_publication_associated_collection(neo4j_driver_instance, entity_uuid)
54105408

src/schema/provenance_schema.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ ENTITIES:
308308
indexed: true
309309
description: "The displayname of globus group which the user who created this entity is a member of"
310310
before_create_trigger: set_group_name #same as group_uuid, except set group_name
311+
associated_publication:
312+
type: json_string #dict
313+
generated: true
314+
indexed: true
315+
transient: true
316+
description: "A JSON containing the UUID, HuBMAP_ID, and Title for the associated publication"
317+
on_read_trigger: get_collection_associated_publication
318+
on_index_trigger: get_collection_associated_publication
319+
311320

312321

313322
############################################# Dataset #############################################
@@ -786,9 +795,6 @@ ENTITIES:
786795
type: string
787796
indexed: true
788797
description: 'A DOI pointing to an Organ Mapping Antibody Panel relevant to this publication'
789-
790-
# NOTE: As of 5/30/2025, the [:USES_DATA] workaround has been deprecated.
791-
# Still keep it in the code until further decision - Zhou
792798
associated_collection:
793799
type: json_string # dict
794800
generated: true

src/schema/schema_neo4j_queries.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,6 @@ def get_parent_activity_uuid_from_entity(neo4j_driver, entity_uuid):
839839
the uuid of the associated collection
840840
"""
841841
def link_publication_to_associated_collection(neo4j_driver, entity_uuid, associated_collection_uuid):
842-
# NOTE: As of 5/30/2025, the [:USES_DATA] workaround has been deprecated.
843-
# Still keep it in the code until further decision - Zhou
844842
try:
845843
with neo4j_driver.session() as session:
846844
tx = session.begin_transaction()
@@ -1109,9 +1107,6 @@ def get_next_revision_uuids(neo4j_driver, uuid):
11091107
"""
11101108
def get_collection_associated_datasets(neo4j_driver, uuid, property_key = None):
11111109
results = []
1112-
1113-
# NOTE: As of 5/30/2025, the [:USES_DATA] workaround has been deprecated.
1114-
# Still keep it in the code until further decision - Zhou
11151110
if property_key:
11161111
query = (f"MATCH (e:Entity)-[:IN_COLLECTION|:USES_DATA]->(c:Collection) "
11171112
f"WHERE c.uuid = '{uuid}' "
@@ -1210,9 +1205,6 @@ def get_dataset_collections(neo4j_driver, uuid, property_key = None, properties_
12101205
"""
12111206
def get_publication_associated_collection(neo4j_driver, uuid):
12121207
result = {}
1213-
1214-
# NOTE: As of 5/30/2025, the [:USES_DATA] workaround has been deprecated.
1215-
# Still keep it in the code until further decision - Zhou
12161208
query = (f"MATCH (p:Publication)-[:USES_DATA]->(c:Collection) "
12171209
f"WHERE p.uuid = '{uuid}' "
12181210
f"RETURN c as {record_field_name}")
@@ -1229,6 +1221,41 @@ def get_publication_associated_collection(neo4j_driver, uuid):
12291221

12301222
return result
12311223

1224+
1225+
"""
1226+
Get the associated collection for a given publication
1227+
1228+
Parameters
1229+
----------
1230+
neo4j_driver : neo4j.Driver object
1231+
The neo4j database connection pool
1232+
uuid : str
1233+
The uuid of publication
1234+
property_key : str
1235+
A target property key for result filtering
1236+
1237+
Returns
1238+
-------
1239+
dict
1240+
A dictionary representation of the chosen values
1241+
"""
1242+
def get_collection_associated_publication(neo4j_driver, uuid):
1243+
result = {}
1244+
query = (f"MATCH (p:Publication)-[:USES_DATA]->(c:Collection) "
1245+
f"WHERE c.uuid = '{uuid}' "
1246+
f"RETURN {{uuid: p.uuid, hubmap_id: p.hubmap_id, title: p.title}} AS publication")
1247+
1248+
logger.info("=====get_collection_associated_publication() query======")
1249+
logger.debug(query)
1250+
1251+
with neo4j_driver.session() as session:
1252+
record = session.run(query).single()
1253+
if record:
1254+
result = record["publication"]
1255+
return result
1256+
1257+
1258+
12321259
"""
12331260
Get the associated Upload for a given dataset
12341261
@@ -2057,8 +2084,6 @@ def delete_ancestor_linkages_tx(neo4j_driver, entity_uuid, ancestor_uuids):
20572084
The uuid to target publication
20582085
"""
20592086
def _delete_publication_associated_collection_linkages_tx(tx, uuid):
2060-
# NOTE: As of 5/30/2025, the [:USES_DATA] workaround has been deprecated.
2061-
# Still keep it in the code until further decision - Zhou
20622087
query = (f"MATCH (p:Publication)-[r:USES_DATA]->(c:Collection) "
20632088
f"WHERE p.uuid = '{uuid}' "
20642089
f"DELETE r")

src/schema/schema_triggers.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,45 @@ def get_publication_associated_collection(property_key, normalized_type, request
830830
return property_key, schema_manager.normalize_entity_result_for_response(collection_dict)
831831

832832

833+
"""
834+
TriggerTypeEnum.ON_READ
835+
836+
Trigger event method of getting the associated publication for this collection
837+
838+
Parameters
839+
----------
840+
property_key : str
841+
The target property key
842+
normalized_type : str
843+
One of the types defined in the schema yaml: Dataset
844+
request_args: ImmutableMultiDict
845+
The Flask request.args passed in from application request
846+
user_token: str
847+
The user's globus nexus token
848+
existing_data_dict : dict
849+
A dictionary that contains all existing entity properties
850+
new_data_dict : dict
851+
A merged dictionary that contains all possible input data to be used
852+
853+
Returns
854+
-------
855+
str: The target property key
856+
dict: A dictionary representation of the associated publication with all the normalized information
857+
"""
858+
def get_collection_associated_publication(property_key, normalized_type, request_args, user_token, existing_data_dict, new_data_dict):
859+
if 'uuid' not in existing_data_dict:
860+
raise KeyError("Missing 'uuid' key in 'existing_data_dict' during calling 'get_collection_associated_publication()' trigger method.")
861+
862+
logger.info(f"Executing 'get_collection_associated_publication()' trigger method on uuid: {existing_data_dict['uuid']}")
863+
864+
publication_dict = schema_neo4j_queries.get_collection_associated_publication(schema_manager.get_neo4j_driver_instance(), existing_data_dict['uuid'])
865+
866+
# Get rid of the entity node properties that are not defined in the yaml schema
867+
# as well as the ones defined as `exposed: false` in the yaml schema
868+
return property_key, publication_dict
869+
870+
871+
833872
"""
834873
TriggerTypeEnum.ON_READ
835874

0 commit comments

Comments
 (0)