Skip to content

Commit d49026a

Browse files
authored
Merge pull request #832 from hubmapconsortium/karlburke/AddUploadFields
Karlburke/add upload fields
2 parents 0bc0fb6 + a7277a5 commit d49026a

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

entity-api-spec.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,12 @@ components:
903903
$ref: '#/components/schemas/Dataset'
904904
readOnly: true
905905
description: 'The datasets that are contained in this Upload.'
906+
anticipated_complete_upload_month:
907+
type: string
908+
description: 'The month that the Upload is anticipated to have all required data uploaded, in the format YYYY-MM.'
909+
anticipated_dataset_count:
910+
type: integer
911+
description: 'The total number of datasets that this Upload will eventually contain.'
906912
Collection:
907913
type: object
908914
properties:

src/schema/provenance_schema.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,24 @@ ENTITIES:
12411241
type: string
12421242
indexed: true
12431243
description: The organ code representing the organ type that the data contained in the upload will be registered/associated with.
1244+
anticipated_complete_upload_month:
1245+
type: string
1246+
indexed: true
1247+
description: The specific month the Upload is anticipated to have all required data uploaded, in the format YYYY-MM.
1248+
required_on_create: false
1249+
before_property_create_validators:
1250+
- validate_anticipated_complete_date
1251+
before_property_update_validators:
1252+
- validate_anticipated_complete_date
1253+
anticipated_dataset_count:
1254+
type: integer
1255+
indexed: true
1256+
description: The total number of datasets that this Upload will eventually contain.
1257+
required_on_create: false
1258+
before_property_create_validators:
1259+
- validate_anticipated_dataset_count
1260+
before_property_update_validators:
1261+
- validate_anticipated_dataset_count
12441262

12451263
############################################# EPICollection #############################################
12461264
Epicollection:

src/schema/schema_validators.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,63 @@ def validate_upload_status_value(property_key, normalized_entity_type, request,
542542
if new_status not in accepted_status_values:
543543
raise ValueError(f"Invalid status value: {new_status}")
544544

545+
"""
546+
Validate the anticipated_complete_data string provided for an Upload
547+
548+
Parameters
549+
----------
550+
property_key : str
551+
The target property key
552+
normalized_type : str
553+
Submission
554+
request: Flask request object
555+
The instance of Flask request passed in from application request
556+
existing_data_dict : dict
557+
A dictionary that contains all existing entity properties
558+
new_data_dict : dict
559+
The json data in request body, already after the regular validations
560+
"""
561+
def validate_anticipated_complete_date(property_key, normalized_entity_type, request, existing_data_dict, new_data_dict):
562+
MAX_ANTICIPATED_COMPLETE_DATE = '2026-12'
563+
anticipated_complete_date_str = new_data_dict[property_key]
564+
if not re.fullmatch(pattern=r'^\d{4}-\d{2}$', string=anticipated_complete_date_str):
565+
raise ValueError(f"Format of '{anticipated_complete_date_str}' does not match the format YYYY-MM")
566+
anticipated_year, anticipated_month = map(int, anticipated_complete_date_str.split("-"))
567+
if anticipated_month < 1 or anticipated_month > 12:
568+
raise ValueError(f"Anticipated completion month of '{anticipated_complete_date_str[5:]}' is not valid")
569+
now = datetime.now()
570+
current_year = now.year
571+
current_month = now.month
572+
if anticipated_year < current_year or \
573+
(anticipated_year == current_year and anticipated_month < current_month):
574+
raise ValueError( f"Anticipated complete date '{anticipated_complete_date_str}'"
575+
f" cannot be before the current month.")
576+
max_anticipated_year, max_anticipated_month = map(int, MAX_ANTICIPATED_COMPLETE_DATE.split("-"))
577+
if anticipated_year > max_anticipated_year:
578+
raise ValueError( f"Anticipated complete date '{anticipated_complete_date_str}'"
579+
f" cannot be after '{MAX_ANTICIPATED_COMPLETE_DATE}'.")
580+
581+
"""
582+
Validate the anticipated_dataset_count integer provided for an Upload
583+
584+
Parameters
585+
----------
586+
property_key : str
587+
The target property key
588+
normalized_type : str
589+
Submission
590+
request: Flask request object
591+
The instance of Flask request passed in from application request
592+
existing_data_dict : dict
593+
A dictionary that contains all existing entity properties
594+
new_data_dict : dict
595+
The json data in request body, already after the regular validations
596+
"""
597+
def validate_anticipated_dataset_count(property_key, normalized_entity_type, request, existing_data_dict, new_data_dict):
598+
# anticipated_dataset_count of type int, assured by provenance_schema.yaml "type: integer"
599+
anticipated_dataset_count = new_data_dict[property_key]
600+
if anticipated_dataset_count <= 0:
601+
raise ValueError(f"{property_key} must be positive integer when specified.")
545602

546603
"""
547604
Validate the provided value of Sample.sample_category on create via POST and update via PUT

src/schema_templating/example-yaml-templates/upload-schema.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,10 @@ Upload:
8181
items:
8282
$ref: '#/components/schemas/Dataset'
8383
readOnly: true
84-
description: "The datasets that are contained in this Upload."
84+
description: "The datasets that are contained in this Upload."
85+
anticipated_complete_upload_month:
86+
type: string
87+
description: The month that the Upload is anticipated to have all required data uploaded, in the format YYYY-MM.
88+
anticipated_dataset_count:
89+
type: integer
90+
description: The total number of datasets that this Upload will eventually contain.

0 commit comments

Comments
 (0)