From 75f4c333587cf0101c95b1b9a2af0a66a565bc3d Mon Sep 17 00:00:00 2001 From: DerekFurstPitt Date: Mon, 25 Sep 2023 14:04:39 -0400 Subject: [PATCH 1/4] implemented new property creation_action. --- src/app.py | 1 - src/schema/provenance_schema.yaml | 12 ++++++++++-- src/schema/schema_triggers.py | 3 ++- src/schema/schema_validators.py | 21 +++++++++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/app.py b/src/app.py index 69aa1cc7..b2d87622 100644 --- a/src/app.py +++ b/src/app.py @@ -4126,7 +4126,6 @@ def create_entity_details(request, normalized_entity_type, user_token, json_data # Meaning the returned target property key is different from the original key # in the trigger method, e.g., Donor.image_files_to_add filtered_merged_dict = schema_manager.remove_transient_and_none_values(merged_dict, normalized_entity_type) - # Create new entity try: # Check if the optional `superclass` property is defined, None otherwise diff --git a/src/schema/provenance_schema.yaml b/src/schema/provenance_schema.yaml index b6be5ac4..700b0633 100644 --- a/src/schema/provenance_schema.yaml +++ b/src/schema/provenance_schema.yaml @@ -88,8 +88,6 @@ ACTIVITIES: <<: *shared_properties creation_action: type: string - generated: true - immutable: true description: "The activity that was performed." before_create_trigger: set_activity_creation_action @@ -279,6 +277,10 @@ ENTITIES: antibodies: type: list description: "A list of antibodies used in the assay that created the dataset" + creation_action: + type: string + transient: true + description: "The activity that was performed." description: type: string description: "Free text description of the dataset" @@ -508,6 +510,12 @@ ENTITIES: type: string description: "Additional information about the dataset, which can be used to find this dataset, including lab specific (non-PHI) identifiers." # The Dataset.data_access_level is based on Dataset.status and Dataset.contains_human_genetic_sequences + creation_action: + type: string + transient: true + description: "The activity that was performed." + before_property_create_validators: + - validate_creation_action data_access_level: type: string generated: true diff --git a/src/schema/schema_triggers.py b/src/schema/schema_triggers.py index 438b5274..9d0740cb 100644 --- a/src/schema/schema_triggers.py +++ b/src/schema/schema_triggers.py @@ -1907,7 +1907,8 @@ def get_upload_datasets(property_key, normalized_type, user_token, existing_data def set_activity_creation_action(property_key, normalized_type, user_token, existing_data_dict, new_data_dict): if 'normalized_entity_type' not in new_data_dict: raise KeyError("Missing 'normalized_entity_type' key in 'existing_data_dict' during calling 'set_activity_creation_action()' trigger method.") - + if new_data_dict and new_data_dict['creation_action']: + return property_key, new_data_dict['creation_action'] return property_key, f"Create {new_data_dict['normalized_entity_type']} Activity" diff --git a/src/schema/schema_validators.py b/src/schema/schema_validators.py index 5aaf9704..b5c2d13e 100644 --- a/src/schema/schema_validators.py +++ b/src/schema/schema_validators.py @@ -509,6 +509,27 @@ def validate_publication_date(property_key, normalized_entity_type, request, exi except ValueError: raise ValueError(f"Invalid {property_key} format, must be YYYY-MM-DD") +""" +Validate the provided value of the activity creation action. Only very specific +values are allowed. +Parameters +---------- +property_key : str + The target property key +normalized_type : str + Submission +request: Flask request object + The instance of Flask request passed in from application request +existing_data_dict : dict + A dictionary that contains all existing entity properties +new_data_dict : dict + The json data in request body, already after the regular validations +""" +def validate_creation_action(property_key, normalized_entity_type, request, existing_data_dict, new_data_dict): + creation_action = new_data_dict[property_key] + if creation_action and creation_action not in ["HIVE Process", "Lab Process"]: + raise ValueError(f"Invalid {property_key} value") + #################################################################################################### ## Internal Functions From a5a1fd8de34f93fa17ba9231545b30c9a3199c4d Mon Sep 17 00:00:00 2001 From: DerekFurstPitt Date: Tue, 26 Sep 2023 13:52:36 -0400 Subject: [PATCH 2/4] Updated validate_creation_action to accommodate generatlization to 'hubmap process' action to 'central process'. Also added multi-assay split --- src/schema/schema_validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/schema/schema_validators.py b/src/schema/schema_validators.py index b5c2d13e..8346289f 100644 --- a/src/schema/schema_validators.py +++ b/src/schema/schema_validators.py @@ -527,7 +527,7 @@ def validate_publication_date(property_key, normalized_entity_type, request, exi """ def validate_creation_action(property_key, normalized_entity_type, request, existing_data_dict, new_data_dict): creation_action = new_data_dict[property_key] - if creation_action and creation_action not in ["HIVE Process", "Lab Process"]: + if creation_action and creation_action not in ["Central Process", "Lab Process", "Multi-Assay Split"]: raise ValueError(f"Invalid {property_key} value") From 2dc0808624713762b74deae504eea9232502907e Mon Sep 17 00:00:00 2001 From: DerekFurstPitt Date: Tue, 26 Sep 2023 14:34:16 -0400 Subject: [PATCH 3/4] Marked creation_action property in datasets/publications as immutable. It already couldn't be changed because there's no update triggers on the activity, but users could still attempt to update and would not know why it failed. So now an error will be raised. --- src/schema/provenance_schema.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/schema/provenance_schema.yaml b/src/schema/provenance_schema.yaml index 700b0633..b72bf3a1 100644 --- a/src/schema/provenance_schema.yaml +++ b/src/schema/provenance_schema.yaml @@ -280,7 +280,10 @@ ENTITIES: creation_action: type: string transient: true + immutable: true description: "The activity that was performed." + before_property_create_validators: + - validate_creation_action description: type: string description: "Free text description of the dataset" @@ -513,6 +516,7 @@ ENTITIES: creation_action: type: string transient: true + immutable: true description: "The activity that was performed." before_property_create_validators: - validate_creation_action From af8ac172549f8ffb765d83183b14c3a6ce4024d7 Mon Sep 17 00:00:00 2001 From: DerekFurstPitt Date: Thu, 28 Sep 2023 15:34:01 -0400 Subject: [PATCH 4/4] Fixed error that would occur when creation_action not specified. Also added additional validation for empty values. Made it more clear in error messages what the acceptable values are for creation_action. Made creation action validator case insensitive. Also normalized the case for creation action within the trigger. Now always has the first letter capitalized. --- src/schema/schema_triggers.py | 4 ++-- src/schema/schema_validators.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/schema/schema_triggers.py b/src/schema/schema_triggers.py index 9d0740cb..38cf61dc 100644 --- a/src/schema/schema_triggers.py +++ b/src/schema/schema_triggers.py @@ -1907,8 +1907,8 @@ def get_upload_datasets(property_key, normalized_type, user_token, existing_data def set_activity_creation_action(property_key, normalized_type, user_token, existing_data_dict, new_data_dict): if 'normalized_entity_type' not in new_data_dict: raise KeyError("Missing 'normalized_entity_type' key in 'existing_data_dict' during calling 'set_activity_creation_action()' trigger method.") - if new_data_dict and new_data_dict['creation_action']: - return property_key, new_data_dict['creation_action'] + if new_data_dict and new_data_dict.get('creation_action'): + return property_key, new_data_dict['creation_action'].title() return property_key, f"Create {new_data_dict['normalized_entity_type']} Activity" diff --git a/src/schema/schema_validators.py b/src/schema/schema_validators.py index 8346289f..3b04c014 100644 --- a/src/schema/schema_validators.py +++ b/src/schema/schema_validators.py @@ -526,9 +526,12 @@ def validate_publication_date(property_key, normalized_entity_type, request, exi The json data in request body, already after the regular validations """ def validate_creation_action(property_key, normalized_entity_type, request, existing_data_dict, new_data_dict): - creation_action = new_data_dict[property_key] - if creation_action and creation_action not in ["Central Process", "Lab Process", "Multi-Assay Split"]: - raise ValueError(f"Invalid {property_key} value") + accepted_creation_action_values = ["central process", "lab process", "multi-assay split"] + creation_action = new_data_dict[property_key].lower() + if creation_action and creation_action not in accepted_creation_action_values: + raise ValueError("Invalid {} value. Accepted values are: {}".format(property_key, ", ".join(accepted_creation_action_values))) + if creation_action == '': + raise ValueError(f"The property {property_key} cannot be empty, when specified.") ####################################################################################################