diff --git a/src/server/BreCal/validators/input_validation_shipcall.py b/src/server/BreCal/validators/input_validation_shipcall.py index a6d1555..4a591be 100644 --- a/src/server/BreCal/validators/input_validation_shipcall.py +++ b/src/server/BreCal/validators/input_validation_shipcall.py @@ -129,11 +129,14 @@ class InputValidationShipcall(): if check_if_int_is_valid_flag(flags_value, enum_object=ParticipantFlag): raise ValidationError({"flags":f"incorrect value provided for 'flags'. Must be a valid combination of the flags."}) + existing_shipcall = None if is_put_data: - # the type of a shipcall may not be changed. It can only be set with the initial POST-request. - InputValidationShipcall.check_shipcall_type_is_unchanged(loadedModel) - InputValidationShipcall.check_times_are_in_future(loadedModel, content) + existing_shipcall = InputValidationShipcall.get_shipcall_by_id(loadedModel.get("id")) + # the type of a shipcall may not be changed. It can only be set with the initial POST-request. + InputValidationShipcall.check_shipcall_type_is_unchanged(loadedModel, existing_shipcall) + + InputValidationShipcall.check_times_are_in_future(loadedModel, content, existing_shipcall) # some arguments must not be provided InputValidationShipcall.check_forbidden_arguments(content, forbidden_keys=forbidden_keys) @@ -261,14 +264,16 @@ class InputValidationShipcall(): raise ValidationError({"participants":f"every participant id and type should be listed only once. Found multiple entries for one of the participants."}) @staticmethod - def check_shipcall_type_is_unchanged(loadedModel:dict): - # the type of a shipcall may only be set on POST requests. Afterwards, shipcall types may not be changed. - query = SQLQuery.get_shipcall_by_id() - shipcall = execute_sql_query_standalone(query=query, model=Shipcall, param={"id":loadedModel.get("id")}, command_type="single") - - if int(loadedModel["type"]) != int(shipcall.type): + def check_shipcall_type_is_unchanged(loadedModel:dict, existing_shipcall:object): + if int(loadedModel["type"]) != int(existing_shipcall.type): raise ValidationError({"type":f"The shipcall type may only be set in the initial POST-request. Afterwards, changing the shipcall type is not allowed."}) # @pytest.raises return + + @staticmethod + def get_shipcall_by_id(shipcall_id:int): + query = SQLQuery.get_shipcall_by_id() + shipcall = execute_sql_query_standalone(query=query, model=Shipcall, param={"id":shipcall_id}, command_type="single") + return shipcall @staticmethod def check_forbidden_arguments(content:dict, forbidden_keys=["evaluation", "evaluation_message"]): @@ -330,7 +335,7 @@ class InputValidationShipcall(): return @staticmethod - def check_times_are_in_future(loadedModel:dict, content:dict): + def check_times_are_in_future(loadedModel:dict, content:dict, existing_shipcall:object): """ Dates should be in the future. Depending on the ShipcallType, specific values should be checked Perfornms datetime checks in the loadedModel (datetime.datetime objects). @@ -353,11 +358,20 @@ class InputValidationShipcall(): tidal_window_from = loadedModel.get("tidal_window_from", None) tidal_window_to = loadedModel.get("tidal_window_to", None) - # Estimated arrival or departure times - InputValidationShipcall.check_times_in_future_based_on_type(type_, time_ref, eta, etd) + if existing_shipcall is not None: + existing_eta = existing_shipcall.eta + existing_etd = existing_shipcall.etd + existing_tidal_window_from = existing_shipcall.tidal_window_from + existing_tidal_window_to = existing_shipcall.tidal_window_to + + if eta != existing_eta or etd != existing_etd: + # Estimated arrival or departure times + InputValidationShipcall.check_times_in_future_based_on_type(type_, time_ref, eta, etd) + + if tidal_window_from != existing_tidal_window_from or tidal_window_to != existing_tidal_window_to: + # Tidal Window + InputValidationShipcall.check_tidal_window_in_future(type_, time_ref, tidal_window_from, tidal_window_to) - # Tidal Window - InputValidationShipcall.check_tidal_window_in_future(type_, time_ref, tidal_window_from, tidal_window_to) return @staticmethod diff --git a/src/server/BreCal/validators/input_validation_times.py b/src/server/BreCal/validators/input_validation_times.py index a6be514..780bdce 100644 --- a/src/server/BreCal/validators/input_validation_times.py +++ b/src/server/BreCal/validators/input_validation_times.py @@ -419,6 +419,8 @@ class InputValidationTimes(): # commonly used in the PUT-request if loadedModel is not None: (shipcall_id, times_assigned_participant) = InputValidationTimes.prepare_authority_check_for_put_request(loadedModel) + else: + loadedModel = get_times_data_for_id(times_id) # commonly used in the DELETE-request if times_id is not None: