Skip to content

Commit

Permalink
Adding get_has_metadata schema trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmadonna committed Oct 1, 2024
1 parent 4ccee32 commit 9c6e561
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/schema/provenance_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ shared_entity_properties: &shared_entity_properties
before_property_update_validators:
- validate_application_header_before_property_update
description: "The metadata returned from the processing at data submission time."
has_metadata:
type: string
generated: true # Disallow entry from users via POST
immutable: true # Disallow update via PUT
description: "True if the entity has metadata associated with it. Otherwise False."
on_index_trigger: get_has_metadata
was_attributed_to:
type: list
description: "Attribution is the ascribing of an entity to an agent."
Expand Down
49 changes: 49 additions & 0 deletions src/schema/schema_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,55 @@ def link_to_previous_revision(property_key, normalized_type, user_token, existin
raise


def get_has_metadata(property_key, normalized_type, user_token, existing_data_dict, new_data_dict):
"""Trigger event method for determining if the entity has metadata.
Parameters
----------
property_key : str
The target property key
normalized_type : str
One of the types defined in the schema yaml
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
-------
Tuple[str, str]
str: The target property key
str: "True" or "False" if the entity has metadata
"""
if 'uuid' not in existing_data_dict:
msg = create_trigger_error_msg(
"Missing 'uuid' key in 'existing_data_dict' during calling 'get_has_metadata()' trigger method.",
existing_data_dict, new_data_dict
)
raise KeyError(msg)

if equals(Ontology.ops().entities().DATASET, existing_data_dict['entity_type']):
ingest_metadata = existing_data_dict.get('ingest_metadata', {})
has_metadata = 'metadata' in ingest_metadata
return property_key, str(has_metadata)

SpecimenCategories = Ontology.ops().specimen_categories()
if (
equals(Ontology.ops().entities().SOURCE, existing_data_dict['entity_type'])
or equals('Collection', existing_data_dict['entity_type'])
or equals('Publication', existing_data_dict['entity_type'])
or equals(SpecimenCategories.BLOCK, existing_data_dict.get('sample_category'))
or equals(SpecimenCategories.SECTION, existing_data_dict.get('sample_category'))
or equals(SpecimenCategories.SUSPENSION, existing_data_dict.get('sample_category'))
):
has_metadata = 'metadata' in existing_data_dict
return property_key, str(has_metadata)

return property_key, None


def get_source_mapped_metadata(property_key, normalized_type, user_token, existing_data_dict, new_data_dict):
"""Trigger event method of auto generating mapped metadata from 'living_donor_data' or 'organ_donor_data'.
Expand Down

0 comments on commit 9c6e561

Please sign in to comment.