From 2843485d1f7ac60ba73925b8b6b232b1dd0294d7 Mon Sep 17 00:00:00 2001 From: DerekFurstPitt Date: Tue, 14 Nov 2023 11:30:11 -0500 Subject: [PATCH 1/2] work in progress previous_revisions and next revisions --- entity-api-spec.yaml | 7 +++ src/schema/provenance_schema.yaml | 14 ++++++ src/schema/schema_neo4j_queries.py | 74 ++++++++++++++++++++++++++++++ src/schema/schema_triggers.py | 72 +++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) diff --git a/entity-api-spec.yaml b/entity-api-spec.yaml index 8fd04211..2f5c401b 100644 --- a/entity-api-spec.yaml +++ b/entity-api-spec.yaml @@ -782,6 +782,13 @@ components: type: string readOnly: true description: "The uuid of next revision dataset" + previous_revision_uuids: + type: list + description: "The uuids of previous revision datasets. Can only be set at Create/POST time." + next_revision_uuids: + type: list + readOnly: true + description: "The uuids of next revision dataset" thumbnail_file: readOnly: true description: 'The dataset thumbnail file detail. Stored in db as a stringfied json, e.g., {"filename": "thumbnail.jpg", "file_uuid": "c35002f9c3d49f8b77e1e2cd4a01803d"}' diff --git a/src/schema/provenance_schema.yaml b/src/schema/provenance_schema.yaml index b72bf3a1..a88f3422 100644 --- a/src/schema/provenance_schema.yaml +++ b/src/schema/provenance_schema.yaml @@ -651,6 +651,13 @@ ENTITIES: description: "The uuid of previous revision dataset" after_create_trigger: link_to_previous_revision on_read_trigger: get_previous_revision_uuid + previous_revision_uuids: + type: list + transient: true + immutable: true + description: "The list of the uuids of previous revision datasets" + after_create_trigger: link_to_previous_revision + on_read_trigger: get_previous_revision_uuids next_revision_uuid: type: string generated: true @@ -658,6 +665,13 @@ ENTITIES: immutable: true description: "The uuid of next revision dataset" on_read_trigger: get_next_revision_uuid + next_revision_uuids: + type: list + generated: true + transient: true + immutable: true + description: "The list of the uuids of next revision datasets" + on_read_trigger: get_next_revision_uuids # No like image and metadata files handling for Donor/Sample # Dataset has only one thumbnail file thumbnail_file: diff --git a/src/schema/schema_neo4j_queries.py b/src/schema/schema_neo4j_queries.py index b23d33ba..3f9beb93 100644 --- a/src/schema/schema_neo4j_queries.py +++ b/src/schema/schema_neo4j_queries.py @@ -710,6 +710,44 @@ def get_previous_revision_uuid(neo4j_driver, uuid): return result +""" +Get the uuids of previous revision entities for a given entity + +Parameters +---------- +neo4j_driver : neo4j.Driver object + The neo4j database connection pool +uuid : str + The uuid of the entity + +Returns +------- +list + The previous revision uuids +""" +def get_previous_revision_uuids(neo4j_driver, uuid): + result = [] + + # Don't use [r:REVISION_OF] because + # Binding a variable length relationship pattern to a variable ('r') is deprecated + query = (f"MATCH (e:Entity)-[:REVISION_OF]->(previous_revision:Entity) " + f"WHERE e.uuid='{uuid}' " + f"RETURN COLLECT(previous_revision.uuid) AS {record_field_name}") + + logger.info("======get_previous_revision_uuids() query======") + logger.info(query) + + with neo4j_driver.session() as session: + record = session.read_transaction(execute_readonly_tx, query) + + if record and record[record_field_name]: + result = record[record_field_name] + + return result + + + + """ Get the uuid of next revision entity for a given entity @@ -746,6 +784,42 @@ def get_next_revision_uuid(neo4j_driver, uuid): return result +""" +Get the uuids of next revision entities for a given entity + +Parameters +---------- +neo4j_driver : neo4j.Driver object + The neo4j database connection pool +uuid : str + The uuid of the entity + +Returns +------- +list + The uuids of the next revision +""" +def get_next_revision_uuids(neo4j_driver, uuid): + result = [] + + # Don't use [r:REVISION_OF] because + # Binding a variable length relationship pattern to a variable ('r') is deprecated + query = (f"MATCH (e:Entity)<-[:REVISION_OF]-(next_revision:Entity) " + f"WHERE e.uuid='{uuid}' " + f"RETURN COLLECT(next_revision.uuid) AS {record_field_name}") + + logger.info("======get_next_revision_uuids() query======") + logger.info(query) + + with neo4j_driver.session() as session: + record = session.read_transaction(execute_readonly_tx, query) + + if record and record[record_field_name]: + result = record[record_field_name] + + return result + + """ Get a list of associated Datasets and Publications (subclass of Dataset) uuids for a given collection diff --git a/src/schema/schema_triggers.py b/src/schema/schema_triggers.py index 38cf61dc..d42f360a 100644 --- a/src/schema/schema_triggers.py +++ b/src/schema/schema_triggers.py @@ -1107,6 +1107,42 @@ def get_previous_revision_uuid(property_key, normalized_type, user_token, existi return property_key, previous_revision_uuid +""" +Trigger event method of getting the uuids of the previous revision datasets if they exist + +Parameters +---------- +property_key : str + The target property key +normalized_type : str + One of the types defined in the schema yaml: Dataset +user_token: str + The user's globus nexus token +existing_data_dict : dict + A dictionary that contains all existing entity properties +new_data_dict : dict + A merged dictionary that contains all possible input data to be used + +Returns +------- +str: The target property key +str: A list of the uuid strings of previous revision entity or an empty list if not found +""" + + +def get_previous_revision_uuids(property_key, normalized_type, user_token, existing_data_dict, new_data_dict): + if 'uuid' not in existing_data_dict: + raise KeyError( + "Missing 'uuid' key in 'existing_data_dict' during calling 'get_previous_revision_uuid()' trigger method.") + + logger.info(f"Executing 'get_previous_revision_uuids()' trigger method on uuid: {existing_data_dict['uuid']}") + + previous_revision_uuids = schema_neo4j_queries.get_previous_revision_uuids(schema_manager.get_neo4j_driver_instance(), + existing_data_dict['uuid']) + + return property_key, previous_revision_uuids + + """ Trigger event method of getting the uuid of the next version dataset if exists @@ -1139,6 +1175,42 @@ def get_next_revision_uuid(property_key, normalized_type, user_token, existing_d return property_key, next_revision_uuid +""" +Trigger event method of getting the uuids of the next version dataset if they exist + +Parameters +---------- +property_key : str + The target property key +normalized_type : str + One of the types defined in the schema yaml: Dataset +user_token: str + The user's globus nexus token +existing_data_dict : dict + A dictionary that contains all existing entity properties +new_data_dict : dict + A merged dictionary that contains all possible input data to be used + +Returns +------- +str: The target property key +str: The list of uuid strings of next version entity or empty string if not found +""" + + +def get_next_revision_uuids(property_key, normalized_type, user_token, existing_data_dict, new_data_dict): + if 'uuid' not in existing_data_dict: + raise KeyError( + "Missing 'uuid' key in 'existing_data_dict' during calling 'get_next_revision_uuid()' trigger method.") + + logger.info(f"Executing 'get_next_revision_uuid()' trigger method on uuid: {existing_data_dict['uuid']}") + + next_revision_uuids = schema_neo4j_queries.get_next_revision_uuids(schema_manager.get_neo4j_driver_instance(), + existing_data_dict['uuid']) + + return property_key, next_revision_uuids + + """ Trigger event method to commit thumbnail file saved that were previously uploaded via ingest-api From c7d7851fb3357c61f8692303b6299722debb4af5 Mon Sep 17 00:00:00 2001 From: DerekFurstPitt Date: Tue, 21 Nov 2023 14:27:40 -0500 Subject: [PATCH 2/2] implemented previous_revision_uuids and next_revision_uuids properties --- src/schema/provenance_schema.yaml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/schema/provenance_schema.yaml b/src/schema/provenance_schema.yaml index 7900a552..073116e7 100644 --- a/src/schema/provenance_schema.yaml +++ b/src/schema/provenance_schema.yaml @@ -426,6 +426,13 @@ ENTITIES: description: "The uuid of previous revision dataset" after_create_trigger: link_to_previous_revision on_read_trigger: get_previous_revision_uuid + previous_revision_uuids: + type: list + generated: true + transient: true + immutable: true + description: "The list of the uuids of previous revision datasets" + on_read_trigger: get_previous_revision_uuids next_revision_uuid: type: string generated: true @@ -433,6 +440,13 @@ ENTITIES: immutable: true description: "The uuid of next revision dataset" on_read_trigger: get_next_revision_uuid + next_revision_uuids: + type: list + generated: true + transient: true + immutable: true + description: "The list of the uuids of next revision datasets" + on_read_trigger: get_next_revision_uuids # No like image and metadata files handling for Donor/Sample # Dataset has only one thumbnail file thumbnail_file: @@ -657,10 +671,10 @@ ENTITIES: on_read_trigger: get_previous_revision_uuid previous_revision_uuids: type: list + generated: true transient: true immutable: true description: "The list of the uuids of previous revision datasets" - after_create_trigger: link_to_previous_revision on_read_trigger: get_previous_revision_uuids next_revision_uuid: type: string