Skip to content

Commit

Permalink
Merge branch 'main' into Derek-Furst/multiple-components-datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekFurstPitt committed Oct 9, 2023
2 parents a86ec29 + 77be319 commit bd254b4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4294,7 +4294,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
Expand Down
16 changes: 14 additions & 2 deletions src/schema/provenance_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -279,6 +277,13 @@ ENTITIES:
antibodies:
type: list
description: "A list of antibodies used in the assay that created the dataset"
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"
Expand Down Expand Up @@ -508,6 +513,13 @@ 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
immutable: true
description: "The activity that was performed."
before_property_create_validators:
- validate_creation_action
data_access_level:
type: string
generated: true
Expand Down
3 changes: 2 additions & 1 deletion src/schema/schema_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.get('creation_action'):
return property_key, new_data_dict['creation_action'].title()
return property_key, f"Create {new_data_dict['normalized_entity_type']} Activity"


Expand Down
24 changes: 24 additions & 0 deletions src/schema/schema_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,30 @@ 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):
accepted_creation_action_values = ["central process", "lab process"]
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.")


####################################################################################################
## Internal Functions
Expand Down

0 comments on commit bd254b4

Please sign in to comment.