@@ -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"""
547604Validate the provided value of Sample.sample_category on create via POST and update via PUT
0 commit comments