diff --git a/docs/ApiValidationRules.md b/docs/ApiValidationRules.md index c080ae0..8a38a91 100644 --- a/docs/ApiValidationRules.md +++ b/docs/ApiValidationRules.md @@ -147,6 +147,7 @@ The id field is required, missing fields will not be updated. | Field | Validation | |-------|------------| | eta_berth, etd_berth, lock_time, zone_entry, operations_start, operations_end | if set these values must be in the future| + | eta_interval_end, etd_interval_end | if set these values must be in the future. They must be larger than their ETA/ETD counterparts. | | remarks, berth_info | must be <= 512 chars | | participant_type | must not be BSMD | diff --git a/src/server/BreCal/schemas/model.py b/src/server/BreCal/schemas/model.py index a21fb20..14bceda 100644 --- a/src/server/BreCal/schemas/model.py +++ b/src/server/BreCal/schemas/model.py @@ -436,6 +436,21 @@ class TimesSchema(Schema): # when 'value' is 'None', a ValidationError is not issued. valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12) return + + @validates("eta_interval_end") + def validate_eta_interval_end(self, value): + # violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future + # when 'value' is 'None', a ValidationError is not issued. + valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12) + return + + @validates("etd_interval_end") + def validate_etd_interval_end(self, value): + # violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future + # when 'value' is 'None', a ValidationError is not issued. + valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12) + return + # deserialize PUT object target diff --git a/src/server/BreCal/validators/input_validation_times.py b/src/server/BreCal/validators/input_validation_times.py index 0385220..37b70b8 100644 --- a/src/server/BreCal/validators/input_validation_times.py +++ b/src/server/BreCal/validators/input_validation_times.py @@ -167,6 +167,17 @@ class InputValidationTimes(): if ParticipantType.BSMD in loadedModel["participant_type"]: raise ValidationError(f"current user belongs to BSMD. Cannot post times datasets. Found user data: {user_data}") + + if (loadedModel["etd_interval_end"] is not None) and (loadedModel["etd_berth"] is not None): + time_end_after_time_start = loadedModel["etd_interval_end"] >= loadedModel["etd_berth"] + if not time_end_after_time_start: + raise ValidationError(f"The provided time interval for the estimated departure time is invalid. The interval end takes place before the interval start. Found interval data: {loadedModel['etd_berth']} to {loadedModel['etd_interval_end']}") + + + if (loadedModel["eta_interval_end"] is not None) and (loadedModel["eta_berth"] is not None): + time_end_after_time_start = loadedModel["eta_interval_end"] >= loadedModel["eta_berth"] + if not time_end_after_time_start: + raise ValidationError(f"The provided time interval for the estimated arrival time is invalid. The interval begin takes place after the interval end. Found interval data: {loadedModel['eta_berth']} to {loadedModel['eta_interval_end']}") return @staticmethod