diff --git a/entity-api-spec.yaml b/entity-api-spec.yaml index fbfc5548..7dc65b8b 100644 --- a/entity-api-spec.yaml +++ b/entity-api-spec.yaml @@ -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: diff --git a/src/schema/provenance_schema.yaml b/src/schema/provenance_schema.yaml index c00564cc..f8ce3c23 100644 --- a/src/schema/provenance_schema.yaml +++ b/src/schema/provenance_schema.yaml @@ -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 diff --git a/src/schema/schema_manager.py b/src/schema/schema_manager.py index edab58a7..ab0d2450 100644 --- a/src/schema/schema_manager.py +++ b/src/schema/schema_manager.py @@ -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 diff --git a/src/schema/schema_neo4j_queries.py b/src/schema/schema_neo4j_queries.py index 231375b3..7e097787 100644 --- a/src/schema/schema_neo4j_queries.py +++ b/src/schema/schema_neo4j_queries.py @@ -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 diff --git a/src/schema/schema_triggers.py b/src/schema/schema_triggers.py index 3446da2f..682fb1ac 100644 --- a/src/schema/schema_triggers.py +++ b/src/schema/schema_triggers.py @@ -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