diff --git a/entity-api-spec.yaml b/entity-api-spec.yaml index 25d807b7..b3b2120d 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 9a192fab..3f187b1a 100644 --- a/src/schema/provenance_schema.yaml +++ b/src/schema/provenance_schema.yaml @@ -427,6 +427,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 @@ -434,6 +441,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,6 +671,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 @@ -664,6 +685,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 547a30f0..c71ff2ff 100644 --- a/src/schema/schema_neo4j_queries.py +++ b/src/schema/schema_neo4j_queries.py @@ -723,6 +723,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 @@ -759,6 +797,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 fdad79d7..1a2db71a 100644 --- a/src/schema/schema_triggers.py +++ b/src/schema/schema_triggers.py @@ -1117,6 +1117,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 @@ -1163,6 +1199,42 @@ def get_creation_action_activity(property_key, normalized_type, user_token, exis return property_key, creation_action_activity +""" +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