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

Derek furst/add previous revision uuids #578

Merged
merged 3 commits into from
Dec 7, 2023
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
7 changes: 7 additions & 0 deletions entity-api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}'
Expand Down
28 changes: 28 additions & 0 deletions src/schema/provenance_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,27 @@ 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
transient: true
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:
Expand Down Expand Up @@ -655,13 +669,27 @@ 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
transient: true
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:
Expand Down
74 changes: 74 additions & 0 deletions src/schema/schema_neo4j_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,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

Expand Down Expand Up @@ -745,6 +783,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

Expand Down
72 changes: 72 additions & 0 deletions src/schema/schema_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -1149,6 +1185,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

Expand Down