adding input validation for time intervals
This commit is contained in:
parent
4b5ff90b34
commit
1ff972883f
@ -147,6 +147,7 @@ The id field is required, missing fields will not be updated.
|
|||||||
| Field | Validation |
|
| Field | Validation |
|
||||||
|-------|------------|
|
|-------|------------|
|
||||||
| eta_berth, etd_berth, lock_time, zone_entry, operations_start, operations_end | if set these values must be in the future|
|
| 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 |
|
| remarks, berth_info | must be <= 512 chars |
|
||||||
| participant_type | must not be BSMD |
|
| participant_type | must not be BSMD |
|
||||||
|
|
||||||
|
|||||||
@ -437,6 +437,21 @@ class TimesSchema(Schema):
|
|||||||
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
||||||
return
|
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
|
# deserialize PUT object target
|
||||||
|
|
||||||
class UserSchema(Schema):
|
class UserSchema(Schema):
|
||||||
|
|||||||
@ -167,6 +167,17 @@ class InputValidationTimes():
|
|||||||
|
|
||||||
if ParticipantType.BSMD in loadedModel["participant_type"]:
|
if ParticipantType.BSMD in loadedModel["participant_type"]:
|
||||||
raise ValidationError(f"current user belongs to BSMD. Cannot post times datasets. Found user data: {user_data}")
|
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
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user