Skip to content

Commit 0bc0fb6

Browse files
authored
Merge pull request #831 from hubmapconsortium/karlburke/addSampleCategoryCaseValidation
Add case-check to sample_category validator, and use validators durin…
2 parents 1d407a9 + 4da16ef commit 0bc0fb6

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

entity-api-spec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ components:
434434
- block
435435
- section
436436
- suspension
437-
description: 'A code representing the type of specimen. Must be an organ, block, section, or suspension'
437+
description: 'A code representing the type of specimen. Must be an organ, block, section, or suspension, in all lower case.'
438438
protocol_url:
439439
type: string
440440
description: 'The protocols.io doi url pointing the protocol under wich the sample was obtained and/or prepared.'
@@ -482,7 +482,7 @@ components:
482482
- TR
483483
- UR
484484
- UT
485-
description: 'Organ code specifier, only set if sample_category == organ. Valid values found in: [organ types](https://github.com/hubmapconsortium/search-api/blob/main/src/search-schema/data/definitions/enums/organ_types.yaml)'
485+
description: 'Organ code specifier, only set if sample_category == organ. Valid values found in: [organ types](https://ontology.api.hubmapconsortium.org/organs/by-code?application_context=HUBMAP)'
486486
organ_other:
487487
type: string
488488
description: The organ type provided by the user if "other" organ type is selected

src/app.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,15 @@ def create_multiple_samples(count):
12721272
# No need to log the validation errors
12731273
bad_request_error(str(e))
12741274

1275-
# `direct_ancestor_uuid` is required on create
1275+
try:
1276+
schema_manager.execute_property_level_validators('before_property_create_validators', normalized_entity_type, request, {}, json_data_dict)
1277+
# Currently only ValueError
1278+
except ValueError as e:
1279+
bad_request_error(e)
1280+
except schema_errors.UnimplementedValidatorException as uve:
1281+
internal_server_error(uve)
1282+
1283+
# `direct_ancestor_uuid` is required on create for a Sample.
12761284
# Check existence of the direct ancestor (either another Sample or Donor)
12771285
direct_ancestor_dict = query_target_entity(json_data_dict['direct_ancestor_uuid'], user_token)
12781286

@@ -1288,7 +1296,7 @@ def create_multiple_samples(count):
12881296
if ('organ' not in json_data_dict) or (not json_data_dict['organ']):
12891297
bad_request_error("A valid organ code is required since the direct ancestor is a Donor")
12901298

1291-
# Generate 'before_create_triiger' data and create the entity details in Neo4j
1299+
# Generate 'before_create_trigger' data and create the entity details in Neo4j
12921300
generated_ids_dict_list = create_multiple_samples_details(request, normalized_entity_type, user_token, json_data_dict, count)
12931301

12941302
# Also index the each new Sample node in elasticsearch via search-api

src/schema/schema_validators.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,14 @@ def validate_sample_category(property_key, normalized_entity_type, request, exis
564564
sample_category = new_data_dict[property_key].lower()
565565

566566
if sample_category not in defined_tissue_types:
567-
raise ValueError(f"Invalid sample_category: {sample_category}")
568-
567+
raise ValueError(f"Invalid sample_category: {sample_category}."
568+
f" Should be one of {', '.join(defined_tissue_types)}.")
569+
570+
# Given the sample_category is a defined_tissue_types element, assure the request has
571+
# the proper case for storage
572+
if new_data_dict[property_key] != sample_category:
573+
raise ValueError(f"The case of sample_category '{new_data_dict[property_key]}'"
574+
f" must be specified as '{sample_category}'.")
569575

570576
"""
571577
Validate the provided value of Publication.publication_date is in the correct format against ISO 8601 Format:

0 commit comments

Comments
 (0)