Skip to content

Commit

Permalink
Merge pull request #574 from hubmapconsortium/expose_creation_action_…
Browse files Browse the repository at this point in the history
…from_activity

Add Dataset Activity.creation_action to ENTITY.Dataset as creation_action_activity
  • Loading branch information
yuanzhou authored Dec 1, 2023
2 parents 7775846 + 1bc7ed0 commit e18adae
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions entity-api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,9 @@ components:
dbgap_study_url:
type: string
description: 'A URL linking the dataset to the particular study on dbGap it belongs to'
creation_action:
type: string
description: 'The associated action that represents the creation of that dataset'
Upload:
type: object
properties:
Expand Down
1 change: 1 addition & 0 deletions src/schema/provenance_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ ENTITIES:
type: string
transient: true
immutable: true
on_read_trigger: get_creation_action_activity
description: "The activity that was performed."
before_property_create_validators:
- validate_creation_action
Expand Down
2 changes: 1 addition & 1 deletion src/schema/schema_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def load_provenance_schema(valid_yaml_file):
with open(valid_yaml_file) as file:
schema_dict = yaml.safe_load(file)

logger.info("Schema yaml file loaded successfully")
logger.info(f"Provenance Schema yaml file loaded successfully from {valid_yaml_file} :)")

return schema_dict

Expand Down
14 changes: 14 additions & 0 deletions src/schema/schema_neo4j_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,20 @@ def get_entity_type(neo4j_driver, entity_uuid: str) -> str:
return None


def get_entity_creation_action_activity(neo4j_driver, entity_uuid: str) -> str:
query: str = f"MATCH (ds {{uuid:'{entity_uuid}'}})<-[:ACTIVITY_OUTPUT]-(a:Activity) RETURN a.creation_action"

logger.info("======get_entity_creation_action() query======")
logger.info(query)

with neo4j_driver.session() as session:
record = session.read_transaction(execute_readonly_tx, query)
if record and len(record) == 1:
return record[0]

return None


"""
Create or recreate one or more linkages (via Activity nodes)
between the target entity node and the direct ancestor nodes in neo4j
Expand Down
14 changes: 14 additions & 0 deletions src/schema/schema_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,20 @@ def get_next_revision_uuid(property_key, normalized_type, user_token, existing_d
return property_key, next_revision_uuid


def get_creation_action_activity(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_creation_action_activity()' trigger method.")

uuid: str = existing_data_dict['uuid']
logger.info(f"Executing 'get_creation_action_activity()' trigger method on uuid: {uuid}")

neo4j_driver_instance = schema_manager.get_neo4j_driver_instance()
creation_action_activity =\
schema_neo4j_queries.get_entity_creation_action_activity(neo4j_driver_instance, uuid)

return property_key, creation_action_activity


"""
Trigger event method to commit thumbnail file saved that were previously uploaded via ingest-api
Expand Down

0 comments on commit e18adae

Please sign in to comment.